USB controlled SPÖKA night light

2012-03-12 10:28


This is an IKEA SPÖKA light. It is a small night light resembling a little ghost.


Originally powered by an internal rechargable battery, the light is controlled by a single button. When pressing that button it starts cycling through various color combintations. When you press that button again it freezes the current color. That's all it can do. Depending on the model the colors can be a combination of either blue and green or red, orange and blue.

Inspired by another SPÖKA mod I decided to also modify such a light, but instead of wirelessly communicating with the device, I wanted to be able to control it through USB. As the power requirements of the SPÖKA light are very low, it can easily be powered through the USB as well.
I chose the blue/green model of the SPÖKA light. First I disassembled the light, which by the way is not that easily done, because the silicone skin is attached very tightly.

Disassembling the light

Here is a picture showing how I removed the skin. Rather than trying to pull the skin off the SPÖKA's body (well, I actually tried, but it did not work ;), I pushed the lower half of the skin to the inside like you can see on the picture. Afterwards I was able to remove the skin rather easily. I did not use any tools here, to avoid damaging the skin.


This is how the inner body looks like.


Here is another picture showing the inner parts of the light. The light comes with an internal 3.6 V/550 mAh battery constisting of three AAA NiMH batteries.


The internals of the SPÖKA light I am using differs considerably from the one being used in the hack mentioned above (the more round one). The main differences are that the round SPÖKA seems to use single-color LEDs, although in three different colors, instead of only two colors. Also, the round SPÖKA's main circuit is placed on a single PCB, while the one I am using consists of two PCBs for the main circuit.

So my SPÖKA light comes with three PCBs: One very tiny one located in the head of the ghost, containing nothing but the button.

schematic button

The second PCB contains four two-color-LEDs (blue/green) and current limiting resistors.


The LEDs for each color are connected in parallel. The Anodes of all LEDs are connected together. I have drawn a schematic showing the wiring of that PCB.

schematic LEDs

Then there is a third PCB containing an unknown IC, probably some sort of micro controller and a few other components (like resistors and transistors for switching the LEDs and some simple charging circuitry for the battery). I did not bother analyzing that circuit in detail, as the IC on the PCB is completely blank with no marking whatsoever.


I decided to replace that PCB and keep the other two (with the button and the LEDs). As a micro controller I chose an ATtiny25 AVR controller (with 2048 bytes of flash memory and 128 bytes of SRAM). To be able to talk to a computer over USB I chose the great V-USB firmware-only USB implementation.

As I intended to use the light with a computer all the time, I had no need for the internal battery either, so I removed that as well.

The new circuit

Here is the schematic of my new controller circuit. It consists of the ATtiny25 micro controller, one 100 nF capacitor, two diodes (for lowering the 5 V supply voltage), a few resistors and two BC337 transistors for switching the LEDs. It would probably be a good idea to use an additional capacitor in parallel to the supply voltage with ~ 100 µF or so, when using very long USB cables. As the available space is rather limited, I did not include one, though.

schematic new main circuit


The new controller board connected to the LEDs and the button can be seen in the following picture.


Because of the Mini USB connector's different shape and position, I had to enlarge the hole for the connector. I did not modify the silicone skin in any way, though.



The new PCB needs to be of exactly the same size as the old one to fit into its place. You can see the (partly) reassembled SPÖKA light in the following pictures.



The reassembled inner body...


...and the USB cable attached to the night light still without its skin...


..and then with the skin reattached:




Even though I want to use the modded SPÖKA light with a computer, I still wanted to be able to use a simple USB power supply (like one of those USB phone chargers) and still be able to turn it on, which is why I designed the new firmware to allow that.

The new firmware can operate in a few different modes. The default mode allows the light to be turned on even without a computer. With the button one can cycle through three colors (blue, green, turquoise). An algorithm for fading through various color combinations did not fit into the 2K of controller memory, so that mode is not available in stand-alone mode. It is available when connected to a computer, though.

When connected to a computer, one can configure the light in different ways. Each color can be turned on individually (with configurable brightness). Also, the button's behavior can be configured. By default, the button works as described above (cycling through those three colors). Another possible configuration for the button is to only turn the light off when it had been turned on previously. The third option for the button is to do nothing to the lights but instead report a button press through USB to the computer. That way the software on the host side can decide how to react to a button press.

When connecting the device to a Linux computer, the kernel log says something like the following about the device:
generic-usb 0003:16C0:05DF.0002: hiddev0,hidraw1: USB HID 
v1.01 Device [ SPOKA] on usb-0000:00:12.0-2/input0

The Makefile for the firmware can build the firmware (make hex) and flash it onto the controller (make program). To build it the avr-gcc is needed, to flash it avrdude is needed. Also, as the call to avrdude for flashing is specific to the programmer used, the AVRDUDE=.. line in the Makefile needs to match the programmer that is being used.

Host computer software

I have written a little utility for controlling the light with a computer. As I am using Linux on my computers, the software has been designed to work in Linux. It should work on other POSIX-compatible operating systems too. To use it with Windows it probably needs to be modified a little. There is a libusb port for Windows, so that part should probably work somehow, but the whole background process thing is most likely done differently on Windows.

