Bluetooth LE Integration with Digispark

Earlier, I was able to control RGB LED Strip via an IR remote built with Digispark (ATTiny85). Taking a step further, I integrated Bluetooth with Digispark so I can send control commands from a remote application!

I have already decoded RGB LED Strip remote codes and learned to program bluetooth LE, now taking another step forward; I integrated bluetooth with Digispark so I can send commands over Bluetooth to Digispark who can then send commands via IR to the RGB LED strip.

One of the reasons to take this direction is that Digispark (ATTiny85) has very less memory, so I cannot save a set of commands on it, thus it made sense to send commands via BT. From previous experiments, I learned not to ‘solder’ things to P4 of Digispark since it creates problem with USB programming (USB-), I instead used pins P2 and P3 (USB+) for serial communication with Bluetooth (CC-41A, HM-10 clone) and P1 for IR data.

This whole setup can run on 5v output from Digispark board.

This slideshow requires JavaScript.

IR Edge Device (Digispark)

#include <SoftSerial.h>
#include <IRremote.h>
#include <IRremoteInt.h>

SoftSerial btDeskLight(2, 3); //Rx/Tx
char cmd[32] = {0};

IRsend irsend;

// accept hex in ascii without '0x' and converts to int
int atohex(char *s)
  int val = 0;
  while((NULL != s) && ('\0' != *s)){
    if (*s >= '0' && *s <= '9') {
      val *= 16; val += *s - '0';      
    } else if (*s >= 'a' && *s <= 'f') {
      val *= 16; val += (*s - 'a') + 10;
    } else if (*s >= 'A' && *s <= 'F') {
      val *= 16; val += (*s - 'A') + 10;
    } else {
      val = 0; break;
  return val;

void setup() {
  btDeskLight.write("AT+Role0\r\n");  //Slave
  btDeskLight.write("AT+TYPE1");      //Simple Pairing

void loop() {
  static int iter = 0;

  if (btDeskLight.available())
    cmd[iter] =;

    //if CRLF (CC41A)
    if((cmd[iter] == 10) && (cmd[iter-1]==13)){
      cmd[iter-1] = '\0'; iter = 0;
      irsend.sendNEC(atohex(cmd), 32);
      //executed command back to controller for confirmation
      btDeskLight.write(cmd); btDeskLight.write("\n");
    } else {
      iter++; iter %= 32;

I can connect from my Controller program to this device and send HEX commands that I learned earlier.




Posted in IoT.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s