Hello AAC Forum,
Working on a circuit to control an LED display which
uses a PIR sensor to an Arduino microcontroller.
Code copied below.
For some reason I don't understand LED2, which indicates an out put from the Arduino, was not coming on. LED1, which indicates a signal from the motion detector was coming on. So I decided to switch out the LEDs in case one bad.
When LED1 was removed LED2 came on. So when LED1 is inserted LED2 goes off and when LED1 is inserted LED2 goes off. Its like the ground of LED2 is keeping LED2 from being grounded or something.
How can I get both indicators to work?
Thanks.
Allen Pitts, Dallas Texas
+++++++++begin Arduino sketch++++++++++++++
/*
* PIR sensor to Arduino
Allen Pitts pittsallen@usa.net 160407 */
int ledPin1 = 10; // choose the pin for the LED
int inputPin = 5; // choose the input pin (for PIR sensor)
int pirState = LOW; // start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin1, LOW); // turn LED OFF
// digitalWrite(ledPin2, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
+++++++++End Arduino sketch++++++++++++++
Working on a circuit to control an LED display which
uses a PIR sensor to an Arduino microcontroller.
Code copied below.
For some reason I don't understand LED2, which indicates an out put from the Arduino, was not coming on. LED1, which indicates a signal from the motion detector was coming on. So I decided to switch out the LEDs in case one bad.
When LED1 was removed LED2 came on. So when LED1 is inserted LED2 goes off and when LED1 is inserted LED2 goes off. Its like the ground of LED2 is keeping LED2 from being grounded or something.
How can I get both indicators to work?
Thanks.
Allen Pitts, Dallas Texas
+++++++++begin Arduino sketch++++++++++++++
/*
* PIR sensor to Arduino
Allen Pitts pittsallen@usa.net 160407 */
int ledPin1 = 10; // choose the pin for the LED
int inputPin = 5; // choose the input pin (for PIR sensor)
int pirState = LOW; // start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin1, LOW); // turn LED OFF
// digitalWrite(ledPin2, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
+++++++++End Arduino sketch++++++++++++++