Tag Archives: Arduino

Wake-up Light Part 3: Hardware

This is the third part (part 1, part 2) of my write-up on building a Raspberry Pi-based wake-up light. At this point, the Pi was capable of switching 433 MHz remote controlled outlets and can be scheduled to do this at certain times.

I had a few ideas on how to roll my own light for the project. In the end, I went for 10 m of RGB-LED strip on Ebay and four pieces of quarter round rod from the department store. I think these pictures speak for themselves:

2014-02-03 21.00.58 2014-02-08 21.51.332014-02-03 20.14.41 2014-02-08 19.51.592014-02-03 20.14.32 2014-02-03 20.36.15 2014-02-03 20.14.562014-02-08 22.42.13

To get off the ground quickly, I whipped out an Arduino and soldered three MOSFET transistors to a protoboard. My initial idea was to hook it up to the Pi via I2C, but as I had the 433 MHz receiver left over from the kit I bought, and also already being familiar with the library as I used it to find what codes to use for my outlets, I figured I might as well make it wireless. This also has the added bonus of making it possible to control the light directly with my existing remote.

2014-02-08 21.46.16

To test things out, I hastily modified the rc-switch library example. The code is available over on my Github account, although for the time being it really is not very pretty and does contain bugs! I made the A-channel on my remote turn the light on and off and used B to set the brightness. I also wrote a small state machine to dim the light from blue through red and orange and up to white at full brightness over the course of 15 minutes. This would be my wake-up sequence. The “E” channel does not have any buttons on my remote (only A-D). It is, however, no problem to send on and off commands on it using the commands on the Raspberry Pi. Making the Arduino listen to channel “E” of my outlet remote system meant I did not have to waste one of the four channels on the actual remote. To the Pi it was all the same, I just changed what channel it should power on in the crontab. Here is an attempt to catch a sped-up version of the light sequence on camera. You get the idea.

2014-03-04 21.02.06

Sweet, at this point the project was really starting to get somewhere! The wake-up sequence is good enough for now, and the extra feature of being able to toggle the light on and off along with my other lamps in the evening is very convenient. With the right setup, ssh, nano and cron can be quite ok for setting the alarm. However, I was hoping to do something more portable and… modern, like an MQTT message server perhaps?

Next time: Software!

Wake-up Light Part 1: Flipping switches

2014-02-08 22.45.39 2014-02-08 22.45.20 2014-02-08 22.45.31

I’ve had the idea to build my own wake-up light for quite some time. This winter i finally got around to it. This is the first part of my write-up of the project.

In simple terms, the point of a wake-up light is to gently wake you up by slowly turning up the light before the alarm goes off in the morning. There are several commercial products available that do this already, all of which I think are either ugly, too small or simply not practical enough for my use case. Some of the things I wanted that are commonly not available in these products are:

  • Big, powerful light. Usually, products are night stand-size alarm clocks with a few measly watts of power.
  • RGB controllable light. My living room is also my bedroom. If I’m going to make the wake-up light big and powerful, I also want to be able to set it to a cosy warm evening-setting. Plus, this would make it able to do a more sunrise-like color fade in the morning.
  • Powerful scheduling options. I’m a student and don’t get up at regular hours every day. I want the wake-up time to be easily settable, preferably synchronized to my alarm or even my schedule.

Flipping some switches

I figured I could use my Raspberry Pi as the central point for the system. It’s hanging off the back off my TV, running Raspbmc and is on 24/7 anyway, so a simple start would be to add a cronjob to simply turn on some lights in the morning. I already had 433 MHz light switches connected to three ambient lights in my room, so I started out with by hooking up a transmitter to the Pi.

2013-10-12 22.51.17

Having someone in Shenzen send me a transmitter/receiver pair for 433 MHz on Ebay set me back about the same amount sending a normal letter home to my mother would. Mine was titled “RF Wireless Transmitter & Receiver Kit Module 433Mhz for Arduino/ARM/MCU WL”.


Obviously, someone on the Internetz already wrote the code to talk to my outlets using Arduino. And someone else also ported it to Raspberry Pi. Sweet! The project I’m using is called rcswitch-pi. According to the readme, it depends on the (seemingly useful) wiringpi project, so first we need to get that (assuming you have git installed):

$ cd
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build

Wiringpi is used for the gpio calls inside rc-switch and is sort of replacing the Arduino’s digitalWrite() and the like. Now let’s install rcswitch-pi:

$ cd
$ git clone https://github.com/r10r/rcswitch-pi.git
$ cd rcswitch-pi
$ make

The program is hardcoded to have the transmitter connected to Wiringpi pin 0, which corresponds to pin 11 of the GPIO header on the Pi. If you want, you can change this by editing send.cpp and running the make command again.

Hooking up the receiver to my Arduino and using the original rc-switch library, I figured out what group and channel corresponded to the buttons on my remote.

2013-10-12 22.50.14

I could now control the lights from the Pi using these commands:

$ cd ~/rcswitch-pi
$ sudo ./send 11111 3 1 #Press "C on"
$ sudo ./send 11111 3 0 #Press "C off"
$ sudo ./send 11111 4 1 #Press "D on"
$ sudo ./send 11111 4 0 #Press "D off"

A small explaination to all these numbers: my outlets have “group switches” allowing different remotes to control  different sets of outlets. I have mine set to 11111. The buttons on the remote are labeled A-D. I have some lights hooked up to C (3) and D (4). All this I learned by loading the example sketch from the rc-switch library onto my Arduino and observing the serial output as I pushed some buttons on the remote.

Once I knew the send command was working, I linked it into /usr/bin/. This makes it possible to run the command without having to cd into the folder every time, which will be convenient for scheduling later.

$ sudo ln -s ~/rcswitch-pi/send /usr/bin/send
$ cd
$ sudo send 11111 3 1
$ sudo send 11111 3 0

Next time: Scheduling!

Projekt: Arduino på hjul



Det kom ett paket här om dagen, med servon till micromouse-roboten. Planen är att använda två av dem som motorer för själva framdrivningen. Eftersom servon är som motorer med en inbyggd “växellåda” och färdig infästning och dessutom är rätt så billiga är de bra att ha som framdrivning på sådana här enklare småprojekt. Det enda problemet är att vanliga servon bara kan röra sig 180°. Det brukar dock ofta vara enkelt att råda bot på; det finns massor av guider på hur man modifierar olika servomodeller för kontinuerlig gång som det kallas. Mina Mystery 9G var mycket enkla att modifiera, speciellt då det finns en bra guide att följa. Det gick inte bara bra hela tiden, jag råkade slita lite för hårt i ett av servona så att några sladdar lossnade och fick lödas tillbaka – var försiktig!



hjul med ok


servo med hjul


arduino på hjul


När det var klart skruvade jag fast ett par av de medföljande oken i ett par hjul som jag hade liggande och sedan satte jag medelst kattstrypare fast servona lite provisoriskt i en bit plåt och tejpade dit Arduinon ovanpå. Resultatet är inte jättebra, men precis som IR-sensorn jag skrev om här om dagen är det en bra utgångspunkt för att se vilka svårigheter man kan vänta sig framöver. En sådan svårighet var till exempel att limmet jag använde för att fixera potentiometrarna inne i servona var för mjukt, vilket gjorde att mittenläget där servona står stilla flyttar sig lite hit och dit. Du kan se hur den drar åt höger precis i början i klippet här nedan just på grund av det problemet: