Jan 05

How to Build a BlinkM Clone

The original BlinkM was the first in a series of I2C controlled RGB LEDs from ThingM. It’s easy to integrate into projects and control with anything that supports I2C. At its base level it is an ATtiny45 and a Piranha RGB LED. For anyone who wants a simple, elegantly packaged component I would highly recommend that you buy one of these. I am more of a do it yourselfer so I decided to build my own out of parts I had laying around.


Here are materials I used in my project:

  • ATtiny chip (I’ll be using the ATtiny85 but an ATtiny45 will work too)
  • RGB LED with a Common Cathode
  • 3 resistors
  • Jumper cables

This project is very tolerant to variation and you can really do it however you see fit. If you don’t have an RGB LED and want to use individual LEDs that will work. If you have a common anode LED instead of a common cathode LED you will need to use a different firmware package but it’ll work as well. The point is to have fun and learn.

Firmware upload

The firmware for the BlinkM is currently closed source. The reason for this is that the patent for controlling RGB LEDs over I2C is owned by Phillips/NXP. ThingM has licensed these patents to produce their line of BlinkM products. You’ll notice that the license for the BlinkM firmware states that it is for personal use only, not for internal business purposes or for commercial gain. Keep this in mind if you would like to produce a product using this technology.

Because this is closed source it led to the development of an open source alternative: CyzRgb. This firmware is fairly similar to the BlinkM firmware with some additions (like a logarithmic curve for more accurate colors) and some subtractions (it only has 1 script as opposed to the 18 BlinkM has). Some people have noted it’s buggier but if you want to make something that is physically different from the BlinkM (like using a common Anode LED) you will need to use it.

ThingM offers a simple way to upload the firmware through which is called the ReflashBlinkM. This program can be used with the ArduinoISP and can be used to load raw ATtiny chips with their firmware. To do this you’ll need to setup the Arduino ISP wiring as described in the Run Arduino Code on an ATtiny article. Once it’s all connected then start the ReflashBlinkM program:

  1. Select the BlinkM firmware to use (if you are using CyzRgb, select custom and pick the .HEX file from their binary zip file)
  2. Click ArduinoISP on Arduino
  3. Select the port your Arduino is currently on
  4. Click Reflash

ReflashBlinkM using ArduinoISP

It will show the progress in the text at the bottom. When it says “Reflashing Done!” you now are ready to use your ATTiny as a BlinkM.

NOTE: This worked for me when using my UNO but not with my Leonardo.


Now that you have an ATtiny programed with the BlinkM (or CyzRgb) firmware it’s time to build the rest of the circuit around it. It’s important to make sure the correct colors are attached to each pin. This circuit can run on 5v or 3.3v.

ATTiny blinkm clone wiring


Now that it’s all hooked up it’s time to test it out. When you first power up a newly flashed BlinkM it will run a default script which flashes through white, red, green, blue and off then starts again.

ThingM offers a package of example code which includes a handful of sketches for controlling it with Arduino. I found it easier to just extract the whole zip file to my Arduino Sketch folder. The all-in-one sketch for controlling everything the BlinkM does is BlinkMTester. With it you can use the serial monitor in ArduinoIDE to view a menu of options. If you are using ArduinoIDE 1.0.2 this will not work, it functions properly on version 1.0.3. If you are using a Leonardo you need to send “?” to get the menu to show up.

BlinkMTester Arduino Sketch Menu

Next Steps

This is an easy component to work with on its own or to integrate into existing products. I created mine as an exploration of the product but I foresee it having functionality in future projects where a diagnostic light is needed. In addition, since it works over I2C it’s compatible with a variety of development boards including the Raspberry Pi.

May 22

Relay Control Over I2C

Relays are pretty fun to work with. They take all of the DIY electronics stuff and bring it to the “real world” where high voltages and amps live. Relays are all around us and many people don’t even know it. Next time you turn on your TV, oven, or coffee maker and it makes a click, that’s the sound of a relay.

In a previous article I wrote about programming an ATtiny to run Arduino code. There is also a library that allows you to make ATtiny chips I2C slave devices that can be addressed by an Arduino. With this combination you can control up to 3 relays per 8 pin ATtiny. It’s actually possible to have 4 relays per ATtiny85, however, it requires burning the bootloader to disable the reset pin which also prevents you from uploading code.


  • ArduinoISP setup from previous article
  • ATtiny85 (or any compatible ATtiny chip)
  • 3 relays (with a switching voltage of 5V)
  • 3 LEDs with resistors
  • 2 pull up resistors (4.7k Ohm)
  • Jumper wires

Program the ATtiny85

In this project the ATtiny is acting as the slave device. It simply waits for commands to be sent. When it receives a 1, 2 or 3 it switches the corresponding relay. If the relay is currently off it switches it on, if it is currently on, it switches it off.
The code that needs to be uploaded requires the I2C library for the ATtiny chips.

  1. Download the code here: http://arduino.cc/playground/Code/USIi2c
  2. Create a “libraries” folder inside the Arduino Sketch folder
  3. Extract the zip file to the libraries folder you just created.
  4. Open Arduino program and paste the code below
  5. Select the ATtiny as the board
  6. Select Arduino ISP as the programmer
  7. Upload
// ATTiny based I2C relay control
// ForkRobotics 2012

#include "TinyWireS.h"                  // wrapper class for I2C slave routines

