Friday, March 13, 2015

Controlling a 120 VAC lamp

Suppose that instead of a low voltage LED as outlined in my last post we want to control a household lamp?  The microcontrollers we are using are DC devices and in any case they couldn't supply the voltages or current directly that a household lamp requires.

There is an easy solution and in fact the same identical code we used to blink an LED can be used to blink a lamp.  In fact, you could use it to control all sorts of things - not just lamps.  Here is the schematic:




















Bill of materials:
MSP-EXP430F-5529LP or other LaunchPad
PowerSwitch Tail II
Jumpers

Connections:
PowerSwitch Tail II:
Plug             120 VAC Household Receptacle
1: +in           MCU digital pin 2
2: -in            MCU GND
3: Ground    not used

Lamp:
Plug            PowerSwitch Tail II Receptacle

That's it - run the same code as the LED example and if you hooked up the digital pin the same it should work.  A couple of suggestions...

  1. There is an LED on the PowerSwitch Tail II.  Before plugging in the PowerSwitch test it with power only to the MCU.  It will blink the LED on the PowerSwitch and let you know if things on the low voltage side are working.
  2. Don't leave this blinking once per second for an extended period unless you want to burn it out.  The PowerSwitch is an optically isolated mechanical relay and the relay is rated for 100,000 cycles.  That is less than 28 hours at one switch per second.  On the other hand, if you are turning it on and off once a day it is about 137 years.  The video below shows it blinking once a second.
Here is the same code as the LED example, but with the variable names, comments, and delay between blinks changed.

Code:

/*
  Turns a lamp on and off repeatedly using a PowerSwitch Tail II optically isolated relay.
 
  This example code is in the public domain.
*/

const int PSTII = 2;         // note that this is the same as P6_5 on the 5529
                             // Pin 2 should work on most LaunchPads
                             // Connect the pin to "1: +in" on the PowerSwitch
                             // Connect GND to "2: -in" on the PowerSwitch
                             // "3: Ground" on the PowerSwitch is not used
void setup()
{                
  pinMode(PSTII, OUTPUT);    // initialize the digital pin as an output. 
}

void loop()
{
  digitalWrite(PSTII, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(10000);               // wait
  digitalWrite(PSTII, LOW);   // turn the LED off by making the voltage LOW
  delay(10000);               // wait

}



No comments:

Post a Comment