// Bluetooth controlled lights using arudino uno and hc-05 bluetooth module
// This code was originally written for instructables: https://www.instructables.com/member/piyushsuteri/
// Youtube video available at: https://www.youtube.com/@piyushsuteri and https://youtube.com/shorts/8NufHkCCvnI?feature=share
// Author: Piyush Suteri
// 13:14, 16 March 2023
// bluetooth app link: https://play.google.com/store/apps/details?id=com.himanshu.ArduinoAutomation&pli=1
// disconnect tx and rx pins of bluetooth module before uploading this code
#define led_pin 7 // pin to which anode of indication led is connected
#define relay_pin 11 // pin to which signal pin of relay module is connected
char val; // integer variable which stores data recieved from mobile app via bluetooth
void setup() { // put your setup code here, to run once:
pinMode(led_pin, OUTPUT); // define led_pin as output
pinMode(relay_pin, OUTPUT); // define relay_pin as output
Serial.begin(9600); // initalize serial communication
}
void loop() { // put your main code here, to run repeatedly:
if (Serial.available()) { // check if data is recieved from bluetooth module
val = Serial.read(); // store data recieved from bluetooth in val
Serial.println(val); // print value in Serial monitor
if (val == 'A') { // check if data is 1
digitalWrite(led_pin, HIGH); // indicate that lights will be on using indicator led
digitalWrite(relay_pin, HIGH); // turn on relay
}
else if (val == 'a') { // othervise data recieved is not 0 so turn off relay
digitalWrite(led_pin, LOW); // indicate that lights will be off using indicator led
digitalWrite(relay_pin, LOW); // turn off relay
}
}
}