I am using an L298N motor control. I want to use my 2*16 LCD. Can I use the code like this?

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(12, 9, 4, 5, 6, 7);

// Motor Control
#define enableA  3
#define enableB  11
#define in1 4
#define in2 5
#define in3 6
#define in4 7
  • 1
    You can not use pins that are used by the LCD for your motors, you have to use other pins. – Andre Courchesne Jan 1 '17 at 7:13
  • No, you can't use that pins for both. Use other pins. – Hasan Mar 3 '17 at 11:40
  • 1
    You cannot use the pins for distinct purposes at the same time, however as you have the enable pins to the motor drivers wired up, you may be able to communicate with the LCD with the motors disabled, and then drive around while not communicating with the LCD (and making sure not to activate its strobe). – Chris Stratton Jun 1 '17 at 5:53

Using that pin configuration you'll have several problems despite you'll use enable pin.

I would use a I2C module for 16x2 lcd like this https://www.amazon.com/SainSmart-Serial-Module-Display-Arduino/dp/B00813HBEQ

Control 16x2 lcd with I2C.

| improve this answer | |
  • 1
    You will need two 16x2 LCD with different I2C addresses. – user31481 Nov 30 '17 at 18:26

You cannot use same pins for LCD and motor. Data transfer through pins 4,5,6,7(being data pins for LCD) will effect your motor state. You should use different pins and if you does not have sufficient digital pins so you can use analog pins as digital pins (0-LOW,255-HIGH).

| improve this answer | |
  • 1
    What's the 0-LOW 255-HIGH part about? Surely you are talking about the analog inputs that can also be used as digital pins. The analog outputs are already all on digital pins. With the analog pins you'd use pinMode and digitalWrite(pin, LOW) or digitalWrite(pin, HIGH) just like with any other digital pin. – Delta_G Jun 1 '17 at 3:25

You can use the same pins for both the motor and the LCD.

A condition is that the enable pin decides when the LCD or the motor is accepting inputs from the data pins. This is a normal bus configuration, several devices share data pins and have a enable pin to tell the device when they owns the data bus.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.