The software consists of two components. A little daemon that does the actual talking with the SPÖKA light and a command line utility that talks to the daemon. That way, one can tell the daemon to e.g. slowly cycle through different colors and then the daemon does its job in the background until one tells it to do something else. With that software it would also be possible to configure the light such that it flashes when an email or instant message arrives, given that the IM/email program supports calling external programs for such an event.

To be able to talk to the USB device, the user running the daemon needs the permissions to do that. When running it as root, it automatically has all the permissions it needs, so there is nothing to be done in that case. When running it with an ordinary user, the neccessary permissions can be granted through an udev rule. Such rules can be created by adding a file to the /etc/udev/rules.d/ directory. So to allow user access to the SPÖKA USB device, I have added a file called "10-spoka.rules" with the following content:

ACTION!="add|change", GOTO="spoka_rules_end"
SUBSYSTEM=="usb_device", GOTO="spoka_rules_real"
SUBSYSTEM=="usb", GOTO="spoka_rules_real"
SUBSYSTEM!="usb", GOTO="spoka_rules_end"
ATTR{idVendor}=="16c0", ATTR{idProduct}=="05df", MODE="664", 
This grants read/write access to the device for all users in the "users" group. After creating that file, udev needs to be restarted to reload the configuration.

When the host software has been compiled with the Makefile inside the "tool" directory, there is an executable file called "spokausb". Executing that file with the -d option starts the daemon in the background:
$ ./spokausb -d
Once the daemon is running one can send commands to it by calling the spokausb executable again, but with other parameters. Calling it without any parameters prints a little help.
$ ./spokausb
spokausb 0.1.0
  ./spokausb [option] [...]
 -d  .................................... start daemon
 --led{lednum}={brightness}  ............ set brightness of LED
 --led{lednum}+={brightness increase}  .. increase brightness of LED
 --led{lednum}-={brightness decrease}  .. decrease brightness of LED
 --button=  ........ configure button mode
 --fade   ............................... slowly cycle through all colors
 --flash  ............................... flash repeatedly
 --freeze  .............................. stop cycling through colors
 --read-button  ......................... read button state
 --read-led{lednum}  .................... reade LED state
 --help/-h  ............................. this help
So to turn on the blue LEDs at full brightness one would run:
$ ./spokausb --led1=255
Or to turn on all LEDs at medium brightness one could execute the following command:
$ ./spokausb --led1=128 --led2=128
This would cause the SPÖKA light to light up in a turquoise color.

To terminate the daemon one can simply kill it.
killall spokausb
This shuts down the daemon cleanly.

Possible modifications

There are a few things that I can think of, which could be done differently.

First, the circuit could be modified to support a third color, so the round SPÖKA light could be used as well. This would require to disable the RESET pin on the ATtiny25 to be able to use it as an ordinary I/O pin. Once that has been done, the controller can no longer be reprogrammed using the normal programming mode. So either one needs to program it before setting the fuses, or a programmer supporting high voltage serial programming is needed.

Another possible modification would be to use hardware PWM to control the LEDs, instead of doing that with a software routine. The advantage of this would be that the PWM could be done without the CPU. That would leave the CPU with basically only handling the USB stuff. This would also mean, that USB transfers would not be able to interrupt the PWM routine. Because the hardware PWM can only be used on specific pins one would have to re-route one of the LEDs, which is kind of difficult to do on that small PCB. Also, as there are only two PWM channels available on the ATtiny25 this would not be possible for the three color SPÖKA light.

As already mentioned abobe, another thing that comes to my mind is the addition of a capacitor with about 100 µF in parallel to the power supply line, to stabilize it a bit. When using a very long USB wire (several meters) this might actually be necessary. Due to the very limited amount of available space, I did not include such a capacitor. I had no problems with unstable supply voltage, though.

Of course one could also use a larger micro controller (as in higher memory capacity) like an ATtiny45 or ATtiny85 (which come with twice/four times the the memory) and add more features to the firmware. I simply liked the idea of using one of the smallest AVR controllers. It is also the cheapest of those three.

Last but not least, one could modify the firmware such that it acts like a real HID device and exposes the button of the SPÖKA light as a one key keyboard. This would certainly require a controller with more memory (e.g. ATtiny45).

There are probably a lot more things one could do differently/better. If you have any ideas, suggestions or questions, you are welcome to leave a comment or write me an e-mail.

spokausb-0.1.0.tar.gz (Firmware and host utility (96 kB, GPLv2)
md5sum: bf50712e1b5160dfd82f7ee50e9909aa


Update: Here is a little video showing the USB SPÖKA light in action. Sorry for the poor quality. What I'm doing in the video is basically just sending a few commands from the computer (running a terminal program) to the USB SPÖKA. Unfortunately the camera automatically adjusts its brightness control (which I can't turn off) when the SPÖKA changes its brightness, so one cannot really see the fading effect.

