Well, to start with, I cannot find a category for the problem I'm having. And, I have done as much searching as I know how too to find an answer to the problem.
So, in a nut shell, the problem is the relays run wild, faster and faster if left un-plugged.
This happens when using an 8 Relay Module, Arduino Uno (two different boards, and two or three different sketches, attaching a (measured 4.95dc from a 2elego supply) to the GND and JD-VCC of the 8 Relay Module.
The sketch and the 8 Relay Module work fine (normally, see below) when using the arduino-uno board power supply (cap on VCC, JD-VCC.
I am using a downloaded Delphi Kontrol program to switch on/off. FYI, the Delphi is not the problem because at times, when reworking the sketch to find the problem, the relays will run wild without Delphi connected.
[note: I had previously referenced the wrong site]
Correct site: Project III - 6. Control 8 Channel Relay with Delphi Apps on PC (Arduino Based) | basic arduino tutorial
One exception here: the on buttons and the off buttons are reversed on Delphi Kontrol.
I began with this sketch, but have tried others.
Currently working with the one seen below.
However, I'm missing something to make to make Arduino Uno activate the relays. Delphi is working, indicated by the TX light blinking when a button is pushed.
The relays are all on (why?). And when the external power is connected as discribed above, the relays run wild.
When the sketch is correct, I can turn the relays on and off, but when all eight are on, they run wild (non stop on and off).
So, first help me fix this particular sketch, then we can address the root problem of run-away relays.
The lcd works fine. And by the way, I am confident the "basic" wiring between the Arduino board and the relays is correct. See most anyones 8 channel wiring diagram.
[Sketch originally used] This makes the relays come on when loaded, the go into run-away mode.
Note: I have not changed this sketch.
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
char b;
void setup(){
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
digitalWrite(9, 0);
digitalWrite(10, 0);
digitalWrite(11, 0);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("Kontrol 8 Relay");
lcd.setCursor(0,1);
lcd.print(" via Delphi");
delay(2000);
lcd.setCursor(0,1);
lcd.print("Tunggu Koneksi..");
do{
b = Serial.read();
}
while(b != 'R');
lcd.setCursor(0,1);
lcd.print("Koneksi OK ");
}
void loop(){
b = Serial.read();
switch(b){
//---------------------------Perintah Relay ON
case 'A': lcd.setCursor(0,1);
lcd.print("Relay 1 ON ");
digitalWrite(4, 1); // Relay1 on
break;
case 'B': lcd.setCursor(0,1);
lcd.print("Relay 2 ON ");
digitalWrite(5, 1); // Relay2 on
break;
case 'C': lcd.setCursor(0,1);
lcd.print("Relay 3 ON ");
digitalWrite(6, 1); // Relay3 on
break;
case 'D': lcd.setCursor(0,1);
lcd.print("Relay 4 ON ");
digitalWrite(7, 1); // Relay4 on
break;
case 'E': lcd.setCursor(0,1);
lcd.print("Relay 5 ON ");
digitalWrite(8, 1); // Relay5 on
break;
case 'F': lcd.setCursor(0,1);
lcd.print("Relay 6 ON ");
digitalWrite(9, 1); // Relay6 on
break;
case 'G': lcd.setCursor(0,1);
lcd.print("Relay 7 ON ");
digitalWrite(10, 1); // Relay7 on
break;
case 'H': lcd.setCursor(0,1);
lcd.print("Relay 8 ON ");
digitalWrite(11, 1); // Relay8 on
break;
//-------------------------- Perintah Relay OFF
case 'a': lcd.setCursor(0,1);
lcd.print("Relay 1 OFF ");
digitalWrite(4, 0); // Relay1 off
break;
case 'b': lcd.setCursor(0,1);
lcd.print("Relay 2 OFF ");
digitalWrite(5, 0); // Relay2 off
break;
case 'c': lcd.setCursor(0,1);
lcd.print("Relay 3 OFF ");
digitalWrite(6, 0); // Relay3 off
break;
case 'd': lcd.setCursor(0,1);
lcd.print("Relay 4 OFF ");
digitalWrite(7, 0); // Relay4 off
break;
case 'e': lcd.setCursor(0,1);
lcd.print("Relay 5 OFF ");
digitalWrite(8, 0); // Relay5 off
break;
case 'f': lcd.setCursor(0,1);
lcd.print("Relay 6 OFF ");
digitalWrite(9, 0); // Relay6 off
break;
case 'g': lcd.setCursor(0,1);
lcd.print("Relay 7 OFF ");
digitalWrite(10, 0); // Relay7 off
break;
case 'h': lcd.setCursor(0,1);
lcd.print("Relay 8 OFF ");
digitalWrite(11, 0); // Relay8 off
break;
//----------------------------koneksi
case 'R': lcd.setCursor(0,1);
lcd.print("Koneksi OK ");
break;
case 'r': lcd.setCursor(0,1);
lcd.print("Koneksi OFF ");
break;
}
}`Preformatted text`
Thanks, Daniel
Current Sketch:
// Found Home Automation System at https://harshsharmatechnicals.com/2018/01/30/code-and-circuit-diagram-for-home-automation-system-using-arduino/
// 1) Home Automation System
// CODE :-
#include <ezButton.h> // Debounce added in an effort to stop relays from
// run-away effect.
ezButton button1 (3); // create ezButton object that attach to pin 3;
ezButton button2 (4);
ezButton button3 (5);
ezButton button4 (6);
ezButton button5 (7);
ezButton button6 (8);
ezButton button7 (9);
ezButton button8 (10);
#include <LiquidCrystal.h>
const int rs = 14, en = 15, d4 = 16, d5 = 17 , d6 = 18, d7 = 19;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //make these pins output
int output;
// ****** Home Automation Code starts here *****************
//****** With codes added to use Liquid Crystal ****
#define relay1 3 //Connect relay1 to pin 3
#define relay2 4 //Connect relay2 to pin 4
#define relay3 5 //Connect relay3 to pin 5
#define relay4 6 //Connect relay4 to pin 6
#define relay5 7 //Connect relay5 to pin 7
#define relay6 8 //Connect relay6 to pin 8
#define relay7 9 //Connect relay7 to pin 9
#define relay8 10 //Connect relay8 to pin 10
char b;
char c;
// ************************** Setup begins
void setup()
{
Serial.begin(9600); //Set rate for communicating with adelphi
// Debounce added in an effort to stop relays from Run-away.
button1.setDebounceTime(500); // set debounce time to 100 milliseconds
button2.setDebounceTime(500);
button3.setDebounceTime(500);
button4.setDebounceTime(500);
button5.setDebounceTime(500);
button6.setDebounceTime(500);
button7.setDebounceTime(500);
button8.setDebounceTime(500);
pinMode(relay1, OUTPUT); //Set relay2 as an output
pinMode(relay2, OUTPUT); //Set relay1 as an output
pinMode(relay3, OUTPUT); //Set relay2 as an output
pinMode(relay4, OUTPUT); //Set relay1 as an output
pinMode(relay5, OUTPUT); //Set relay2 as an output
pinMode(relay6, OUTPUT); //Set relay1 as an output
pinMode(relay7, OUTPUT); //Set relay2 as an output
pinMode(relay8, OUTPUT); //Set relay1 as an output
digitalWrite(relay1, LOW); //Swtich relay1 off
digitalWrite(relay2, LOW); //Switch relay2 off
digitalWrite(relay3, LOW); //Swtich relay3 off
digitalWrite(relay4, LOW); //Switch relay4 off
digitalWrite(relay5, LOW); //Swtich relay5 off
digitalWrite(relay6, LOW); //Switch relay6 off
digitalWrite(relay7, LOW); //Swtich relay7 off
digitalWrite(relay8, LOW); //Switch relay8 off
lcd.begin(16, 1);
lcd.setCursor(0, 1);
lcd.print("ok Daniel");
delay(4000);
do
b = Serial.read();
while (b != 'R');
lcd.setCursor(2, 1);
lcd.print("What? OK");
}
void loop() // ****************** void loop begins
{
Serial.begin(9600);
b = Serial.read();
// switch (b);
while (Serial.available()) //Check if there are available bytes to read
{
delay(50); //Delay to make it stable
char c = Serial.read(); //Conduct a serial read
c = Serial.read();
if (c == '#') {
break; //Stop the loop once # is detected after a word
}
inputs += c; //Means inputs = inputs + c
}
if (inputs.length() > 1)
{
Serial.println(inputs);
if (inputs == "A") //Relay 1
{
digitalWrite(relay1, LOW); //*******
}
else if (inputs == "a") //*******
{
digitalWrite(relay1, HIGH); //Relay 1
}
}
else if (inputs == "B") //Relay 2
{
digitalWrite(relay2, LOW);
}
else if (inputs == "b")
{
digitalWrite(relay2, HIGH); //Relay 2
}
else if (inputs == "C") //Relay 3
{
digitalWrite(relay3, LOW);
}
else if (inputs == "c")
{
digitalWrite(relay3, HIGH); // Relay 3
}
else if (inputs == "D")
{
digitalWrite(relay4, LOW);
}
else if (inputs == "d")
{
digitalWrite(relay4, HIGH);
}
else if (inputs == "E")
{
digitalWrite(relay5, LOW);
}
else if (inputs == "e")
{
digitalWrite(relay5, HIGH);
}
else if (inputs == "F")
{
digitalWrite(relay6, LOW);
}
else if (inputs == "f")
{
digitalWrite(relay6, HIGH);
}
else if (inputs == "G")
{
digitalWrite(relay7, LOW);
}
else if (inputs == "g")
{
digitalWrite(relay7, HIGH);
}
else if (inputs == "H")
{
digitalWrite(relay8, LOW);
}
else if (inputs == "h")
{
digitalWrite(relay8, HIGH);
}
inputs = "";
return;
}
//break // if (inputs.length() .0;}`Preformatted text``Preformatted text`
