lightcontrol_icon.jpgIn this article we are programming the basic stamp to trigger a remote switch for your home lights or any other power switching device, like a garage door, fireplace and so on. We are controlling it through the web or the ipod (the ipod also has a web browser)

How does it work?
After programming the basic stamp, it looks for a specific variable; when it receives this variable we are putting a current on the output pin of the basic stamp. The current switches a relay, this closes the electronic circuit of the remote “klikaan klikuit” transceiver. The variable, where it all starts with, is send through the serial / usb port by a single web page.

Shopping list:

  • Micro controller Basic Stamp http://www.parallax.com
  • Breadboard 6″ board (not necessary)
  • DC power supply 5-9 V or regular 9V battery
  • 5V DC voltage regulator
  • 220 Ohm resistors 1/4 watt
  • Two TIP 122
  • (stiff) wires
  • two* 9-pin D-sub female
  • two* gender changers
  • two* USB-to-serial adapter including mini gender changer (if you don’t have a serial port)
  • two* serial connection cable (not a null-modem cable!)
  • some 5V relays (minimal of two, depending on the connections you want to make)
  • similar klikaan klikuit tranceiver.
  • similar klikaan klikuit receiver.

NOTE: *This project can be done by using a one serial cable setup. This is not recommended, you really don’t want to to switch your cables every time..

Making the scheme:
its all coming together when you’re making your test board. Connect the components by the following scheme. See the image for better understanding of the scheme.

First we look at the end result, this drawing will explain the parts:

lightcontrol_sheme2.jpg

here is a technical drawing of the wire connections..

Programming the basic stamp chip
Now before we can start programming we need to download a free basic program from parallax.
follow the link for win or mac installers: http://www.parallax.com/ProductInfo/Microcontrollers/BASICStampSoftware/tabid/441/Default.aspx

Once installed we can setup the program.
before we can go further we need to connect the serial cable and must know on which (COM) port it is connected. (for example: look at my computer -> preferences ->hardware config.)
We are connected to com port 14

Now connect the serial cable and power to the micro controller and launch the program.

ui.gif

1) Choose the basic stamp 2 code setup
2) Add pBasic language to version 2.5

port.gif

3) change the port setting to your com port, in our example this is port 14.

' {$STAMP BS2}

' {$PBASIC 2.5}

' {$PORT COM14}serData   VAR     Byte(10)

Main:

  SERIN 7, 16468, [WAIT("123"),  serData]

IF serData = 65 THEN

       GOSUB LichtAan

  ENDIF

IF serData = 66 THEN

       GOSUB LichtUit

  ENDIF

GOTO main

LichtAan:

HIGH 8

PAUSE 1000

LOW 8

RETURN

LichtUit:

HIGH 9

PAUSE 1000

LOW 9

RETURN

this code will be constantly running on the chip and will wait for the incoming data 123, When 123 passes it will be looking for the next Byte. In our case we will be sending the data 123 followed by A (representing ON) or B ( representing OFF) . So when we send the data 123A the chip has encountered the ‘A’ in ASCII DEC language this is 65. The char ‘B’ is 66, you get the point..
For a nice overview of the ASCII codes look here.

Installing a local server:
Now we need to set up a local server like wamp (For linux, any LAMP like setup will suffice). Why? This because we need a PHP page that sends the variable to the COM port. In our example sending data to the COM port will be done directly through PHP.

Setting up the pages and code..

We are using wamp for windows. If your using a other operating system use Lamp (linux) or Mamp (mac).

Download wamp

The installation wizard is really easy, just click next and next :) We don’t need to configure it (for now).

When wamp is running you will be seeing a small speedometer icon in you task bar..

Creating the PHP file (not yet ready for ipod use!):

  • Note! Make sure you set your com port correct!!

if (isset($_GET[’action’])) {
`mode com15: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen (”COM15″, “w+b”);
if (!$fp) {
echo “Uh-oh. Port not opened.”;
} else {
switch ($_GET[’action’]) {
case “on”:
$string = “123A”;
break;
case “off”:
$string = “123B”;
break;

}
fputs ($fp, $string );
fclose ($fp);
}
}

?>

Home Control:

Click here to turn the light on.

Click here to turn the light off.

Here is the iPod friendly code:

if (isset($_GET['action'])) {

`mode com15: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen (“COM15″, “w+b”);
if (!$fp) {
echo “Uh-oh. Port not opened.”;
} else {
$e = chr(27);
switch ($_GET['action']) {
case “on”:
$string = “123A”;
break;
case “off”:
$string = “123B”;
break;
}
fputs ($fp, $string );
fclose ($fp);
}
}
?>

Home Control

Overview:

  • Ceiling Lights

    on.gif, 1 kB


    off.gif, 0 kB
  • Garagedoor

    on.gif, 1 kB


    off.gif, 0 kB
  • Garden Lights

    on.gif, 1 kB


    off.gif, 0 kB
  • Fireplace

    on.gif, 1 kB


    off.gif, 0 kB
  • Curtains

    on.gif, 1 kB


    off.gif, 0 kB

And of course you can control the light trough the ipod by accessing the php code on the ipod Touch / iphone.

Just access your local server in your wireless home network, it should be similar to 10.0.0.15x

webapp_3.jpg

Download the files
This Zip package contains all the needed files to make the above application!

homeControl.zip

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati