Harsh Dethe
Published © CC BY-NC-SA

Control Your Projects with Bluetooth Low Energy

Learn how to program and use Arduino over Bluetooth using BLE.

BeginnerProtip1 hour449
Control Your Projects with Bluetooth Low Energy

Things used in this project

Hardware components

Arduino
×1
BLE
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1

Software apps and online services

Arduino IDE
Arduino IDE
Bluetooth APK

Story

Read more

Code

BLE_LED.ino

Arduino
No preview (download only).

Code snippet #1

Plain text
int led1 = 8;
int led2 = 9;

int data;

int flag1 = 0;
int flag2 = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2,OUTPUT);
}

void loop()
{
  while(Serial.available())
  {
    data == Serial.read();
    if(data == '1')
    {
      if(flag1 == 0)
      {
        digitalWrite(led1,HIGH);
        Serial.println("LED 1 is on");
        flag1 = 1;
      }
      else if(flag1 == 1)
      {
        digitalWrite(led1,LOW);
        Serial.println("LED 1 is off");
        flag1 = 0;
       }
    }
    if (data == '2')
    {
     if(flag2 == 0)
      {
        digitalWrite(led2,HIGH);
        Serial.println("LED 2 is on");
        flag2 = 1;
       }
       else if(flag2 == 1)
       {
         digitalWrite(led2, LOW);
         Serial.println("LED 2 is off");
         flag2 = 0;
        }
      }
    }
 }

Credits

Harsh Dethe

Harsh Dethe

27 projects • 36 followers
Computer science student, Electronics hobbyist, AI Enthusiast. I like to play with technology.

Comments