The video should play fine in at least the Chrome, Firefox and Opera browsers.
Gunnar (web) says:
2012-03-14 13:46:50
Nice work!
I'm just connecting the Spöka with my Arduino. I'll have a closer look at your project.
Rusty (web) says:
2012-04-28 11:03:12
Hi, Really nice hack! How did you get the tight outer skin off? I am finding it impossible and I can't really tell how you managed to fold the skin inside (in fact I'm finding that harder than trying to peel it off the other way). Did you use fingers, a butter knife, something else?
wej (web) says:
2012-04-28 11:38:34
Rusty: Removing the skin was indeed kind of difficult, but I did not use any tools. First I tried to push the plastic body out of the skin, by holding the skin at the bottom edge (where one can see the plastic of the inner part) and then pushing it by pressing on the ghosts head. This moved the inner part a little, but not very far. Then I did what you can see on the second picture. I've tried both, peeling it off and pushing it inside and the former did not work at all for me, while pushing it inside worked eventually without damaging the skin and without hurting myself. It requires quite some force though, but once you've pushed it as far as you can see on that picture, you are almost done. Unfortunately, it is somewhat hard to describe and I did not take a video of the procdure. :/
dogbone (web) says:
2012-05-17 22:47:28

Could someone pls tell me the color code or value of metal foil resistor marked in the picture in the link..

wej (web) says:
2012-05-18 07:27:46
dogbone: Sure, the resistor is colored brown-green-black-gold, which would be 15 ohms / 5 % tolerance.
stas (web) says:
2012-05-21 20:42:59
Hi mate! Cool project you got here. Any idea of the polarity of the original charger connector? Would really appreciate this! Thanks!
wej (web) says:
2012-05-21 22:05:45
stas: Thanks. The original connector has +5V on the inside and ground on the outside. Btw, there also is a small image on the charger showing the polarity of the connector.
stas (web) says:
2012-05-23 22:37:47
I suspected the charger would have that, but I have no charger, only the lamp. Thanks a lot!
kiko (web) says:
2012-07-19 16:08:47
My SPÖKA does not work unplugged.
The batteries does charge (tested it) and I fixed all the solderings.
Anyone figures where can be the problem?
If its plugged to the charger it works...
isharko (web) says:
2012-10-16 00:19:46
kiko, same here. No idea how to fix it. Help would be appreciated, if anyone knows.
isharko (web) says:
2012-10-16 00:21:20
Actually, the way it works for me is, when I unplug the charger, the battery shows 3.5-3.7V steady, but the moment i hit the switch to turn on the LEDs, the voltage drops to 1.5 and the LEDs flash and don't light up.
wej (web) says:
2012-10-17 11:52:53
Those problems sound pretty much as if the battery is dead, as in "has a high internal resistance". If that's the case, the battery's voltage drops considerably as soon as some load is applied. To verify if that is actually the case, you could remove the battery from the LED circuit and connect some other load to it, while measuring its voltage.
Janice (web) says:
2016-04-17 17:46:46
Hi, I wanted to ask for your help with this exact spoka long oval night light. It doesn't change colors anymore. I opened it up and I have a soldering gun but I don't know which is the spot that is for color changing. While opened and messing with the mother boards ill accidentally get the changer to work. I know theirs an area that should probably be touching each other between the boards but have no clue where and I think you have to know. Please if you can send me a picture or a diagram of where I need to add soldering to id really appreciate it. I'm not an electronic but I'm determined. Thank you
wej (web) says:
2016-04-24 08:22:13
Janice: The color changing happens inside of the eight pin chip on the PCB. That chip is a microcontroller of some sort. I haven't bothered figuring out what kind of controller exactly, since I have replaced the whole PCB anyway. It could be a PIC maybe. Unless you want to do a mod like I did, you can't do much about it I am afraid, because even if you could replace the microcontroller chip, you still would have to get the firmware from somewhere and flash it onto the controller.
That said, if you are really determined to fix the thing and you want to do it mostly for the learning aspect, of course you could try to figure out what microcontroller has been used, write your own firmware for it and replace the chip.
kougaz (web) says:
2017-12-17 20:36:19
hi, can anyone help me with this spoka?
when i turned on the blue light is fade... i measured the voltage and i found the greens get 4.5v and start dropping to light the blue ones, but when i measured the voltage of the blue ones they only get 2v max then they start dropping... so what would be the problem?
thank you
mrzoom (web) says:
2018-08-02 14:28:01
If SPÖKA does not work unplugged (or flash only one second), work plugged. The batteries does charge (tested) and solderings are ok :
check deep inside the big power jack.
you may find a little broken piece of the smooth white plastic from the ghost, which alter correct functionality. Remove it.
Geoffrey AGUILERA (web) says:
2020-09-13 19:57:38
Thanks ! : )
Oskar (web) says:
2020-10-20 21:29:54
Very nice writeup! I used it as inspiration to do something similar. I removed all internals except the led PCB and put a LOLIN D1 mini inside. I used the 3.3V pin and two digital outputs for the leds and power it using 1A usb power source. Now it checks NTP time and changes color so my kid knows if it's too early to get out of bed :) Thanks!

Leave a comment