0% found this document useful (0 votes)
13 views2 pages

Program LED Bluetooth

This document contains an Arduino sketch for controlling two LEDs via Bluetooth using the BluetoothSerial library. It initializes Bluetooth communication, sets up GPIO pins for the LEDs, and listens for incoming messages to turn the LEDs on or off based on specific commands. The code also handles Bluetooth configuration checks to ensure Bluetooth is enabled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Program LED Bluetooth

This document contains an Arduino sketch for controlling two LEDs via Bluetooth using the BluetoothSerial library. It initializes Bluetooth communication, sets up GPIO pins for the LEDs, and listens for incoming messages to turn the LEDs on or off based on specific commands. The code also handles Bluetooth configuration checks to ensure Bluetooth is enabled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include "BluetoothSerial.

h"

// Check if Bluetooth configs are enabled

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

// Bluetooth Serial object

BluetoothSerial SerialBT;

// GPIO where LED is connected to

const int ledPin1 = 25;

const int ledPin2 = 32;

// Handle received and sent messages

String message = "";

char incomingChar;

void setup() {

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

Serial.begin(115200);

// Bluetooth device name

SerialBT.begin("bimoalifwijaya");

Serial.println("The device started, now you can pair it with bluetooth!");

void loop() {

// Read received messages (LED control command)

if (SerialBT.available()){

char incomingChar = SerialBT.read();


if (incomingChar != '\n'){

message += String(incomingChar);

else{

message = "";

Serial.write(incomingChar);

// Check received message and control output accordingly

if (message =="on"){

digitalWrite(ledPin1, HIGH);

if (message =="onn"){

digitalWrite(ledPin2, HIGH);

else if (message =="off"){

digitalWrite(ledPin1, LOW);

else if (message =="offf"){

digitalWrite(ledPin2, LOW);

delay(20);

You might also like