Arduino to Transistor and LEDs controlled by PIR sesnsor

Status
Not open for further replies.
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

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
    }
  }
}
 
The first thing I'd do is to double check the pinout of the transistor. Here is the datasheet for the BD437.
https://www.onsemi.com/pub/Collateral/BD437-D.PDF

As for voltage measurements. The voltage at the base of the transistor should be at about 0.6V when the signal coming from the Arduino is 5V. And zero when the Arduino voltage is zero.

Also, make sure that the value of R8 matches the current you want through the LEDs. The LED current will be (5V) - (LED forward voltage) / (R8 resistance.)
 
I know nothing about Arduinos, but you are driving the LED from an analog input A0.

Would it not be more appropriate to drive it from a digital output?

JimB
 
With the 18 LED setup, you can't simply parallel them, each LED needs it's own current limiting resistor. You may be able to connect two in series and use a 50 ohm series resistor and have 9 chains of these. To test it just blink the LEDs until you know that part is working.

Mike.
 

The LED (or the base of the transistor driver) should be connected to a digital pin and the digital pin configured as an output
 
Some of the others have said that you need to connect a digital output of the Arduino to the LED or driver board input. That is correct, but as far as I can see you are configuring A0 to be a digital output, which is fine. The fact that it can, at other times, be an analog input doesn't mean you've got it configured incorrectly.

You can test the control board without the Arduino. When you connect the input of the control board to +5 V, the LED should come on.

The connection that worked would have had the LED illuminate when the Arduino output was low, while the connection with the control board should have had the LED illuminate when the Arduino output was high. There is no problem with that, as long as you are aware of the difference.
 
Hello ChrisP58, JimB, Pommie, eTech, Diver300 and the ETO forum,

Thanks for the replies.

to ChrisP58
The info on the voltage measuements is helpful. Will get out
the mulimeter and check.


On the value of R8: the LED forward voltage is 3.3 volts
5V minus (3.3 v / 470 ohms) looks like 5-(.007) or 4.99 volts. Right?

to JimB
The A0 on the Arduino can be either digital or analog.
The system, when complete would have eight sensors and seven LED groups
so almost all of the pins, analog and digital, on the Arduino will
be employed. The analog pins can be used as digital outputs but
not conversely.

to Pommie
Will look at rewiring the LEDs in series. Thanks.

to eTech
Same as JimB

to Diver300
Will try testing by connecting the input of the control board
to the +5V. But I tried connecting the output of the PIR to
the control board input w negative result, that is nothing happens.

to the ETO forum
It is conjectured that the arrangement of R1, Q1
and R8 puts R1 and R8 in serial and therefore a cumulative
480 ohms. And it is this subsystem, marked 'Control board'
at the diagram titled 'Subsytem Test....' that is thought
to be the fly in the ointment. All the other components,
the PIR, the Arduino, the power supply, the LEDs have
been tested operational as expected. The only functional
block that has not been tested is the R1, Q1, R8 group.
If there is a method for turning the transistor on
and off and testing the transistor switching the LED
on and off that would be most helpful. (I just realized
that such a test is what has been suggested by
Diver300.)

I also get a lot of good counsel from the guys
at the Dallas Makerspace Electronics room. A great
gentleman there is Richard Meyer PE, EE. Mr.
Meyer suggests reducing the value of R1 from
470 ohms to, say, 220 ohms. Will also try that when
I get off work this evening.

Thanks again. It is written: 'The gods will smile on
he that helps a lost stranger.'


Allen in Dallas
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…