Hello
I am a new user here.
I want to ask if anybody have code for arduino uno and android application to control relays via Bluetooth.
Thanks
Hello
I am a new user here.
I want to ask if anybody have code for arduino uno and android application to control relays via Bluetooth.
Thanks
I use arduino uno and HC-05 Bluetooth
This would get you started, although can presently control only 1 relay,
http://forum.arduino.cc/index.php?topic=173246.0
Thank you for fast and accurate reply.
I try it and its work perfect!
Better if i can find the same with more channels
Thanks
I've been trying to get kas to add a couple more on/off channels, ;-).
EDIT: check here,
http://forum.arduino.cc/index.php?topic=173246.msg1323065#msg1323065
Id will be perfect, please let me know when id will be ready
Thanks
I find this code for 8 relays on/off switch
*/
int MAX_RELAYS = 8;
// Arrays used to "decode" incoming bytes and ports
int Relays[8] = {53, 51, 49, 47, 45, 43, 41, 39};
int KeysOn[8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
int KeysOff[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
int RelayStatus = 0;
void setup() {
Serial1.begin(9600); // initialize BT serial port:
Serial.begin(9600); // initialize debug serial port:
// Initialize PORTS
for(int i = 0; i < MAX_RELAYS; i++){
pinMode(Relays*, OUTPUT);*
_ digitalWrite(Relays*, LOW);_
_ }_
_ int zero = 0; // 0 cannot be used with .write directly, for some reason compiler gets errors*_
* Serial1.write(zero); // Send feedback in order to turn off buttons on Android app*
}
void loop() {
* // Send FeedBack to Android App so you know if the relay is actually turned on.*
* Serial1.write(RelayStatus);*
* if (Serial1.available() > 0) {*
* int inByte = Serial1.read();*
* for(int i = 0; i < MAX_RELAYS; i++){
TurnOn_Relay_on_Key(inByte, KeysOn_, Relays);
TurnOn_Relay_off_Key(inByte, KeysOff, Relays);
}
}
}
// Tunr on relay selected relay*
void TurnOn_Relay_on_Key(int input, int key, int port){
* if (input == key){
digitalWrite(port, HIGH);
Serial.print("Relay turned On: "); // Debug*
* Serial.println((char)key);
RelayStatus |= (1 << (key - KeysOn[0])); // Set Status*
}
}
// Tunr off relay selected relay
void TurnOn_Relay_off_Key(int input, int key, int port){
* if (input == key){
digitalWrite(port, LOW);
Serial.print("Relay turned Off: "); // Debug*
* Serial.println((char)key);
RelayStatus &= ~(1 << (key - KeysOff[0])); // Clear Status*
}
}
I try to upload in my arduino uno with no luck
I get error
sketch_jul20b:1: error: expected unqualified-id before '/' token
sketch_jul20b:1: error: expected constructor, destructor, or type conversion before '/' token
sketch_jul20b.ino: In function 'void setup()':
sketch_jul20b:11: error: 'Serial1' was not declared in this scope
sketch_jul20b:14: error: 'MAX_RELAYS' was not declared in this scope
sketch_jul20b.ino: In function 'void loop()':
sketch_jul20b:24: error: 'Serial1' was not declared in this scope
sketch_jul20b:28: error: 'MAX_RELAYS' was not declared in this scope
This code is compatible with BT Relay Control (android application)_
First off, use the '#' icon to wrap your code, so we can tell the code from the rest of the post. You can go back to your previous post, click on the 'Modify' button and fix it.
Secondly, always look at the very first error in the list, and fix that one. Then, most of the others usually disappear. In this case, it looks like the first '*/' is the problem.
Unfortunately I don't understand what I have to do....
What I was saying was, you use the '#' icon above the editing window and it makes your code look like the following. Also, if your sketch starts with */ as below, that's an error. Comments must be written as
/* .... */
The other thing is, you've not defined Serial1 anywheres. It's ok for a Mega board, but not a UNO like you mentioned. If you're trying to use SoftwareSerial [which never worked for me, BTW] you need something like
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2,3); // RX, TX
at the top of the sketch.
*/
int MAX_RELAYS = 8;
// Arrays used to "decode" incoming bytes and ports
int Relays[8] = {53, 51, 49, 47, 45, 43, 41, 39};
int KeysOn[8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
int KeysOff[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
int RelayStatus = 0;
void setup()
{
Serial1.begin(9600); // initialize BT serial port:
Serial.begin(9600); // initialize debug serial port:
// Initialize PORTS
for(int i = 0; i < MAX_RELAYS; i++){
pinMode(Relays, OUTPUT);
digitalWrite(Relays, LOW);
}
int zero = 0; // 0 cannot be used with .write directly, for some reason compiler gets errors
Serial1.write(zero); // Send feedback in order to turn off buttons on Android app
}
void loop()
{
// Send FeedBack to Android App so you know if the relay is actually turned on.
Serial1.write(RelayStatus);
if (Serial1.available() > 0) {
int inByte = Serial1.read();
for(int i = 0; i < MAX_RELAYS; i++){
TurnOn_Relay_on_Key(inByte, KeysOn, Relays);
TurnOn_Relay_off_Key(inByte, KeysOff, Relays);
}
}
}
// Tunr on relay selected relay
void TurnOn_Relay_on_Key(int input, int key, int port)
{
if (input == key){
digitalWrite(port, HIGH);
Serial.print("Relay turned On: "); // Debug
Serial.println((char)key);
RelayStatus |= (1 << (key - KeysOn[0])); // Set Status
}
}
// Tunr off relay selected relay
void TurnOn_Relay_off_Key(int input, int key, int port)
{
if (input == key){
digitalWrite(port, LOW);
Serial.print("Relay turned Off: "); // Debug
Serial.println((char)key);
RelayStatus &= ~(1 << (key - KeysOff[0])); // Clear Status
}
}