Hi, I am trying to use three different obstacle sensors with my Arduino Uno. For some reason only one will work at a time. Is there a reason for this? If not, posting a simple program using multiple sensors which I can learn from would be super helpful.
The sensors I am using are "IR Transmitting and Receiving Tube Photoelectric Switch"
Thanks!
int airHose = 11; // STAGE ONE VALVE (SINGLE)
int entrySensor = 2; // This is our input pin
int entrySensor1 = HIGH; // HIGH MEANS NO OBSTACLE
int primaryForkValve = 13; // STAGE TWO VALVE PART ONE
int pistonSensor = 3;
int pistonSensor1 = HIGH; // HIGH MEANS NO OBSTACLE
int topValve = 12; // STAGE TWO VALVE PART TWO
int isObstaclePin3 = 4;
int isObstacle3 = HIGH; // HIGH MEANS NO OBSTACLE
int x = 0;
void setup() {
pinMode(airHose, OUTPUT);
pinMode(entrySensor, INPUT);
pinMode(primaryForkValve, OUTPUT);
pinMode(pistonSensor, INPUT);
pinMode(topValve, OUTPUT);
pinMode(isObstaclePin3, INPUT);
Serial.begin(9600);
}
void loop() {
entrySensor1 = digitalRead(entrySensor);
pistonSensor1 = digitalRead(pistonSensor);
isObstacle3 = digitalRead(isObstaclePin3);
if (entrySensor1 == LOW)
{
Serial.println("Stage 1 active");
//Part one
digitalWrite(airHose, LOW);
delay(200);
digitalWrite(airHose, HIGH);
//Part two
digitalWrite(topValve, LOW);
digitalWrite(primaryForkValve, HIGH);
delay(1000);
while (pistonSensor1 == HIGH)
{
if (pistonSensor1 == LOW);
{
Serial.println("if loop start");
digitalWrite(topValve, HIGH);
delay(1000);
digitalWrite(topValve, LOW);
digitalWrite(primaryForkValve, LOW);
delay(1000);
}
Serial.println("if loop over");
break;
}
delay(1000);
}
{
Serial.println("Stage one clear");
digitalWrite(airHose, HIGH);
}
delay(200);
}