Things used in this project

Hardware components:
Ardgen 101
Arduino 101 & Genuino 101
×1
12002 04
Breadboard (generic)
×1
09264 1
RGB Diffused Common Cathode
×3
11026 02
Jumper wires (generic)
×1
Software apps and online services:
Ide web
Arduino IDE
MIT app inventor

Schematics

Fritzing Squematic
rgb_ble_lamp_hVrjjjL8Gc.fzz

Code

Arduino codeArduino
Arduino code to make a BLE control a RGB Led
/*
  
  This code was modify by Gustavo Reynaga @gsreynaga and base on the job by:
  Andrew McKinney (mckinney@mit.edu)  
  A Simple example that alows you to turn on/off a light connected to a digital relay (switch)  using a Arduino 101 microcontroller.

  

*/
#include <CurieBLE.h>

BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService RGBService("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedIntCharacteristic switchCharacteristicRed("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic switchCharacteristicBlue("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic switchCharacteristicGreen("19B10013-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);


const int RedPin = 3; // pin to use for the Light
const int BluePin = 5; // pin to use for the Light
const int GreenPin = 6; // pin to use for the Light


void setup() {
  Serial.begin(115200);

  // set Color pin to output mode
  
  pinMode(RedPin, OUTPUT);
  pinMode(BluePin, OUTPUT);
  pinMode(GreenPin, OUTPUT);
  //This configuration its for Cathode Led if you use a Anode, need to make a change to LOW
  digitalWrite(3,HIGH);
  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("RGB Service");
  blePeripheral.setAdvertisedServiceUuid(RGBService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(RGBService);
  //blePeripheral.addAttribute(switchCharacteristic);
  blePeripheral.addAttribute(switchCharacteristicRed);
  blePeripheral.addAttribute(switchCharacteristicBlue);
  blePeripheral.addAttribute(switchCharacteristicGreen);

  // set the initial value for the characeristic:
  //switchCharacteristic.setValue(0);
  //use 0 (Zero) invalue for ANODE Led
  switchCharacteristicRed.setValue(255); 
  switchCharacteristicBlue.setValue(255);
  switchCharacteristicGreen.setValue(255);

  // begin advertising BLE Light service:
  blePeripheral.begin();

  Serial.println("BLE RGB service.");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the color:
      if (switchCharacteristicRed.written()) {
          Serial.println(switchCharacteristicRed.value());
          int light = switchCharacteristicRed.value();
          analogWrite(RedPin,light);
          Serial.println(light);
      }
      else
      if (switchCharacteristicBlue.written()) {
          Serial.println(switchCharacteristicBlue.value());
          int light = switchCharacteristicBlue.value();
          analogWrite(BluePin,light);
          Serial.println(light);
      }
      else
      if (switchCharacteristicGreen.written()) {
          Serial.println(switchCharacteristicGreen.value());
          int light = switchCharacteristicGreen.value();
          analogWrite(GreenPin,light);
          Serial.println(light);
      }
      
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}
App Inventor 2 project CodeArduino
AiA Project file for App Inventor
No preview (download only).
Arduino INOArduino
/*
  
  This code was modify by Gustavo Reynaga @gsreynaga and base on the job by:
  Andrew McKinney (mckinney@mit.edu)  
  A Simple example that alows you to turn on/off a light connected to a digital relay (switch)  using a Arduino 101 microcontroller.

  

*/
#include <CurieBLE.h>

BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService RGBService("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedIntCharacteristic switchCharacteristicRed("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic switchCharacteristicBlue("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic switchCharacteristicGreen("19B10013-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);


const int RedPin = 3; // pin to use for the Light
const int BluePin = 5; // pin to use for the Light
const int GreenPin = 6; // pin to use for the Light


void setup() {
  Serial.begin(115200);

  // set Color pin to output mode
  
  pinMode(RedPin, OUTPUT);
  pinMode(BluePin, OUTPUT);
  pinMode(GreenPin, OUTPUT);
  //The configuration maybe to change its the led are Anode or Cathode
  digitalWrite(3,HIGH);
  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("RGB Service");
  blePeripheral.setAdvertisedServiceUuid(RGBService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(RGBService);
  //blePeripheral.addAttribute(switchCharacteristic);
  blePeripheral.addAttribute(switchCharacteristicRed);
  blePeripheral.addAttribute(switchCharacteristicBlue);
  blePeripheral.addAttribute(switchCharacteristicGreen);

  // set the initial value for the characeristic:
  //switchCharacteristic.setValue(0);
   //The configuration maybe to change its the led are Anode or Cathode
  switchCharacteristicRed.setValue(255); 
  switchCharacteristicBlue.setValue(255);
  switchCharacteristicGreen.setValue(255);

  // begin advertising BLE Light service:
  blePeripheral.begin();

  Serial.println("BLE RGB service.");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the color:
      if (switchCharacteristicRed.written()) {
          Serial.println(switchCharacteristicRed.value());
          int light = switchCharacteristicRed.value();
          analogWrite(RedPin,light);
          Serial.println(light);
      }
      else
      if (switchCharacteristicBlue.written()) {
          Serial.println(switchCharacteristicBlue.value());
          int light = switchCharacteristicBlue.value();
          analogWrite(BluePin,light);
          Serial.println(light);
      }
      else
      if (switchCharacteristicGreen.written()) {
          Serial.println(switchCharacteristicGreen.value());
          int light = switchCharacteristicGreen.value();
          analogWrite(GreenPin,light);
          Serial.println(light);
      }
      
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

Credits

Gus 002
Gustavo Reynaga

Iam a teacher

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Oled Display with Arduino 101
Easy
  • 65
  • 2

Full instructions

After many failed attempts, find the way to connect my 128X64 screen with my Arduino 101, and make a mini tutorial for all users to use.

Graphical Programming Drawing Robot On The Wall
Easy
  • 1,051
  • 9

Full instructions

In this low-cost project, you can learn fun stuff like laser cutting, coding, mechanics, trigonometry. No Arduino codes required!

Laser Stuff
Easy
  • 625
  • 3

A laser module that makes light patterns.

Making a Wooden LED Clock
Easy
  • 762
  • 5

Full instructions

I built a simple wood LED clock, using modern electronics and traditional wood and metal working techniques.

Handheld Infinity Kaleidoscope Group Kit
Easy
  • 3,002
  • 32

Full instructions

Use the orientation sensor in your Arduino 101 to control a cool Petri dish infinity-mirror illusion. This project is great for groups.

LEDog Collar
Easy
  • 1,224
  • 10

Full instructions

The LEDog collar lights up when it gets dark, helping you locate your dog from far away.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback