Stepper Motor/LCD coding and wiring help?

Hello Everyone, I just needed a lot of help with using arduino and setting up my lcd. The problem im facing mainly is with the lcd I do not know how to wire and how to make it count the rotations of the motor (Basically everytime the motor does a full rotation I want it to display that as 2 hits). I managed to get the motor up and running but the LCD im confused about. Could anyone help me with the wiring and the coding please?
This is the code I have for the motor:
`#define dirPin 2
#define stepPin 3
#define Switch 4
#define stepsPerRevolution 400

void setup()
{
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(Switch, INPUT_PULLUP);

digitalWrite(stepPin, LOW);

}

void loop()
{
if(digitalRead(Switch)==LOW)
{
// Set the spinning direction clockwise:
digitalWrite(dirPin, LOW);

// Spin the stepper motor 1 revolution slowly:
  // These four lines result in 1 step:
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(400);

}

else
{
delayMicroseconds(10);

}

delay(5);

}`

What should I add to have it display the number of full rotations as two hits.

General advice, look into:

  • Stepper motor drivers, A4988 for example.
  • Libraries like AccelStepper or FlexyStepper.

Which LCD are you using? Can you explain what you're confused about?

For a standard 16x2 LCD without I2C, the examples say something like

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

So it uses pins 2, 3, 4, 5, 11 and 12. You already have your motor on the first 3 so you have to move those LCD pins to e.g. A0, A1 and A2 and adjust the code to e.g.

const int rs = 12, en = 11, d4 = 5, d5 = A0, d6 = A1, d7 = A2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the IDE 1.x category.

You will need a sensor to count the rotations.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the IDE 1.x category.

Oh im using an adafruit 16x2 Lcd, I arleady know about the connecting part but everytime I do it, it wont display anything just turn on and thats it. It wont display letters, I wired it properly and then defined it and then it still wont work.

Please provide a link to the LCD you are using. Adafruit has different ones. Show a schematic and the code you tried.

I do not know what type it is its just a regualr adafruit 16x2 lcd, the code i used is:#include <LiquidCrystal.h>
// Define stepper motor connections and steps per revolution:
#define dirPin 2
#define stepPin 3
#define Switch 4
#define stepsPerRevolution 400
const int rs = 12, en = 11, d4 = 5, d5 = A1, d6 = A2, d7 = A3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(Switch, INPUT_PULLUP);

digitalWrite(stepPin, LOW);
lcd.begin(16,2);

}

void loop()
{
if(digitalRead(Switch)==LOW)
{
lcd.print("HI");
// Set the spinning direction clockwise:
digitalWrite(dirPin, LOW);

// Spin the stepper motor 1 revolution slowly:
  // These four lines result in 1 step:
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(400);

}

else
{
delayMicroseconds(10);

}

delay(5);

}

I don't know what a 'regular' LCD is. There are different ones, and in the end they all are 'regular'.
Can you provide a picture of your LCD? And is there a potentiometer to adjust the contrast?. If not you usually must provide one externally. And please show a schematic of the wiring. Otherwise its impossible to help.

Please use code tags to post your sketch and read this information to see what is needed to get the best help.

Hello,
So i just made a bit of progress on my code oh and my lcd is a raspberry pi adafruit and im using an arduino uno , I managed to have both the lcd display letters normally. Now I just need a code to basically add 1 for every 200 steps (since my motor has two arms) and display it on the lcd.
so the code looks like:

// Define stepper motor connections and steps per revolution:
#define dirPin 2
#define stepPin 3
#define Switch 8
#define stepsPerRevolution 400
LiquidCrystal lcd(4, 9, 5, 13, 11, 12);
int counter, hits=0;
void setup() 
{
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(Switch, INPUT_PULLUP);

  digitalWrite(stepPin, LOW);
  lcd.begin(16,2);
  lcd.setCursor(2,1);
analogWrite(6,100); // Generate PWM signal at pin D11, value of 100 (out of 255)

   

}

void loop() 
{

  if(digitalRead(Switch)==LOW)
  {
    
     lcd.print(" Strikes= ");
  lcd.setCursor(1,1);
   
    
    // Set the spinning direction clockwise:
    digitalWrite(dirPin, LOW);

    // Spin the stepper motor 1 revolution slowly:
      // These four lines result in 1 step:
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(400);
      
      
  }
  
  else
  {
    delayMicroseconds(10);
    lcd.print(" Test Rig ");
    lcd.setCursor(1,1);
    
  }

  delay(5);
 
 
   }
type or paste code here

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.