Wednesday, January 4, 2012

Christmas Cheerlights

This year I joined a few other guys in the Cheerlights project.

CheerLights is an ioBridge Labs project that allows people's lights all across the world to synchronize, stay linked based on social networking trends. It's a way to connect physical things with social networking experiences and spread cheer at the same time. We are all connected.

Whenever anyone tweeted @cheerlights or #cheerlights and a color, my house lights (just the deck icicles) changed to that color.




I was a bit of a rebel and decided to change to the tweeted color just for 1 minute instead of just leaving the lights constantly to the selected color. After 1 minute the stockplus program for GE G-35 Color Effects Lights written by sowbug (https://github.com/sowbug/G35Arduino) took over.


I couldn't resist not using the random mode: these lights are just amazing, and the effects are REALLY cool.

My setup was wireless. I used an ioBrigde module, xbee radios and an arduino to accomplish this.






The other cool part about this year's Christmas lights is that they were programmed to start/stop via a cronjob. I used the ioBridge x10 board and a bunch of x10 devices to accomplish this.

Cronjob entry:

-bash-3.2$ crontab -l

30 15 * * * /oracle/start_cheerlights > /dev/null
00 21 * * * /oracle/stop_cheerlights > /dev/null

Bash script:


#!/bin/bash
#Upastairs
curl "http://www.iobridge.com/widgets/static/id=XXXXXXX&value=1"
#Downstairs
curl "http://www.iobridge.com/widgets/static/id= XXXXXXX&value=1"


*change value 1 for On and 0 for Off.


I also setup an IP webcam to keep an eye on my cheerlights remotely.
For more info on how you can build you own check http://www.cheerlights.com/

Tuesday, February 1, 2011

Ski Resort Desk Snow Meter (Snowbird)

As my snowboarding trip approaches, I find myself checking Utah Snowbird's snowcam (http://www.snowbird.com/snowcam.html) a few times a day, wishing for more snow to accumulate on my favorite ski resort.

So as a fun mini-project I decided to create my own Snowbird Desk Snow Meter! The Meter displays the snow accumulated in the past 24 hours and it gets updated hourly.


As a bonus feature I setup a Twilio phone line to call and get my personalized Snowbird snow report. Click Play below to hear what I get when I call my twilio number.





For more information check my Instructable http://www.instructables.com/id/Ski-Resort-Desk-Snow-Meter-Snowbird/

Tuesday, October 26, 2010

Automatic Halloween Candy Dispenser

This year my Halloween project is the Automatic Halloween Candy Dispenser® triggered by TextforTreat®, CallforTreat® (powered by Twilio)and @TweetforTreat® technologies. Of course it can also be triggered from a Big Red push button, but where is the fun in that?

When trick-or-treaters show up at my house they can text, call, or tweet a code displayed on an LCD screen to get their Halloween candy. They can also push the Big Red button.

Once the candy request is made a few "special" effects are triggered by X10 modules. A low laying fog machine is activated and lights turn on while the candy shoots down from my front deck on the second floor.

* Check my Instructable write up for more detailed information.




Candy Dispenser
Control Box
Main Box
Communication Bridge
Fog Machine
Lights and accesories


Candy Dispenser


The first thing was to figure out a good way to hold the candy and dispense it. I used a plastic bucket, a metal ventilation pipe and a CD attached to a servo motor. I figured that by having the candy dispense from the side as opposed to the bottom would allow the candy to move more freely and avoid candy jams.

The ventilation pipe comes in a "U" shape, so I made a "U" shaped cut in the bottom center of the bucket. Notice I did't cut the whole "U", instead I left a piece of plastic in the middle to hold the servo motor that rotates the CD.

After I inserted the ventilation pipe I did a few cuts to allow me to expand the pipe into a sheet form. I used a couple screws and bolts to keep the sheet attached to the bucket.  The rest of the space was covered by the mighty duck tape.

I cut the CD to allow the candy flow when rotated. Also I duck taped a continuous servo inside to function as a "shaker."


Control Box

The control box is pretty simple. I drilled/dremelled a few holes to attach the big red button, ioBridge LCD screen,  power jack and the RJ45 jack.

I really like the use of CAT 5 cable to make things more modular.

Main Box

The main program runs in the Arduino Duemilanove.  When the board is initialized it immediately makes a Web call to check for the current code and displays it on the LCD screen.

The main loop is waiting for either a physical push of the big red button or to receive a remote serial message. The attached XBee module communicates with another XBee module connected to the ioBridge IO-204 module serial board.

These are the digital I/O pins configuration:
  • XBee Module (with adafruit XBee kit)
    • Pin 13 - TX 
    • Pin 12 - RX
    • Gnd and 5v
  • Big Dome Push Button
    • Pin  8 - Button NO(normally open) +  GND + 100K. 
    • 5v - COM
  • Servo 1 (continuous rotating servo used for shaking)
    • Pin  7 - Data
    • Gnd and 5v
  • Servo 2 (used to rotate the CD)
    • Pin 6 - Data
    • Gnd and 5v
  • X10 C17A (x10 devices controller)
    • Pin  3 - DTR line for C17A - DB9 pin 4
    • Pin  2 - RTS line for C17A - DB9 pin 7
    • Gnd  - DB9 pin 5
  • ioBridge 16x2 serial LCD display
    • Pin 1 - LCD Data pin
    • Gnd and 5v
Attached is the Arduino Sketch, it also includes a library to control the ioBridge LCD screen.

Code Generator

I realized that someone with mischievous intentions could just tweet-spam the @Tweetfortreat account (or less likely someone could text or call my Twilio number numerous times) and I would end up with tons of candy on the floor.

Instead, I created a REST web service using of course my favorite web development tool, Oracle Application Express http://apex.oracle.com/ , to make sure a unique and random code was generated each time candy drop request was made from text, call or Twitter.

The REST application is really simple and I recognize it can also be created using any other technologies such as LAMP or even a GCI, or Perl application.

Application Objects:
  • 1 Table (ID,CODE,SELECTED)
  • 1 Numerical Sequence to generate primary key (ID)
  • 1 Trigger before insert record that will get the ID value and append a random number to the CODE column
  • 1 public procedure to retrieve the code (where selected = 1)
  • 1 public procedure to update the code once is used and generate a new one.
So I ended up with these two URL
http:/my.apexserver.com/pls/apex/getcode
http:/my.apexserver.com/pls/apex/updatecode?code=XXXX
*If you would like to implement something with a static file instead, I would recommend using http://www.random.org/clients/http/ to get a random number and store it in file, memory, or even the arduino itself.

ioBridge Setup

The ioBridge IO-204 is used as bridge (duh!) between the arduino and the internet. I am using the ioBridge serial board to connect an XBee module.

There are two main functions that the ioBridge was used for:
  1. Request current code
     I do a GET call from the arduino to retrieve the current code from my Code Generator service using ioBridge Serial Web Services API.
     Arduino code:
     mySerial.println("[[[get|http:/my.apexserver.com/pls/apex/getcode]]]");

      
  2. Start candy dropping sequence by text, call or tweet.
     An ioBridge widget will send a start character via serial message and the candy dropping sequence will start. This widget can be called using the ioBridge Static Widget API.
This URL  is called by Twilio and by my custom Twitter alert script.

http://www.iobridge.com/widgets/static/id=[widgetID]


These are the digital I/O pins configuration:
  • ioBridge Serial Board
  • TX - RX XBee
  • RX - TX XBee
  • GND and 5v

Twilio Setup


Twilio is a web-service API for communication apps. Twilio is as simple as it gets. It only  took me a short time to get my  SMS and Voice applications up and running! I had tried in the past to create similar applications with other technologies (VoiceXML and even Google Voice) and let me tell you is not that easy.

The voice application answers the phone, plays an intro sound file and asks for the code followed by the # sign. If a code is detected Twilio will do a "GET" action to a PHP file that will lookup the current code from my Code Generator Web Service. If it matches it will call the ioBridge static widget URL and candy will be dispensed.

The SMS application has almost the same PHP code except this time instead of looking for the digits dialed  it will look for body of the SMS message.

Check the attached XML and PHP files that generate the TwiML XML.

All in all Twilio is a winner and I have plenty of other ideas for the future.

Twitter Setup


No modern internet enabled project is complete without Twitter integration, right? :) Here is mine: This time i used a bash script, twurl and a crontab job to check for replies to @tweetfortreat. This bash script is running on my Sheevaplug, but it can be run in any linux/mac machine or it could be adapted to run as .bat in windows (using scheduled tasks).

