Hi Guys,
I made a simple IR object counter on conveyor, componenets I am using are :
- Aurduino UNO
- 16X2 IC
- 1 IR Sensor.
The problevm I facing in running the stepper motor with IR counting sketch. The complete sketch is below...the IR counter working perfectly fine witout these two line in VOID LOOP
** // step one revolution in one direction:**
** //Serial.println("forward");**
** myStepper.step(stepsPerRevolution);**
...pls help in correcting the code...
// include the library code:
#include <LiquidCrystal.h>
#include <Stepper.h>
const int stepsPerRevolution = 360; // change this to fit the number of steps per revolution
// for your motor
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 5, 4, 3, 2);
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
// set up a constant for the tilt switchPin
const int switchPin = 6;
int hits = 0;
// variable to hold the value of the switchPin
int switchState = 0;
// variable to hold previous value of the switchpin
int prevSwitchState = 0;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
// set up the number of columns and rows on the LCD
lcd.begin(16, 2);
// set up the switch pin as an input
pinMode(switchPin,INPUT);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hit the button");
lcd.setCursor(0, 1);
lcd.print("to increment");
}
void loop() {
// step one revolution in one direction:
//Serial.println("forward");
myStepper.step(stepsPerRevolution);
// check the status of the switch
switchState = digitalRead(switchPin);
Serial.println(switchState);
// compare the switchState to its previous state
if (switchState != prevSwitchState) {
if (switchState == LOW ) {
hits = hits + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hits:");
lcd.setCursor(0, 1);
lcd.print(hits);
}
}
if(hits == 100){
myStepper.setSpeed(0);
}
// save the current switch state as the last state
prevSwitchState = switchState;
}