Achindra Bhatnagar
Published © MIT

Bluetooth LE Integration with Digispark

Programmatically control RGB LED strip from remote built with Digispark.

IntermediateFull instructions provided10 hours5,913
Bluetooth LE Integration with Digispark

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Fritzing Fie

Schematic

Schematic of Circuit

Code

DeskLight IR Endpoint

Arduino
Receive commands over Bluetooth and Pass it to IR Transmitter
#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;
    }
    s++;
  }
  return val;
}

void setup() {
  btDeskLight.begin(9600);
  btDeskLight.write("AT+DEFAULT\r\n");
  btDeskLight.write("AT+RESET\r\n");
  delay(1000);
  btDeskLight.write("AT+NAME=DeskLight\r\n");
  btDeskLight.write("AT+Role0\r\n");  //Slave
  btDeskLight.write("AT+TYPE1");      //Simple Pairing
}

void loop() {
  static int iter = 0;

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

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

Credits

Achindra Bhatnagar

Achindra Bhatnagar

20 projects • 161 followers
Windows Kernel Hacker, IoT Hobbyist, Enthusiast, Developer and Dreamer

Comments