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

Using CA and CC RGB LED by Current Sourcing and Sinking!
Easy
  • 315
  • 21

Protip

RGB LEDs are of two types, common cathode and common anode which behave differently with same Arduino code; how to resolve this.

Physical Computing - Scratch for Arduino
Easy
  • 18
  • 1

Full instructions

Scratch is a great tool to teach beginners how to code, program interactive stories, and do Physical Computing!

Arduino Amiga Floppy Disk Reader
Easy
  • 1,302
  • 3

Work in progress

An Arduino powered floppy disk controller and reader for making disk images from old AmigaDOS floppy disks.

Simple Dark Sensor
Easy
  • 32
  • 1

A simple dark sensor with or without Arduino.

Arduino Controlled USB Trackpad
Easy
  • 2,342
  • 4

Full instructions

I really want to make a Raspberry Pi laptop but just can't find the right size trackpad so in this project we will be salvaging an old one.

Arduino - Web-Based Keypad
Easy
  • 3,694
  • 33

Full instructions

Remotely controlling Arduino by using web-based keypad.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login