Created sketch to turn on a two LEDs (LED6 and LED7) based on
a trigger from two motion dectectors (PIR [passive
infrared]), input 12 and input 11.
The operation of LED7 by input 11 is as designed,
that is the LED comes on when the PIR is triggered,
stays on for a about twenty seconds and the goes off.
But the behavior of LED6 is baffling.
When the Arduino is powered up both LEDs come on because
when intialized the PIRs send a signal. But then,
although LED7 is operating as expected,
LED6 will come on without being triggered or
come on and stay on without ever going off.
As a test input 12 PIR was removed. But LED6
continues to come on, usually about five seconds
after LED7 is triggered.
So input 12 was tied to LED7 and input 11 sent
to LED6. The same behavior was onbserved with,
in the swapped setup, LED7 exhibiting unpredictable
results and LED 6 operating normally.
Perhaps, with the input 12 removed the value of
val12 is floating and the program mistakes the
lack of a value for HIGH.
Hello apf1979,
Sorry, I meant to post the code and forgot.
Code posted herewith below.
The schematic changed so much in the PCB design that we never
got to updating it. But a JPG of the PCB design is posted. The project
Is actually eight PIRS controlling 7 LEDs with PIRs 1 thru 7 controlling
7 LEDs if the staircase is approached from below and PIRs 8 thru 2 controlling the 7 LEDs is approaching from above.
When the unusual behavior appeared the sketch
was pared down to focus on the the two channels that are erratic.
Thanks.
Allen Pitts
`/***********************************************************************************
* This sketch Staircase_PIR_6_w_directionality_230503.ino
* is based on
* Staircase_PIR_7_Directionality_220813.ino
* and eliminates L3 and P3
* See Arduino Sketches/Staircase Programming Log 220717.txt
* detailed logic
************************************************************************************/
// ++++ LED pin numbers ledPinX Output 2-10 ++++
int ledPin6 = 7;
int ledPin7 = 8;
// ++++ Input pin numbers for PIR inputPinXX A5-A0, 11, 12 13 ++++
int inputPin11 = 11; // 220504 acp
int inputPin12 = 12;
// ++++ PIR State pirStateXX = LOW ++++
int pirState11 = LOW; // 220504 acp
int pirState12 = LOW;
// ++++ Input status variable valXX A5 - 12, 13
int val11 = 0; // 220504 acp
int val12 = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// +++++ declare ledPinXX numbers as OUTPUT ++++
pinMode(ledPin6, OUTPUT); // declare LED6 as output
pinMode(ledPin7, OUTPUT); // declare LED7 as output
// ++++ declare inputPinXX numbers as INPUT ++++
pinMode(inputPin11, INPUT); // declare sensor11 as input 220504 acp
pinMode(inputPin12, INPUT); // declare sensor12 as input
}
// the loop function runs continuously
void loop(){
//Connect PIR inputPin12 to '+LED6-'
val12 = digitalRead(inputPin12); // read input value
if (val12 == HIGH) { // check if the input is HIGH
digitalWrite(ledPin6, HIGH); // turn LED ON
} else {
digitalWrite(ledPin6, LOW); // turn LED OFF
if (pirState12 == HIGH){
pirState12= LOW;
}
}
//Connect PIR inputPin11 to '+LED7-'
val11 = digitalRead(inputPin11); // read input value
if (val11 == HIGH) { // check if the input is HIGH
digitalWrite(ledPin7, HIGH); // turn LED ON
} else {
digitalWrite(ledPin7, LOW); // turn LED OFF
if (pirState11== HIGH){
pirState11 = LOW;
}
}
}
Try a 1 mega Ohm from the board IO pin to ground in case you are getting a floating value and let us know. If it does work, probably best to do them all the same way just in case.