Turn on an led in a low voltage circuit

It's almost the holiday season and you might want to get geekie. If you are unsure about this, get profession help for the project. Try this at your own risk. We take no responsibilities for anything you may or may not do. This article is not a how to, but it is informational.



What we want to do is to control lighting so that we can turn it off or on with electronic equipment instead of doing it manually with a traditional light switch.


In this case, we may want to control holiday lights Such as an Xmas tree.



We could use the light switch like above, or we can use a computer or a micro-controller. In this case we will suggest three posiblilities. The computer using a
traditional parallel port, A raspberry Pi, or an Arduino.

The simplest way to do this is with a solid state relay. Basically it is just like turning on an led.

If you turn on the data line so it goes to near 5 volts, the led will turn on  or the SSR will allow the output side to work. An SSR let you control the switch but the low voltage circuit when hooked up correctly will be isolated from the circuit being controlled.

When the SSR is controlled electronically, we can program how the lights will come on or go off.



Parallel port: using a breakout cable





Code:

In FreeBasic we would use:

out 888, (2^0) or out 888, 1
to turn on the Led and
out 888, 0
to turn off the led.


Raspberry Pi: (Raspberry Pi ver, B will be different also). Note: normally the resistor and the led would be in opposite positions.


Code:

Oldest version
-----------
# Turn light on
cd /sys/class/gpio
# Turn on pin but defaults to low.
echo 17 > export
# Set port direction in this case we aredoing output.
echo out > gpio17/direction
# Set pin high and turn on led.
echo 1 > gpio17/value
#Turn light off
echo 0 > gpio17/value
-----------------------------------
Newer version: You have to use the full path with commands.
# Turn light on
cd /sys/class/gpio
# Turn on pin but defaults to low.
echo "17" > /sys/class/gpio/export
# Set port direction in this case we aredoing output.
echo "out" > /sys/class/gpio/gpio17/direction
# Set pin high and turn on led.
echo "1" > /sys/class/gpio/gpio17/value
#Turn light off
echo "0" > /sys/class/gpio/gpio17/value


Arduino:


 
 

Code:
 
/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}
 
So you could use the same resistor and led combination for all three devices. 
So once you have done it for one, you can easily do it for the others! If you 
want to control several leds, it gets fun like the video above.
 
Beaglebone Black. 


Code:

var b = require('bonescript');
var led = "P8_13";
var state = 0;

b.pinMode(led, 'out');
toggleLED = function() {
    state = state ? 0 : 1;
    b.digitalWrite(led, state);
};

timer = setInterval(toggleLED, 100);

stopTimer = function() {
    clearInterval(timer);
};

setTimeout(stopTimer, 30000);

Comments

Popular posts from this blog

Guiless?

MSOffice vs Libreoffice

Raspberry pi zero.