Stepper Motor + Voltage to LCD Display.

Hello guys,

Being new at the forum i have no idea if the topic is at the correct section, so if not, please move it at the correct one.

So let's talk about the problem that i am dealing with.

At first, I have a code that is making a comparison between two analog pins (in my case two Potentiometers) and transforming the analog inputs at two voltages which by comparison are moving a stepper motor clockwise and anti-clockwise. The code is working correctly until I execute the voltages at the LCD display. The display becomes blurry and the motor doesn't move even if the LEDs at the driver detect pulses. I am importing the code so anyone can tell me what is messed up with it.

Thanks in advance. :slight_smile:

code :
</>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

int analogPin = A0; // POT 0
int analogPin1 = A1; // POT 1
int analogValue = 0; //
int analogValue1 = 0; //

float Rvoltage = analogValue * (5.0 / 1023.0); // CONSTANT VOLTAGE
float Vvoltage = analogValue1 * (5.0 / 1023.0); // VARIABLE VOLTAGE

int Pin1 = 8;//IN1 is connected to 8
int Pin2 = 9;//IN2 is connected to 9
int Pin3 = 10;//IN3 is connected to 10
int Pin4 = 11;//IN4 is connected to 11

int pole1[] ={0,0,0,0, 0,1,1,1,0};//pole1
int pole2[] ={0,0,0,1, 1,1,0,0,0};//pole2
int pole3[] ={0,1,1,1, 0,0,0,0,0};//pole3
int pole4[] ={1,1,0,0, 0,0,0,1,0};//pole4

int poleStep = 0; //
int dirStatus = 3;//

void setup()

{

//INITIALIZE MOTOR PINS

pinMode(Pin1, OUTPUT); //DEFINING THE MOTOR PINS AS OUTPUT PINS
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);

// INITIALIZE LCD

lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor (7,0);
lcd.print("WELCOME");

delay(2000);

lcd.setCursor (2,1);
lcd.print(" TO THE WORLD OF");
delay(2000);

lcd.setCursor (0,3);
lcd.print(" ARDUINO! ");

delay(5000);
}

void loop(){

analogValue = analogRead(analogPin); // READING VALUES
analogValue1 = analogRead(analogPin1); // READING VALUES

float Rvoltage = analogValue * (5.0 / 1023.0); // CONSTANT VOLTAGE
float Vvoltage = analogValue1 * (5.0 / 1023.0); // VARIABLE VOLTAGE

if (Rvoltage < Vvoltage)
{
poleStep++;
driveStepper(poleStep);
}
else if (Rvoltage > Vvoltage)
{
poleStep--;
driveStepper(poleStep);
}
else
{
driveStepper(8);
}
if (poleStep>7)
{
poleStep = 0;
}
else if (poleStep<0)
{
poleStep = 7;
}
delay(50);

lcd.clear();
lcd.setCursor (0,0);
lcd.print("Rvoltage : "); // print text
lcd.print(Rvoltage); //Showing voltage value

lcd.setCursor (0,3);
lcd.print("Vvoltage : "); // print text
lcd.print(Rvoltage); //Showing voltage
}

void driveStepper(int c)
{
digitalWrite(Pin1, pole1

);  
     digitalWrite(Pin2, pole2[c]); 
     digitalWrite(Pin3, pole3[c]); 
     digitalWrite(Pin4, pole4[c]); 
}
</>



[for_arduino_forum.ino|attachment](upload://z0z0D87omh0nKfklIIdzsr1C4VE.ino) (2.33 KB)

please also post your schematics! Might be a wiring issue!

I don't think there is a wiring issue but yet check the code until i upload the schematics. :slight_smile:

The only timing I see is a 1ms delay at line 97, so you are looping dozens or hundreds of times per second. No wonder your display looks fuzzy. Try delay(50) or more.
What was the purpose of:

#define DELAY 32

electp:
I am importing the code so anyone can tell me what is messed up with it.

It's only a short program so please include it in your Post so we don't have to download it.

Please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum

...R

JCA34F:
The only timing I see is a 1ms delay at line 97, so you are looping dozens or hundreds of times per second. No wonder your display looks fuzzy. Try delay(50) or more.
What was the purpose of:

#define DELAY 32

Not working with changing the delay...

electp:
Not working with changing the delay...

Thank you for including the code in your Post. However you have not posted it correctly using the code button </> as requested earlier. That's why it has the little yellow guy with the dark glasses.

...R