AllenPitts
Member
Hello Electrotech forum,
Working on a project using an Arduino, PIRs and transistors to control groups of LEDS.
Having the devil of a time getting it to work so I simplified the system down to one PIR
and one group of LEDs controlled by a transistor
Still can't get it to operate the LEDs.
So to just get something to work I simplified it further thinking there might be a power problem
with 18 LEDS,
Still no joy.
So to test that a signal was coming from Arduino pin A0 I connected the output from the microcontroller,
thru a resistor to the LED.
The LED then operated as expected.
(The Arduino sketch, copied herewith below is pretty simple. It declares to variables, one for the sensor input,
and for ouput to the LED and then tells the LED if it gets a signal from the PIR to turn the LED on for one
second.)
So there is something wrong in the area marked 'Control Board'. I tried putting a probe at R1 and to ground
and there is a 5 volt signal coming from the Arduino for a second after there is movement at the PIR.
So I think there is some defect in the logic at the transistor but can't figure it out.
Thanks.
Allen in Dallas
Working on a project using an Arduino, PIRs and transistors to control groups of LEDS.
Having the devil of a time getting it to work so I simplified the system down to one PIR
and one group of LEDs controlled by a transistor
Still can't get it to operate the LEDs.
So to just get something to work I simplified it further thinking there might be a power problem
with 18 LEDS,
Still no joy.
So to test that a signal was coming from Arduino pin A0 I connected the output from the microcontroller,
thru a resistor to the LED.
The LED then operated as expected.
(The Arduino sketch, copied herewith below is pretty simple. It declares to variables, one for the sensor input,
and for ouput to the LED and then tells the LED if it gets a signal from the PIR to turn the LED on for one
second.)
So there is something wrong in the area marked 'Control Board'. I tried putting a probe at R1 and to ground
and there is a 5 volt signal coming from the Arduino for a second after there is movement at the PIR.
So I think there is some defect in the logic at the transistor but can't figure it out.
Thanks.
Allen in Dallas
Code:
/*
Arduino with PIR motion sensor
For complete project details, visit: http://RandomNerdTutorials.com/pirsensor
Modified by Rui Santos based on PIR sensor by Limor Fried
*/
int led = A0; // the pin that the LED is atteched to
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(1000); // delay 1000 milliseconds
if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}