I'm working on my project in that im to controlling traffic light with android which are connect by HC-05 using Arduino Uno. HC-05 is connecting with android.
At first I have make single led on and off with android through Hc-05 it was working without delay.
I have build app with MIT App inventor.
Now i have made connection of 12 led with arduino and programmed it. The HC-05 was receiving data but there was of 25 sec ( when i pressed on from mobile the HC-05 was receiving it after 25 sec).
I thought HC-05 is getting low power due to 12 leds connected on arduino.
Then i commented 6 leds working and forgot to remove connection of that 6 leds then the delay reduced to 10 sec.
I figured out that as the code length increases the communication delay also increases.
I have allo tried to change the baud rate, but i was getting garbge values at 38400 baud rate so im now using 9600.
Please help me to reduce this delay in project.
HC -05 PINS >>> ARDUINO PINS
EN 3.3v
Vcc 5v
gnd gnd
RX TX
tx rx
######## Code ######
char Incoming_value = 0;
int red1 = 2;
int yel1 = 3;
int gre1 = 4;
int red2 = 5;
int yel2 = 6;
int gre2 = 7;
int red3 = 8;
int yel3 = 9;
int gre3 = 10;
int red4 = 11;
int yel4 = 12;
int gre4 = 13;
void setup()
{
pinMode(red1,OUTPUT);
pinMode(yel1,OUTPUT);
pinMode(gre1,OUTPUT);
pinMode(red2,OUTPUT);
pinMode(yel2,OUTPUT);
pinMode(gre2,OUTPUT);
pinMode(red3,OUTPUT);
pinMode(yel3,OUTPUT);
pinMode(gre3,OUTPUT);
pinMode(red4,OUTPUT);
pinMode(yel4,OUTPUT);
pinMode(gre4,OUTPUT);
Serial.begin(9600);
}
///////////////////////////////////////////// ## TRAFFIC 1 ## ////////////////////////////////////////////////////
void TRAFFIC_1(){
digitalWrite(red1, LOW);
digitalWrite(yel1, LOW);
digitalWrite(gre1, HIGH);
digitalWrite(red2, HIGH);
digitalWrite(yel2, LOW);
digitalWrite(gre2, LOW);
digitalWrite(red3, HIGH);
digitalWrite(yel3, LOW);
digitalWrite(gre3, LOW);
digitalWrite(red4, HIGH);
digitalWrite(yel4, LOW);
digitalWrite(gre4, LOW);
delay(5000);
////////////////////////
digitalWrite(red1, LOW);
digitalWrite(yel1, HIGH);
digitalWrite(gre1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yel2, HIGH);
digitalWrite(gre2, LOW);
digitalWrite(red3, HIGH);
digitalWrite(yel3, LOW);
digitalWrite(gre3, LOW);
digitalWrite(red4, HIGH);
digitalWrite(yel4, LOW);
digitalWrite(gre4, LOW);
delay(2000);
}
///////////////////////////////////////////// ## TRAFFIC 2 button ## ////////////////////////////////////////////////////
void TRAFFIC_2(){
digitalWrite(red1, HIGH);
digitalWrite(yel1, LOW);
digitalWrite(gre1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yel2, LOW);
digitalWrite(gre2, HIGH);
digitalWrite(red3, HIGH);
digitalWrite(yel3, LOW);
digitalWrite(gre3, LOW);
digitalWrite(red4, HIGH);
digitalWrite(yel4, LOW);
digitalWrite(gre4, LOW);
delay(5000);
////////////////////////
digitalWrite(red1, HIGH);
digitalWrite(yel1, LOW);
digitalWrite(gre1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yel2, HIGH);
digitalWrite(gre2, LOW);
digitalWrite(red3, LOW);
digitalWrite(yel3, HIGH);
digitalWrite(gre3, LOW);
digitalWrite(red4, HIGH);
digitalWrite(yel4, LOW);
digitalWrite(gre4, LOW);
delay(2000);
}
///////////////////////////////////////////// ## TRAFFIC 3 button ## ////////////////////////////////////////////////////
void TRAFFIC_3(){
digitalWrite(red1, HIGH);
digitalWrite(yel1, LOW);
digitalWrite(gre1, LOW);
digitalWrite(red2, HIGH);
digitalWrite(yel2, LOW);
digitalWrite(gre2, LOW);
digitalWrite(red3, LOW);
digitalWrite(yel3, LOW);
digitalWrite(gre3, HIGH);
digitalWrite(red4, HIGH);
digitalWrite(yel4, LOW);
digitalWrite(gre4, LOW);
delay(5000);
////////////////////////
digitalWrite(red1, HIGH);
digitalWrite(yel1, LOW);
digitalWrite(gre1, LOW);
digitalWrite(red2, HIGH);
digitalWrite(yel2, LOW);
digitalWrite(gre2, LOW);
digitalWrite(red3, LOW);
digitalWrite(yel3, HIGH);
digitalWrite(gre3, LOW);
digitalWrite(red4, LOW);
digitalWrite(yel4, HIGH);
digitalWrite(gre4, LOW);
delay(2000);
}
///////////////////////////////////////////// ## TRAFFIC 4 button ## ////////////////////////////////////////////////////
void TRAFFIC_4(){
digitalWrite(red1, HIGH);
digitalWrite(yel1, LOW);
digitalWrite(gre1, LOW);
digitalWrite(red2, HIGH);
digitalWrite(yel2, LOW);
digitalWrite(gre2, LOW);
digitalWrite(red3, HIGH);
digitalWrite(yel3, LOW);
digitalWrite(gre3, LOW);
digitalWrite(red4, LOW);
digitalWrite(yel4, LOW);
digitalWrite(gre4, HIGH);
delay(10000);
////////////////////////
digitalWrite(red1, LOW);
digitalWrite(yel1, HIGH);
digitalWrite(gre1, LOW);
digitalWrite(red2, HIGH);
digitalWrite(yel2, LOW);
digitalWrite(gre2, LOW);
digitalWrite(red3, HIGH);
digitalWrite(yel3, LOW);
digitalWrite(gre3, LOW);
digitalWrite(red4, LOW);
digitalWrite(yel4, HIGH);
digitalWrite(gre4, LOW);
delay(2000);
}
/////////////////////////////////////////////////// # START BUTTON # ///////////////////////////////////////////////////
void startbutton(){
digitalWrite(red1, HIGH);
digitalWrite(red2, HIGH);
digitalWrite(red3, HIGH);
digitalWrite(red4, HIGH);
delay(300);
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(red3, LOW);
digitalWrite(red4, LOW);
delay(300);
digitalWrite(red1, HIGH);
digitalWrite(red2, HIGH);
digitalWrite(red3, HIGH);
digitalWrite(red4, HIGH);
delay(20000);
}
/////////////////////////////////////////////////// Normal traffic working ///////////////////////////////////////////////////
void traffic_light(){
TRAFFIC_1();
TRAFFIC_2();
TRAFFIC_3();
TRAFFIC_4();
}
/////////////////////////////////////////////////// BT traffic working ///////////////////////////////////////////////////
void loop(){
traffic_light();
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("\n");
//////////////////////////////// ## START button ## //////////////////////////////////////////
if(Incoming_value == '1'){
startbutton();
}
//////////////////////////////// ## TRAFFIC 2 button ## //////////////////////////////////////////
if(Incoming_value == '2'){
TRAFFIC_1();
}
//////////////////////////////// ## TRAFFIC 3 button ## //////////////////////////////////////////
if(Incoming_value == '3'){
TRAFFIC_2();
}
//////////////////////////////// ## TRAFFIC 4 button ## //////////////////////////////////////////
if(Incoming_value == '4'){
TRAFFIC_3();
}
//////////////////////////////// ## TRAFFIC 5 button ## //////////////////////////////////////////
if(Incoming_value == '5'){
TRAFFIC_4();
}
}
}