LCD printing while motor is working

Hi there,

I tried to print a message on the LCD while a step motor was working.
As you can see in this picture, when I am on the main screen (when the step motor doesn’t work), everything is okay:

But when I start the stepper motor the message I want the LCD to print is not clear:

This is the part in my code when I start the step motor:

if (key == 'A')
        {
          lcd.clear();
          lcd.setCursor(3, 0);
          lcd.print("Feeding...");
          lcd.setCursor(2, 1);
          lcd.print("Please Wait");
          step_motor(); // Step Motor Start Working
          lcd.clear();
          screen_start();
          screen = 0;  // Go back to Beginning Screen
        }

The step motor code:

void step_motor()
  {
    int steps = 0;
    while(steps<512)
    {
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      delay(10);
      steps++;
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      delay(10);
      steps++;
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      delay(10);
      steps++;
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      delay(10);
      steps++;
    }
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }

How can I fix this?

Thanks for help.

The code snippets don't help in any way. Need more code. Need wiring info.

You can control the LCD with only 4 datalines (D4-D7) instead of all 8 (D0-D7), you'll have some spare pins on your Arduino.

I think it is because the current supply is too small. Nothing wrong with the code. Just show me the wiring. The LCD display become not clear because the current is used to supply the motor. Make sure you know how current used to rotate the motor. So, you have more current to supply the motor and LCD.

MAS3:
The code snippets don’t help in any way.
Need more code.
Need wiring info.

You can control the LCD with only 4 datalines (D4-D7) instead of all 8 (D0-D7), you’ll have some spare pins on your Arduino.

I know. D0-D3 are not connected.

tzudin:
I think it is because the current supply is too small. Nothing wrong with the code. Just show me the wiring.
The LCD display become not clear because the current is used to supply the motor. Make sure you know how current used to rotate the motor. So, you have more current to supply the motor and LCD.

I am new with Arduino, how can I control the current?

I am pretty sure this is the problem because when I disconnect the stepper motor from the board the message is clear.

Thank you very much, both of you!

Show us your circuit.

Paul__B: Show us your circuit.

I use Atmega2560

LCD Screen: VSS to ground VDD to 5v V0 to pin 3 of potentiometer RS to digital pin 36 R/W to ground E to digital pin 34 D4 to digital pin 32 D5 to digital pin 30 D6 to digital pin 28 D7 to digital pin 26

ULN2003 driver for the stepper motor: IN1 to digital pin 7 IN2 to digital pin 6 IN3 to digital pin 5 IN4 to digital pin 4 5v supply

typix:
I know. D0-D3 are not connected.

I am new with Arduino, how can I control the current?

I am pretty sure this is the problem because when I disconnect the stepper motor from the board the message is clear.

Thank you very much, both of you!

Did you use separate power supply for the motor?
You don’t have to control the current. You just need to know how maximum rating of your power supply.
If your motor need 1A of current. Then you need more than 1A current to power the LCD too.
As example you have to use 2A power supply instead of only 1A.

typix:
I use Atmega2560

LCD Screen:
VSS to ground
VDD to 5v
V0 to pin 3 of potentiometer
RS to digital pin 36
R/W to ground
E to digital pin 34
D4 to digital pin 32
D5 to digital pin 30
D6 to digital pin 28
D7 to digital pin 26

ULN2003 driver for the stepper motor:
IN1 to digital pin 7
IN2 to digital pin 6
IN3 to digital pin 5
IN4 to digital pin 4
5v supply

This not clear enough because we don’t know where the power supply.

tzudin: Did you use separate power supply for the motor? You don't have to control the current. You just need to know how maximum rating of your power supply. If your motor need 1A of current. Then you need more than 1A current to power the LCD too. As example you have to use 2A power supply instead of only 1A.

This not clear enough because we don't know where the power supply.

All power supply comes from the Arduino for both the motor and the LCD.

So I need to use separate power supply to control the motor if I want to see a clear message? (like a battery?)

All power supply comes from the Arduino for both the motor and the LCD.

Never do that. Always use a separate power supply to power motors. And of course never connect motors directly to Arduino pins (i'm not saying you did, just do not ever consider doing that).

typix: All power supply comes from the Arduino for both the motor and the LCD.

So I need to use separate power supply to control the motor if I want to see a clear message? (like a battery?)

Yes of course, or you will burn your arduino. You can read this for reference. Arduino I/O pin maximum current is only 40mA and DC Current VCC and GND Pins is 200.0 mA. There are so many tutorials on the internet how to drive motor using arduino.

MAS3: Never do that. Always use a separate power supply to power motors. And of course never connect motors directly to Arduino pins (i'm not saying you did, just do not ever consider doing that).

Yap, I'm agree.