Problem in Switching 8 leds on and off via Bluetooth.

hi,
sorry if this question has been answered before but i tried and searched but to no avail.
i have modified genotronix (sorry if i have spelled it incorrectly) code which was to work with one led only… to work with 8 leds …
i am using hc-05 module of bluetooth and pin 10 and 11 for rx and tx and others 13,12,9,8,7,6,5 and 4 pin for leds.
i use bluetooth terminal for android to control leds.

problem is thatif i use only one led … the program works perfectly…
but when i increase the no. of leds i have to click 10 - 15 time to send a command…
the code is provided as follows… please let me know where i am wrong
i have to use relays to connect AC power to my project but thought of working with leds first…
… thanks in advance…

“”"""""""""“Modified Code”"""""""""""""

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial FreePower(10, 11); // RX, TX
int ledpin1=13;
int ledpin2=12;
int ledpin3=9;
int ledpin4=8;
int ledpin5=7;
int ledpin6=6;
int ledpin7=5;
int ledpin8=4;

int BluetoothData; // the data given from Computer

void setup() {
// put your setup code here, to run once:
FreePower.begin(115200);
FreePower.println(“Enjoy”);
pinMode(ledpin1,OUTPUT);
pinMode(ledpin2,OUTPUT);
pinMode(ledpin3,OUTPUT);
pinMode(ledpin4,OUTPUT);
pinMode(ledpin5,OUTPUT);
pinMode(ledpin6,OUTPUT);
pinMode(ledpin7,OUTPUT);
pinMode(ledpin8,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘A’){ // if number 1 pressed …
digitalWrite(ledpin1,1);
FreePower.println("LED On D13 ON ! ");
}
if (BluetoothData==‘a’){// if number 0 pressed …
digitalWrite(ledpin1,0);
FreePower.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘B’){ // if number 1 pressed …
digitalWrite(ledpin2,1);
FreePower.println("LED On D12 ON ! ");
}
if (BluetoothData==‘b’){// if number 0 pressed …
digitalWrite(ledpin2,0);
FreePower.println("LED On D12 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘C’){ // if number 1 pressed …
digitalWrite(ledpin3,1);
FreePower.println("LED On D09 ON ! ");
}
if (BluetoothData==‘c’){// if number 0 pressed …
digitalWrite(ledpin3,0);
FreePower.println("LED On D09 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘D’){ // if number 1 pressed …
digitalWrite(ledpin4,1);
FreePower.println("LED On D08 ON ! ");
}
if (BluetoothData==‘a’){// if number 0 pressed …
digitalWrite(ledpin4,0);
FreePower.println("LED On D08 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘E’){ // if number 1 pressed …
digitalWrite(ledpin5,1);
FreePower.println("LED On D07 ON ! ");
}
if (BluetoothData==‘e’){// if number 0 pressed …
digitalWrite(ledpin5,0);
FreePower.println("LED On D07 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘F’){ // if number 1 pressed …
digitalWrite(ledpin6,1);
FreePower.println("LED On D06 ON ! ");
}
if (BluetoothData==‘f’){// if number 0 pressed …
digitalWrite(ledpin6,0);
FreePower.println("LED On D06 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘G’){ // if number 1 pressed …
digitalWrite(ledpin7,1);
FreePower.println("LED On D05 ON ! ");
}
if (BluetoothData==‘g’){// if number 0 pressed …
digitalWrite(ledpin7,0);
FreePower.println("LED On D04 Off ! ");
}
}
delay(100);// prepare for next data …
if (FreePower.available()){
BluetoothData=FreePower.read();
if(BluetoothData==‘H’){ // if number 1 pressed …
digitalWrite(ledpin8,1);
FreePower.println("LED On D04 ON ! ");
}
if (BluetoothData==‘h’){// if number 0 pressed …
digitalWrite(ledpin8,0);
FreePower.println("LED On D04 Off ! ");
}
}
delay(100);// prepare for next data …
}

“”"""""""""""""""""""""""""""""""""""""'Original Code for Bluetooth terminal for android"""""""""""""""""""""""""""""""""""""""""""""""""""""

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println(“Bluetooth On please press 1 or 0 blink LED …”);
pinMode(ledpin,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData==‘1’){ // if number 1 pressed …
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData==‘0’){// if number 0 pressed …
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data …
}

