Hi all, I'm building device that moves a stepper motor based on input from two LDR's. I developed the code using simple contacts (for convenience), and it worked great.
I've removed the digital contacts, and installed two LDR's in A1 and A2, but the code no longer seems to work. When I monitor the LDR's I noticed that when I light one up w/ a laser, it increases as expected, but so does the other one (but less so). Even with this, there is a large enough difference that my triggers should work, but again... they don't.
Any help would be appreciated.
I know my motor works because I can load my button code and everything is still fine. I have the LDR's in A1 and A2 with a 10k resistor on the output of the LDR feeding the Analog input. Ground is attached on the same rail as the output of the LDR.
#include <Stepper.h>
const int sensor_1 = A1;
const int sensor_2 = A2;
int sensorValueA1 = analogRead(sensor_1);
int sensorValueA2 = analogRead(sensor_2);
const int stepsPerRevolution = 512;
// initialize the stepper library on pins 4 through 7
Stepper myStepper (stepsPerRevolution, 4, 5, 6, 7);
void setup()
{
// Set the speed of the stepper.
myStepper.setSpeed(15);
// initialize the serial port:
Serial.begin(9600);
analogReference(INTERNAL);
// pinMode(button_1, INPUT);
// pinMode(button_2, INPUT);
pinMode(sensor_1, INPUT);
pinMode(sensor_2, INPUT);
}
void loop()
{
// read the sensors
sensorValueA1 = analogRead(sensor_1);
sensorValueA2 = analogRead(sensor_2);
float voltage1 = sensorValueA1;(5.0/1023.0);
float voltage2 = sensorValueA2;(5.0/1023.0);
{
if ((analogRead(voltage1)<17) && (analogRead(voltage2)<17)) // Chassis on target
{
delay(100);
} // Wait's a tenth of a second before looking for new inputs.
}
{
if ((analogRead(voltage1)<17) && (analogRead(voltage2)>17)) // Chassis is below target
{
myStepper.step(1); // Track up
}
}
{
if ((analogRead(voltage1)>17) && (analogRead(voltage2)<17)) // Chassis is above target
{
myStepper.step(-1); // Track down
}
}
//Print sensor information
Serial.print("sensor_1 = "); //from site
Serial.println(voltage1);//from site //changed from sensorValueA1
Serial.print("sensor_2 = "); //from site
Serial.println(voltage2);//from site //changed from sensorValueA2
delay (1000);
}
As a side note, it's now started kicking me out of my Comm port. Not sure what that's all about, but I'm pretty sure it's pissed at me. HAHA!!
