Control 4 LEDs

4 LEDs Arduino Arduino UNO BlueSMiRF Bluetooth LED control RFCOMM RoboRemo buttons

Control 4 LEDs with RoboRemo app


arduino-bluetooth-4-leds.jpg

This page explains how to remote control 4 LEDs via Bluetooth using Arduino and Android phone with RoboRemo app.

Materials needed:
- Arduino UNO (or similar) + USB cable for it
- BlueSMiRF module
- 4 LEDs
- 4 resistors of 1k
- wires
- Android phone with RoboRemo app installed

Introduction
I used 4 LEDs for demo. Actually I'm controlling the output state of 4 digital I/O pins of the Arduino. On those pins you can have 4 relays or some other devices. Also with little code modification, you can extend this project to control more than 4 devices.

Steps:
1.
Upload the code to your Arduino:

// Control 4 LEDs via Bluetooth
// using RoboRemo app
// www.roboremo.app

// Hardware setup:
// BT module   Arduino
// GND ------- GND
// VCC ------- 5V
// TX-O ------ pin2
// RX-I ------ pin3

// LEDs are connected on pins 13, 12, 11, 10

#include <SoftwareSerial.h>  

int bluetoothTx = 2; // TX-O pin of BT module to Arduino pin2
int bluetoothRx = 3; // RX-I pin of B module to Arduino pin3

// also connect VCC pin from BT module to Arduino 5V pin
// and GND pin from BT module to Arduino GND pin.

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;

char cmd[100];
int cmdIndex;

void exeCmd() {
  
  if(strcmp(cmd, "led1 0")==0) digitalWrite(led1, LOW);
  if(strcmp(cmd, "led1 1")==0) digitalWrite(led1, HIGH);
  
  if(strcmp(cmd, "led2 0")==0) digitalWrite(led2, LOW);
  if(strcmp(cmd, "led2 1")==0) digitalWrite(led2, HIGH);
  
  if(strcmp(cmd, "led3 0")==0) digitalWrite(led3, LOW);
  if(strcmp(cmd, "led3 1")==0) digitalWrite(led3, HIGH);
  
  if(strcmp(cmd, "led4 0")==0) digitalWrite(led4, LOW);
  if(strcmp(cmd, "led4 1")==0) digitalWrite(led4, HIGH);
}

void setup() {
  
  delay(500); // wait for bluetooth module to start

  bluetooth.begin(115200); // Bluetooth default baud is 115200
  
  bluetooth.print("$");
  bluetooth.print("$");
  bluetooth.print("$"); // enter cmd mode
  delay(250);  
  bluetooth.println("U,9600,N"); // change baud to 9600
  
  bluetooth.begin(9600);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  
  cmdIndex = 0;
}

void loop() {
  
  if(bluetooth.available()) {
    
    char c = (char)bluetooth.read();
    
    if(c=='\n') {
      cmd[cmdIndex] = 0;
      exeCmd();  // execute the command
      cmdIndex = 0; // reset the cmdIndex
    } else {      
      cmd[cmdIndex] = c;
      if(cmdIndex<99) cmdIndex++;
    }
  }
}



2.
Build the circuit according to this schematic:
arduino-bluetooth-4-leds-schematic.jpg

3.
Connect your Arduino to USB or to a DC power supply.

4.
Configure the RoboRemo interface and enjoy :)



Share Post