#include <SoftwareSerial.h>
SoftwareSerial HC06(2,3);
int redLED = 6;
int yellowLED = 7;
int greenLED = 8;
void setup() {
Serial.begin(9600); // Start serial communication with the Serial Monitor
HC06.begin(9600);
// Initialize LED pins as output
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
// Turn off all LEDs at the start
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
Serial.println("Bluetooth Controlled Traffic Light Ready");
}
void loop() {
// Check if data is available from the Bluetooth module
if (BTSerial.available()) {
char command = BTSerial.read(); // Read the incoming command
Serial.print("Command received: ");
Serial.println(command);
// Control the traffic lights based on the command received
if (command == 'r') {
// Turn on Red LED, turn off others
digitalWrite(redLED, HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
}
else if (command == 'y') {
// Turn on Yellow LED, turn off others
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, HIGH);
digitalWrite(greenLED, LOW);
}
else if (command == 'g') {
// Turn on Green LED, turn off others
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, HIGH);
}
else if (command == '0') {
// Turn off all LEDs
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
}
}
}
// HC-06 Bluetooth Module Connection: TX = 2, RX =3, and 5 V / GND
// In Arduino IDE Serial Monitor, set 'No Line Ending'
// Enter 'AT' to get 'OK' response, then
// Enter 'AT+NAMEBT1234' to set HC-06 Module Name to 'BT1234'
// Enter 'AT+PIN1234' to set HC-06 Module PIN to '1234'
// Recommended Smartphoe App for connection is
// Arduino Bluetooth Control by broxcode
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
chip1:RXD
chip1:TXD
chip1:GND
chip1:VCC
led1:A
led1:C
r1:1
r1:2
led2:A
led2:C
led3:A
led3:C
r2:1
r2:2
r3:1
r3:2