#define I2C_SLAVE_ADDR  0x26            // i2c slave address
#define Relay1_PIN  1
#define Relay2_PIN  4
#define Relay3_PIN  3

void setup(){
  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode

void loop(){
  byte byteRcvd = 0;
  if (TinyWireS.available()){           // got I2C input!
    byteRcvd = TinyWireS.receive();     // get the byte from master
      switch (byteRcvd) {
        case 0x01:
        case 0x02:
        case 0x03:


void Switch(int relay){
    if (digitalRead(relay) == HIGH){ digitalWrite(relay,LOW);}
    else {digitalWrite(relay,HIGH);}

Program the Arduino

The Arduino in this equation is doing the sending of commands. The Arduino can be configured to send these commands in response to any input but for the purposes of this experiment we are using the serial console. Here is the code for the Arduino:

// Control menu for I2C relay control
// 2012 ForkRobotics

#include <Wire.h>
int selection=0;
int ATtinyAddress=0x26;

void setup(){
void loop(){
  if (Serial.available() > 0){
    selection = Serial.read()-48;

void PrintMenu(){
  Serial.println("--- Relay Menu ---");
  Serial.println("1: Switch Relay 1");
  Serial.println("2: Switch Relay 2");
  Serial.println("3: Switch Relay 3");

void RelaySwitch(byte device,byte data) {


In this example the LEDs are used as an example of a completed circuit but it could be anything that meets the capacity of the relay. Here is the wiring for the example.

Update (3/27/2013) – Here is the Fritzing File used to create this: ATtiny85 I2C Relay
I2C Relay wiringHere is what my board looks like:

I2C Relay Module
Here is the video of it working:

Next Steps

This is a simple demo of the power of controlling relays over I2C. At this point the ATtiny relay module is only capable of switching the relays, however, with a more complex function on both sides it is possible to send specific commands to power a device off, on or blink for a period of time.

Apr 16

Run Arduino Code on an ATtiny

I’ve been in this situation many times: I just finished an Arduino project, I’m happy with it and would love to save it, but I only have 2 Arduino boards.  Do I sacrifice one to keep this project intact or pull everything off the breadboard and move on? For all the Arduino enthusiasts that can relate to this, thankfully that’s not the only 2 choices.

In my last post I mentioned the Arduino-Tiny project that allows you to use ATtiny chips as an alternative to a full Arduino in projects. For smaller projects that only need a couple pins, this is a great solution. It’s pretty simple to do and in most cases you probably have everything you need to do it. To upload the Arduino code to an ATtiny you can use a dedicated hardware programmer or you can use an Arduino as an in-system programmer (ISP). Here is how the whole process works:

Components you’ll need:

  • ATtiny chip (in this example I’m using an ATtiny85 but many others are supported)
  • Arduino (Uno or Duemilanove)
  • Breadboard
  • Jumper wires
  • 10 uF Capacitor (only if using an Arduino Uno)
  • 1 LED with resistor
  • 3 LEDs of different colors with resistor (Optional)

Step 1

UPDATE 5/28/2012: There was a bug in version 1.0 of the Arduino software that broke the ArduinoISP sketch. This bug has been fixed in version 1.0.1 of the Arduino software. Please upgrade before performing this step.

First we need to upload the ArduinoISP sketch so we can use the Arduino to program the ATtiny.

  1. Open up the Arduino software
  2. click File>Examples>ArduinoISP
  3. upload the sketch.

Step 2

Next we have to setup the wiring to allow the Arduino to program the ATtiny.

Here is how the connections need to be made:

ArduinoISP Wiring Diagram

As stated above the LEDs are optional but can help if you run into issues. Here is what they mean:

Pin 9: Heartbeat – shows the programmer is running

Pin 8: Error – Lights up if something goes wrong

Pin 7: Programming – In communication with the slave

You are going to need to setup this wiring every time you want to upload code to an ATtiny chip so I would recommend setting up a breadboard dedicated for this purpose. I had a proto-shield lying around so I decided to use that. Here is a picture of my setup:

ArdunioISP wiring on Protoboard

Step 3

This guide assumes you have Arduino IDE version 1.0, to install support for programming ATtiny chips you need to:

  1. Download the latest Arduino Tiny code: http://code.google.com/p/arduino-tiny/downloads/list
  2. Create a “hardware” folder inside the Arduino Sketch folder
  3. Extract the zip file to the hardware folder you just created.
  4. Open Arduino and check the Tools>Board submenu. You should have ATtiny chips as optionsATtiny Chips in Arduino Boards Menu

Step 4

Now you are ready to upload a test program to your ATtiny:

Here is the pinout for the ATtiny85:ATtiny85 Pinout

For a more complete reference for the pinouts of various ATtiny chips refer to: http://www.akafugu.jp/posts/resources/reference-sheet/

A good test here is to upload the Blink sketch.

  1. First hook up an LED to the D4 pin on the ATtiny
  2. Open File>Examples>Basics>Blink
  3. Change the sketch from using pin 13 to use pin 4
  4. Go to Tools>Board and select the ATtiny chip you are programming
  5. Go to Tools>Programmer and select “Arduino as ISP”
  6. Then click the Upload button
  7. Your LED should start blinking now

This is just a basic example but as you can see you have 6 usable pins on this little chip. If you want to expand the functionality of this there is also an I2C library that works on ATtiny chips and acts as a sender or receiver.