About Arduino Bluetooth Controller
this application can control up to 6 channel of relay with feedback function and All On and All Off function
hardware: arduino hc-06
5v to vcc
gnd to gnd
TX to RX
RX to TX
Arduino pins(2,3,4,5,6,7)
arduino code:char command;
String string;
boolean ledon1 = false;
boolean ledon2 = false;
boolean ledon3 = false;
boolean ledon4 = false;
boolean ledon5 = false;
boolean ledon6=false;
boolean allon = false;
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{string = "";}
while(Serial.available() > 0)
{
command = ((byte)Serial.read());
if(command == ':')
{
break;
}
else
{
string += command;
}
delay(1);
}
if(string == "1")
{
ledOn1();
ledon1 = true;
}
if(string =="2")
{
ledOff1();
ledon1 = false;
}
if(string == "3")
{
ledOn2();
ledon2 = true;
}
if(string =="4")
{
ledOff2();
ledon2 = false;
}
if(string == "5")
{
ledOn3();
ledon3 = true;
}
if(string =="6")
{
ledOff3();
ledon3 = false;
}
if(string == "7")
{
ledOn4();
ledon4 = true;
}
if(string == "8")
{
ledOff4();
ledon4 = false;
}
if(string == "9")
{
ledOn5();
ledon5 = true;
}
if(string == "a")
{
ledOff5();
ledon5 = false;
}
if(string == "b")
{
ledOn6();
ledon6 = true;
}
if(string == "c")
{
ledOff6();
ledon6 = false;
}
if(string == "d")
{
allOn();
allon = true;
}
if(string == "e")
{
allOff();
allon = false;
}
}
void ledOn1()
{
digitalWrite(2, HIGH);
}
void ledOff1()
{
analogWrite(2, LOW);
}
void ledOn2()
{
digitalWrite(3, HIGH);
}
void ledOff2()
{
digitalWrite(3, LOW);
}
void ledOn3()
{
digitalWrite(4, HIGH);
}
void ledOff3()
{
digitalWrite(4, LOW);
}
void ledOn4()
{
digitalWrite(5, HIGH);
}
void ledOff4()
{
digitalWrite(5, LOW);
}
void ledOn5()
{
digitalWrite(6, HIGH);
}
void ledOff5()
{
digitalWrite(6, LOW);
}
void ledOn6()
{
digitalWrite(7, HIGH);
}
void ledOff6()
{
digitalWrite(7, LOW);
}
void allOn()
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
void allOff()
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7 LOW);
}
by G####:
Best app on the store !