Hello,
I have a project using an Uno board, Sainsmart 16 relay module and an HC-05 BT module, controlled by an MIT App Inventor app.
I'm learning to create a phone app, while simultaneously learning Arduino coding, which is controlling a small machine I'm building that has electric motors, hydraulic valves, etc. I'm using App Inventor to create the app which appears to be working properly. But, I can't get the 16 relay module to trigger relays properly, actually they aren't triggering at all.
My app simply sends a letter value(A,a,B,b....etc.), to the Uno, to turn on/off relays.
Being new to Arduino, I've scoured many sources to resolve what I'm doing wrong in my code but have had no luck. I've successfully operated two relays but have since made changes to add the other relays and have messed something up. If someone could point out the mistakes I've made, I would be greatly appreciative.
The relay board has a 12v supply to operate the relays, 5v jumpered from the Uno to the relay module and to the HC-05. Output pins are jumpered from the Uno to the relay module.
I can establish connection from my phone to the BT module but then nothing happens when I hold buttons on my phone. Sorry if I haven't worded everything properly... ![]()
Example of phone app :
And my code:
char Incoming_value = 'A,a,B,b,C,c,D,d,E,e,F,f,G,g,H,h,J,j,K,k,L,l,M,m,N,n,P,p,Q,q,R,r'; // Values to be received from smartphone app via HC-05 BT module.
//Motor functions will be operated with directional buttons within MIT App Inventor App and send values to Arduino Uno board.
//Sainsmart 16 module relay board has 12v power connected as well as jumpers from Uno to Relay module as noted in String Function.
String inputs;
#define relay1 2 //Connect relay1 to pin 2
#define relay2 3 //Connect relay2 to pin 3
#define relay3 4 //Connect relay3 to pin 4
#define relay4 5 //Connect relay4 to pin 5
#define relay5 6 //Connect relay5 to pin 6
#define relay6 7 //Connect relay6 to pin 7
#define relay7 8 //Connect relay7 to pin 8
#define relay8 9 //Connect relay8 to pin 9
#define relay9 10 //Connect relay9 to pin 10
#define relay10 11 //Connect relay10 to pin 11
#define relay11 12 //Connect relay11 to pin 12
#define relay12 13 //Connect relay12 to pin 13
#define relay13 A0 //Connect relay13 to pin A0
#define relay14 A1 //Connect relay13 to pin A1
#define relay15 A2 //Connect relay13 to pin A2
#define relay16 A3 //Connect relay13 to pin A3
void setup()
{
Serial.begin(9600);
pinMode(relay1, OUTPUT); //Set pins as outputs
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
pinMode(relay9, OUTPUT);
pinMode(relay10, OUTPUT);
pinMode(relay11, OUTPUT);
pinMode(relay12, OUTPUT);
pinMode(relay13, OUTPUT);
pinMode(relay14, OUTPUT);
pinMode(relay15, OUTPUT);
pinMode(relay16, OUTPUT);
digitalWrite(relay1, HIGH); //Switch relay1 off
digitalWrite(relay2, HIGH); //Swtich relay2 off
digitalWrite(relay3, HIGH); //Switch relay3 off
digitalWrite(relay4, HIGH); //Swtich relay4 off
digitalWrite(relay5, HIGH); //Switch relay5 off
digitalWrite(relay6, HIGH); //Swtich relay6 off
digitalWrite(relay7, HIGH); //Switch relay7 off
digitalWrite(relay8, HIGH); //Swtich relay8 off
digitalWrite(relay9, HIGH); //Swtich relay9 off
digitalWrite(relay10, HIGH); //Swtich relay10 off
digitalWrite(relay11, HIGH); //Swtich relay11 off
digitalWrite(relay12, HIGH); //Swtich relay12 off
digitalWrite(relay13, HIGH); //Swtich relay13 off
digitalWrite(relay14, HIGH); //Swtich relay14 off
digitalWrite(relay15, HIGH); //Swtich relay15 off
digitalWrite(relay16, HIGH); //Swtich relay16 off
}
void loop()
{
if (Serial.available() > 0)
{
Incoming_value = Serial.read(); //Using If Function to switch relays on/off.
Serial.print(Incoming_value);
Serial.print("\n"); {
if (Incoming_value == 'A')
digitalWrite(relay1, LOW);
else if (Incoming_value == 'a')
digitalWrite(relay1, HIGH); {
if (Incoming_value == 'A')
Serial.println("Engine Starting");
else Serial.println("Engine Start Released");
}
}
if (Incoming_value == 'B')
digitalWrite(relay2, LOW);
else if (Incoming_value == 'b')
digitalWrite(relay2, HIGH); {
if (Incoming_value == 'B')
Serial.println("Engine Relay Engaged");
else Serial.println("Engine Relay Disengaged");
}
if (Incoming_value == 'C')
digitalWrite(relay3, LOW);
else if (Incoming_value == 'c')
digitalWrite(relay3, HIGH); {
if (Incoming_value == 'C')
Serial.println("Engine High Rpm");
else Serial.println("Engine Low Rpm");
}