Twurl is almost like curl but for Twitter. I did some ugly parsing of the twitter RSS feed to retrieve the tweet sender, but it works!

Here is my bash script
#!/bin/bash
mycode=`curl --silent http:/my.apexserver.com/pls/apex/getcode`
twitter=`twurl /1/statuses/mentions.rss | grep "@tweetfortreat $mycode" | cut -d ':' -f1 | tail -n 1 | cut -d '>' -f2`
echo $mycode $twitter
if [ -n "$twitter" ]; then
iobridge=`curl --silent http://www.iobridge.com/widgets/static/id=[widgetID]`
newkey=`curl --silent -d "code=$mycode" http:/my.apexserver.com/pls/apex/updatecode`
update=`twurl -d "status=@$twitter The code $mycode is correct. Happy Halloween!" /1/statuses/update.xml`
echo $newkey $iobridge
fi

Crontab will only allow you to execute a script every minute and I think is fine for now. Alternatively a while loop could be used instead.
Here is my crontab entry

*/1 * * * * /script_location/HalloweenCandy.sh > /dev/null 2>&1

Conclussion and Alternatives
If my Google skills (http://lmgtfy.com/?q=automatic+halloween+candy+dispenser)serve me well there are just not many documented Automatic Halloween Candy Dispensers out there. I did run into this one which I really like but is limited to M&Ms sized candy.I found some inspiration from the dog/cat feeders built using the internet enabled ioBridge http://support.iobridge.com/projects/tag/dog-feeder/.

I hope to see more iterations of the Automatic Halloween Candy Dispenser next year. Please make sure you share all your ideas/improvements in the comments section.


Happy Halloween!

Monday, November 30, 2009

xmas-box: Arduino/ioBridge internet controlled Christmas lights and music show

Update - Please check my Instructable for more detailed pictures!


Update 2 - I was featured in engadget.com and hackaday.com


My xmas-box project consists of an internet controlled Christmas lights and music show. A Christmas song can be requested on-line which is then put in a queue and played in the order it was requested. The music is transmitted on an FM station within a 300 ft radius from my house.

The xmas-box has 8 Channels  (power outlets) where different light modes can be played: vu meter style, ascending, descending, split, merge, sequence and random. During each song one of these modes is used randomly every 10 seconds (to make the show less monotonous).

I started my research right after Halloween and I came across a couple different options, but I settled with the following combination of hardware : arduino + adafruit wave shield + ioBridge + wifi bridge + solid state relays (SSRs).

The xmas-box is enclosed in a small plastic tool box. I have place it on my deck under a roof ( it is not completely weather proof). The tool box has "3 levels." The bottom is where all the SSRs and AC wiring are located. The middle (the inside tray) contains the wall warts for the arduino (9v), ioBridge (5v) and Wifi Bridge with power. The top level contains the Arduino board, the ioBridge module and the FM transmitter.

This is the first time I lit my house so I was just able to put 3,300 mini lights, 3 spotlights,1 LED Rope, 4 LED (40 led each) branch trees and 1 reindeer. I hope the lights last so I can keep adding each year.

















BoM - Bill of Materials
Here is the list of materials I used for the xmas-box:
Relay Setup
WARNING
You will be dealing with AC power. If you don't feel comfortable or you are not sure how to handle AC, please consult a licensed electrician before starting to wire the relays.


A great advantage of using SSRs instead of mechanical relays is that I did not have to add any diodes, transistors, or resistors. Also since there there is no mechanical dependency the switching will be smoother. I would advise to use a breadboard with 1k resistors and different color LEDs during your prototyping. Then when you are ready you can use the SSRs and real Christmas lights.

The connections are pretty straight forward. I daisy chained the ground coming from the Arduino to each of the 8 SSRs. Then 8 digital outputs from the Arduino were connected to each positive of the 8 SSRs.

I gutted the
PowerSquid Power Multiplier and removed the 10 outgoing outlets (5 per PowerSquid) as well as the AC plugs. The 5 outgoing outlets came nicely attached together so I cut one from each that used to power the arduino, ioBridge and Wifi bridge.

I connected all the Neutrals (white) together, all the Grounds (green) and then I took the Live (black) and daisy chained to each of the 8 SSRs. Then I individually wired each SSR Live wires to one of the 8 outlets.

I decided to have two power plugs to make the wiring a bit nicer and less bulky. So basically the SSRs on the left are connected to one wall outlet and the SSRs on the right to the other.

Arduino Sketch
You can download the Arduino Sketch from the bottom of this page (xmas_box.pde).
 You will need the following Arduino Libraries:

- AF_Wave and Wave
- String (formerly TextString)

Here is a run down for the pin connections on the Arduino with WAVE shield on top.

Communication
D0(RX) -> ioBridge Serial Board TX
D1(TX )-> ioBridge Serial Board RX

D2-D5 are used by the WAVE shield (they could be changed)
D2 -> LCS
D3 -> CLK
D4 -> DI
D5 -> LAT

xmas-box first 3 channels
D6 -> Channel 1
D7 -> Channel 2
D8 -> Channel 3

FM transmitter ON/OFF
D9 -> 10k resistor -> 2N2222 Base -- Collector and Emitter to FM transmitter switch

WAVE shield

D10 -> LCS

SD card WAVE shield communication (cannot be changed)
D11
D12
D13

Power
Gnd[0] -> Relay daisy chain.
5v pin -> FM transmitter positive
Gnd[1] -> FM transmitter ground
Gnd[2] -> ioBridge Smart Serial Board

Vu Meter
A0 -> R7 1.5K on the WAVE shield to measure output from amplifier. See image.

Analog pins 1-5 are used as digital out for xmas-box channels

A1 = D15 -> Channel 4
A2 = D16 -> Channel 5
A3 = D17 -> Channel 6
A4 = D18 -> Channel 7
A5 = D19 -> Channel 8

Wave shield speaker (mono) to FM transmitter input


ioBridge Configuration
The ioBridge configuration is a breeze! All you have to do is Serial.print the current track number being played to the ioBridge Serial Board. The serial board will hold the track number and have it available to be retrieved by the Data Feed API in JSON format (LastSerialOutput).
I also created a series of widgets with predefined xmas-box commands for a one-click input.

Here is the syntax to communicate with the xmas-box through serial communication.  The semi-colon indicates the end of the command.

Next track
n;
Put on queue
q(1-99);
Put on queue with specific light mode
q(1-99)m(1-8);
Change light mode
xxxm(1-7);
Turn all lights on/off
xxxm8{1/0);
Turn individual channel on/off
xxxm9(1-8)(1/0);

FM Transmitter
I was hoping to find a Belkin TuneCast II since I have found a lot of information online (including this instructable ) but I had to settle with the PPA Digital FM Transmitter and it worked out pretty well! The only modifications I had to do were to desolder the stereo mini plug and connect 2 wires coming from the WAVE shield speaker output and desolder the mini barrel plug to connect power directly from the Arduino.

I'm powering the FM transmitter with the 5v coming out from the Arduino. This would probably not be a good idea if I was powering the Arduino with a 9v battery but since I'm using a wall wart I'm not too concerned.

I am bypassing the ON/OFF switch by connecting a 2N2222 transistor connected to a 10k resistor coming from a digital output from the Arduino. To turn on I just send a fast HIGH/delay/LOW and that's all I need to start the FM transmitter.

I also soldered a wire as an antenna to the ground of the battery power pin.

Web Interface
I decided to leave the job of song queuing to a web application. I am using Oracle Application Express (APEX) for http://xmas-box.com since this is my favorite rapid web application development tool. But this can also be managed by any database oriented web solution (ie  Linux/Apache/MySQL/PHP -  LAMP).

I have 2 main tables:
SONGS - It stores the name and artist of the song
QUEUE - it stores the song requests

The web app uses jQuery to retrieve the ioBridge JSON Data Feeed API to determine the current song being played. Using Javascript I retrieve LastSerialOutput node that holds the number of the current track.

Then another jQuery calls my web application REST service and sends the track number. The REST service returns the song name,artists and name of the person that requested the song.

If the song was not on the queue it means that its just looping through the play list. So in this case the requester will be Santa Claus itself! And it will show Santa's current location by retrieving it from http://www.noradsanta.org/ feed.

The page might have a live view and live sound, but I'm still working on that...


Alternatives
During my research I stumbled upon a few mentionable resources. My requirements became more tight since I wanted a computer-free solution, a stand-alone application and that is why I went with the WAVE shield . Another possible way is to get a cheap mp3 player and build an op amp low filter to detect beats on the music, but then again the WAVE shield is actually pretty inexpensive so it worked out better.

Beat detection
One of the easiest ways to do an Arduino based light/sound show is by using a combination of Proccessing + Minim+ Firmata. All you need is to have serial communication from your pc to your arduino.  These instructables rely on Minim's beat detection and could be adapted for Christmas lights:
LED Dance Room
Music Synchronized LED Pumpkin

Relay board fabrication

You can follow the Arduino Christmas Light Controller Instructable if you prefer to build your own relay board. Note that this will be using mechanical relays instead of SSRs.

Internet communication
Another alternative for the web control part is to have a secondary Arduino with a Ethernet shield or a wi-fi shield (it will be absolutely necessary to have a second Arduino board). But as a side note I really like using the ioBridge module. Their servers manage all incoming/outgoing connections and the Data Feeds and APIs offers great flexibility.

Commercial/Hobby products
diylightanimation.com (Linx)
animatedlighting.com (they got a Christmas In A Box 4 channel for $500!!)
Ligh-O-Rama

Sunday, November 1, 2009

Sunday, September 27, 2009

Webcam + PIR sensor + servos +ioBridge + txt message alerts = awesome security system

So I extended my webcam project to become a security system while I was away for the last couple weeks.


I mounted a webcam with two Futaba S3003 servos (pan + tilt) with the help of a Meccano 5-model set . I also installed 2 PIR sensors to detect movement. Then I mounted all to a tripod.

I created 2 ioBridge messaging actions to send me a TXT message if any of the PIR sensor went to the ON position (note that I only activated this action while away to avoid receiving a huge amount of TXTs) and also a Digital input to servo position action to move the camera to the direction of movement.

I placed the camera on the side of my main hall, so I was able to get at 180 degree view of my house while away.


Luckily it only went off once when I asked my sister to come to my house to grab something for me :) , other than that It worked great! I also used my x10 controllers to turn on/off a few lights inside my house as well as a lamp candle (scentsy) that I was able to to turn on the day I flew back home.

