Dark Places

IMG_0795

Extending the test code I built-in yesterdays LED post, I’ve  added a PIR motion sensor and a LDR (light detection) What we now have is when motion is detected AND the light level is below a certain level the LED’s will fade on to full brightness, stay on until motion is no longer detected and then fade down until off. A bit sexier than just on and off 🙂 I plan on setting something like this up using LED strips or the 2W LED’s. Living in an older house means that there’s not as many light switches nor sometimes enough lighting in the first place. Some of the hallways and outside entrances could really benefit from some sexy automatic lighting. I will rig something together temporarily soon(tm) to get the light thresholds correct before designing a nice encased unit.

Below is the code as it currently stands. Feel free to recommend improvements!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define LEDPin 6 //pin feeding TIP120
#define onboardLED 13 //onboard LED for some debugging
#define motionPin 4  //PIR connection
#define fadeSpeed 10 //Adjust how fast slow you want the fade effect to function
#define lightPin 5 //LDR connection
 
int led;
int motion;
int counter = 0;
int light;
 
void setup() {
//set pinmodes
  pinMode(LEDPin, OUTPUT);
  pinMode(onboardLED, OUTPUT);
  pinMode(motionPin, INPUT);
  pinMode(lightPin, INPUT);
  Serial.begin(9600); //start-up serial for outputting debug info
  int motion = LOW;
  led = 0;
 
}
 
void loop() {
 
  light = analogRead(lightPin); //read light levels
  Serial.print("Light Level: "); 
  Serial.println(light);  //send light levels to serial
  motion = digitalRead(motionPin); //read motion from PIR
 
  Serial.print("Motion: "); 
  Serial.println(motion);  //send motion state to serial
  Serial.println(led);
 
  if((light > 500) && (motion == 1)) { //if motion detected and light level below a certain level, do this
    while (led < 255) { //led below full brightness? 
      led++; //increment fade up to full powahs
      analogWrite(LEDPin, led); //write change to LED control Pin into TIP120
      delay(fadeSpeed); 
      break; //need to try this remarked out when arduino is out of testing location
     }
   }   
  else if((motion == 0) && (led > 0)) { //otherwise if motion not detected and led value is on, fade down
    led--; 
    analogWrite(LEDPin, led);
    delay(fadeSpeed);
 
  }
 
  else {
    // delay(250);
    // Serial.println("delay");
  }
}

Links to some Parts:

2W LEDS – DealExtreme
PIR Sensor
 – Deal Extreme
TIP120 Power Darlington Transistors – Adafruit

Posted in Arduino, Electronics | Tagged , , , , , , | Leave a comment

Sidetracked with LED’s

I was playing with some TIP120 Power Darlington transistors trying to bend them to my will, when I got completely sidetracked….. sort of, with Some 2W LED’s I got a while ago.

IMG_0791

 

 

These bad boys need to be soldered onto a heat sink as they get pretty hot and die quickly without anyway to dissipate the heat. Luckily i have a billion of them handy. The tricky thing is I need a 1 Ohm resistor….. Lowest I have is a 220 Ohm one (Sad Panda) I remember this huge bad boy resistor from a power supply that was beyond repair (transformer blown) I dug it up and actually found what I needed! There were 3 x 1 Ohm 5W resistors on it! Perfect. Desoldered them and grabbed some thermal compound. Have everything I need now!

IMG_0790

IMG_0792
Once I put them all together I attached them to 12V of Powah to see what we got…

IMG_0795

IMG_0796

The Camera did a great job of turning the Mini Sun into something vaguely view-able in a picture. Every time I glance at it I’m blinded in that part of my eye. Har. Anyway I got sidetracked into this by trying to run a 12V strip of LED’s through the TIP120 so I could fade it in and out. For some reason though whether I pump 12V into it or 15 I am only seeing around 7V entering the LED strip. Whats going on! I needed something else 12V for some testing. 2W LEDs it was! Specs of the 2W LEDs are:

– Power: 2W
– Rated voltage: DC 3.0V~3.2V
– Rated current: 600~650mA
– Brightness: 160~180LM
– Color temperature: 2850~3050K

12V (Supply Voltage)/3V (Rated Voltage) =12V

LEDs always need a resistor in series with them to stop thermal runaway. Other wise I believe, as the LED heats up its resistance lowers allowing more current, which makes it heat up more, which lowers its resistance more, repeat, repeat, supernova. While not necessarily causing a popped LED straight away it will lower the life of the LED considerably. (Disclaimer this info is dredged up from parts of my Brain that are quite old and could be totally wrong! Please correct me if I’m wrong!) The value of the resistor you need to use will change depending on your LED specs and voltage used. Just google for a LED calculator and save yourself some maths.

 

Anyhoo! Back on track. Using an Arduino Uno and a TIP120 Darlington transistor I setup the same fade I was trying to use on the strip. Low and behold….. Its working fine. I’ll need to grab the data sheet for the TIP120 and see if I can figure out whats going on. I imagine I’m overloading it perhaps.

 

the Arduino can only supply 5V and around 40mA of current on its Pins so you can’t just run huge Loads of its pins directly. This is where the TIP120 comes in! Using a PWM Pin on the Arduino you can alter the Pins output to vary the voltage output which the TIP120 can use to step your larger voltage by! For example 1V output on the Arduino could be 8V from the Darlington transistor. This can vary on the type of transistor you have of course, check the data sheet.

A video of the pulsing can be seen on YouTube here. I cant figure out how to embed it right now and its getting late!. The humanity! Will come back and fix it later. The fade isn’t quite the whole range of the pulse. I’ve taken the min and max into around 50 –  230

Here is my Arduino code:

#define LEDPin 6
#define onboardLED 13

#define fadeSpeed 10

void setup() {

pinMode(LEDPin, OUTPUT);
pinMode(onboardLED, OUTPUT);
Serial.begin(9600);
}

void loop() {
int led;

// Fade in
for (led = 30; led < 230; led++) {
analogWrite(LEDPin, led);
analogWrite(onboardLED, led);
delay(fadeSpeed);
Serial.println( led );
}

//Fade out
for (led = 230; led > 30; led–) {
analogWrite(LEDPin, led);
analogWrite(onboardLED, led);
delay(fadeSpeed);
Serial.println( led );
}
}

This is all part of a project for some LED lighting around the house hooked up to some motion detectors and LDRs (Light Detecting Resistors?) Instead of just lights on, lights off a nice gentle fade in and out at specified times will look a treat! Moar later!

 

Posted in Arduino, Electronics | Tagged , , | 1 Comment