I'm very new to Arduino, and i'm trying to figure out how to work my project I built. I'm using 4x photo resistors (in a circle), and 1x laser diode. My goal is for the laser to go across the photo resistors in a clockwise, or counter-clockwise motion. When the laser hits them, it will indicate what photo resistor it is on, and send it to turn 90 degrees. I was able to code 1 for testing to do what I want, but having issues when trying to code the others. Any help is appreciated! Below is what I am working on. Trying to work with the second photo resistor.
int sensorValue0;
int sensorValue1;
int sensorValue2;
int sensorValue3;
int laserPin = 12;
int PreviousPC0 = 0;
int PreviousPC1 = 0;
//boolean Sensor1Hit = false;
//boolean Sensor2Hit = false;
//boolean Sensor3Hit = false;
//boolean Sensor4Hit = false;
void setup() {
// initialize the serial communication:
pinMode(laserPin, OUTPUT);
digitalWrite(laserPin, HIGH);
digitalWrite(laserPin, HIGH);
Serial.begin(9600);
PreviousPC0 = analogRead(A0);
PreviousPC1 = analogRead(A1);
//Sensor1Hit = true; //assumption that sensor 1 is starting point
// sensorValue1 = analogRead(A1);
// sensorValue2 = analogRead(A2);
// sensorValue3 = analogRead(A3);
Serial.println("STARTING");
}
void loop() {
sensorValue0 = analogRead(A0);
sensorValue1 = analogRead(A1);
sensorValue2 = analogRead(A2);
sensorValue3 = analogRead(A3);
if ( ((sensorValue0 - 100) <= PreviousPC0) && (PreviousPC0 <= (sensorValue0 + 100))) {
// do
Serial.print("SV0: ");
Serial.println(sensorValue0);
Serial.print("PSV0: ");
Serial.println(PreviousPC0);
}
else
{
Serial.println("ELSE1");
if (PreviousPC0 > sensorValue0) {
//do nothing
Serial.println("Off Sensor 1");
}
else {
// send movement to other program
Serial.println("ON Sensor 1");
if ( ((sensorValue1 - 100) <= PreviousPC1) && (PreviousPC1 <= (sensorValue1 + 100))) {
// do
Serial.print("SV1: ");
Serial.println(sensorValue1);
Serial.print("PSV1: ");
Serial.println(PreviousPC1);
}
else
{
Serial.println("ELSE2");
if (PreviousPC1 > sensorValue1) {
//do nothing
Serial.println("Off Sensor 2");
}
else {
// send movement to other program
Serial.println("ON Sensor 2");
}}
//if Sensor4Hit = true {
//send CW
}
//if Sensor2Hit = true {
//send CCW
}
//Sensor1Hit = true;
//Sensor2Hit = false;
//Sensor3Hit = false;
//Sensor4Hit = false;
Serial.print("Photoresistor1: ");
Serial.println(sensorValue0);
Serial.print("Photoresistor2: ");
Serial.println(sensorValue1);
Serial.print("Photoresistor3: ");
Serial.println(sensorValue2);
Serial.print("Photoresistor4: ");
Serial.println(sensorValue3);
PreviousPC0 = sensorValue0;
delay(1500);
}