Now I only wonder what will it take to tap  into my actual security system with my ioBridge.

Monday, August 24, 2009

ioBridge First Project: Webcam with PIR sensor.

Since I can recollect using the internet (91/92?) I have been doing the following search: "Devices Connected to the Internet" (remember yahoo directory!), and have always been wondering when was my turn to connect "something" to the tubes.

I was finally able to create my own webcam with a Passive Infrared (PIR) sensor.



A couple weeks ago I stumbled in to ioBridge. The minute I saw it I knew I needed it :) . I have
been interested in home automation for while (and even invested on some x10 devices) but I have been always looking for the missing link; internet connectivity.

So this is pretty basic. I have a webcam mounted on a Futaba S3003 servo. I ordered the servo controller smart board as well from ioBridge so all necessary servo communication is done.
I'm using an Airlink 101 wireless webcam (got it at Frys) , and it is really nice that it has a bottom and top standard tripod compatible screw. So all I had to do is get an extra tripod base adaptor that I mounted directly to my servo.


As soon as I got my ioBridge, I ran to radio shack to see what I could find. Sadly Radio Shack does not have the biggest stock of electronic components (at least the one close to my house). But I did manage to find this: a Pir Sensor Module. The voltage required is 3.3-5v, and it has a digital signal output.

Then on friday hackaday.com published this passive infrared (PIR) tutorial and there I found a link to the following project which inspired me to do the same minus the arduino board (which btw I will be getting one soon). And here is where I found out how much ioBridge rocks! I am able to do basically the same using ioBridge actions. This is truly amazing!

I also implemented an iPhone version using the ioBridge iTurn as an example where I can pan the camara depending on my iPhone orientation. Pretty neat!

Using the ioBridge JavaScipt API I was also able to create buttons to move the camera.

You can also see that I have a light control. That implementation is using x10 Firecracker PC serial interface connected to a linux machine and some x10 linux controlling software (BlueLava + Heyu) which I expect to replace soon with an ioBridge x10 smart board.

Video after the break....