Why not do all the tests on the incoming character at once?
Why not use code tags?

Debug messages for G and H need some work.

Read the command once, then test for all possiblities before reading again - that's
why the current code

// which should be edited to be in code tags like this please

requires lots of retries.

thankyou for replying so quickly !!!!!!

sorry i am very much new to arduino platform .... and trying to learn by mistakes.... and reading books.... still in the process...... will take some time

delay(100) 8 times. No wonder it takes a while to get a response. Take on board the suggestions, particularly about reading the input only once.

link of orignal project is as follows

Can anyone help?

Have you tried implementing the suggestions made in this thread ?

Yes I tried to change the delays timing to 10......

I have read various threads and diy tutorials but didnt find my answer... so if anyone can help itll be highly appritiated....

single led with bluetooth is working perfectly but when I try to modify the code its giving me delay...... I have to press on button various time to get the led started... there is no error when I click verify button.
please if u have any link which can guide me or if u can send code to switch 8 leds on and off... please send it to me... been trying for a long time now.

Think of it this way: you're in a room with eight light switches.
Someone is passing you messages telling you to turn a switch on or off.
You take a message and read it
Is it a command to switch on light three?
No, so take another message.

Does that seem sensible?

It is obvious how you got where you are by looking at the comments in the original code and in yours
if(BluetoothData=='B'){  // if number 1 pressed ..Copy/Paste/Modify is a good way to save typing but you have copied the whole of the read/test section of code and changed the tests when you do not need to read again and again.

Look at the original code. How many times does it read from serial ? (once)
How many tests does it do in the byte received ? (two)

Can you extend this to deal with more tests without doing any more reads, I wonder ?

thanks for the replies.... got a few hints from the answer and will try to correct my code...... by the way i corrected the if(BluetoothData=='B'){ // if number 1 pressed ..
to if(BluetoothData=='B'){ // if number B pressed ..

and all the tags before posting this message.... but copied the code which was at early stage....
still not sure about the delays but will read about it now .... :slight_smile: thankyou all

to if(BluetoothData=='B'){   // if number B pressed ..

Number B?

AWOL and ukhelibob and all those who replied ........ thanks alot .......... got it up and running flawlessly...... Awol your example just hit my head like a nail in the wall..... and the hint given by UKHELIBOB also helped me alot...... thankyou guys....... thanks alot

hello again ,
stuck again with a problem or should i say confusion…
following is what the start of code looks like…
###################################################
SoftwareSerial serial(10, 11); // RX, TX
int ledpin1=13; // Connected on d13
int ledpin2=12; // Connected on d12
int ledpin3=9; // Connected on d9
int ledpin4=8; // Connected on d8
int ledpin5=7; // Connected on d7
int ledpin6=6; // Connected on d6
int ledpin7=5; // Connected on d5
int ledpin8=4; // Connected on d4
#####################################################

i am using mega adk board and want to program the software on attiny 44 or 84.
the confusion is that i downloaded pinout of attiny 44/84 and it says that rx/tx pins are on d0,d1 while i am using pin d10, and d11
on the other hand it is also shown in the picture that attiny only supports d0-d10 pins…
i tried to use d0 and d1 pins as rx tx but they are not working.
i am also sharing a picture of pin mapping that i downloaded.
I am confused that if i use my pins as they are then it will not work… any suggestions?

ATtiny84_arduino-tiny_pins.png

anyone?

i am using mega adk board and want to program the software on attiny 44 or 84.
the confusion is that i downloaded pinout of attiny 44/84 and it says that rx/tx pins are on d0,d1 while i am using pin d10, and d11
on the other hand it is also shown in the picture that attiny only supports d0-d10 pins.....
i tried to use d0 and d1 pins as rx tx but they are not working.

I am not familiar with the attiny 44 or 85 but I am not surprised that pins D0 and D1 are used for Rx and Tx because that is the same as the Uno. On the Uno they are wired to the hardware serial interface and cannot be used for anything else if hardware serial comms is used.

As to the paucity of pins on the tiny, that is what you would expect when the total pin count is so low. You may have to consider adding more hardware, such as a shift register, and clocking out the individual bits if a byte variable to be displayed by the LEDs.