Question
below is my code for arduino program, I would like a infrared sensor to give input for its respective relay. For example, IR sensor #3
below is my code for arduino program, I would like a infrared sensor to give input for its respective relay. For example, IR sensor #3 reads motion, activate relay #3 for 3-5 seconds. I would like the program aswell to constantly run. Currently the compiler says that "val1" is undeclared in the scope. CODE >>>>>
int inputpin1 = 1 ; // setting up the inputs from the six infrared sensors int inputpin2 = 2; int inputpin3 =3; int inputpin4 =4; int inputpin5 =5; int inputpin6=6; int outputpin1=7; // setting up the outputs for the 8 channel relay int outputpin2=8; int outputpin3=9; int outputpin4=10; int outputpin5=11; int outputpin6=12;
int pirState1 = LOW; int pirState2= LOW; int pirState3= LOW ; int pirState4 = LOW; int pirState5= LOW; int pirState6= LOW ;// we start, assuming no motion detected int val1 = 0; int val2 =0; int val3 =0; int val4 = 0; int val5 =0; int val6 =0;// variable for reading the pin status void setup() { pinMode(inputpin1, INPUT); pinMode(inputpin2, INPUT); pinMode(inputpin3, INPUT); pinMode(inputpin4, INPUT); pinMode(inputpin5, INPUT); pinMode(inputpin6, INPUT); // declare 6 sensors as input pinMode(outputpin1, OUTPUT); pinMode(outputpin2, OUTPUT); pinMode(outputpin3, OUTPUT); pinMode(outputpin4, OUTPUT); pinMode(outputpin5, OUTPUT); pinMode(outputpin6, OUTPUT); //declare 6 relay channels as output Serial.begin(9600); } void loop(){
va11= digitalRead(inputpin1); va12= digitalRead(inputpin2); //constantly reading for input from sensor va13= digitalRead(inputpin3); va14= digitalRead(inputpin4); va15= digitalRead(inputpin5); va16= digitalRead(inputpin6); if (val1 == HIGH) { val2= LOW; /set all values for input low to avoid other relays val3= LOW; val4= LOW; val5= LOW; val6= LOW; delay(10000); // delay of 10 seconds digitalWrite(outputpin1, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed } else if (val2 == HIGH) { val1= LOW; /set all values for input low to avoid other relays val3= LOW; val4= LOW; val5= LOW; val6= LOW; digitalWrite(outputpin2, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed delay(10000); // delay of 10 seconds, } else if (val3 == HIGH) { val1= LOW; /set all values for input low to avoid other relays val2= LOW; val4= LOW; val5= LOW; val6= LOW; digitalWrite(outputpin3, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed delay(10000); // delay of 10 seconds, } else if (val4 == HIGH) { val1= LOW; /set all values for input low to avoid other relays val2= LOW; val3= LOW; val5= LOW; val6= LOW; digitalWrite(outputpin4, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed delay(10000); // delay of 10 seconds, } else if (val5 == HIGH) { val1= LOW; /set all values for input low to avoid other relays val2= LOW; val3= LOW; val4= LOW; val6= LOW; digitalWrite(outputpin5, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed delay(10000); // delay of 10 seconds, } else if (val6 == HIGH) { val1= LOW; /set all values for input low to avoid other relays val2= LOW; val3= LOW; val4= LOW; val5= LOW; digitalWrite(outputpin6, HIGH); // force the respective relay channel to activate and complete the circuit hence moving the bed delay(10000); // delay of 10 seconds, } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started