Hi all,
I experienced some weird problem with operating a 5V 8-relay board with an Arduino Mega.
I followed the excellent guidance specified here.
Please not that although in the below pictures, the jumper is still on the VCC and JD-VCC, it was removed for all experiments.
The external power that I use to power the relay board is 12V - 2000mA (see attachment).
To make sure that this power does what it is expected to do, I just hooked it up to the relay board as specified in the wiki and connected it to the VCC. The relay board's IN1 ... IN8 was connected to its GND.
It all looks like you can find in the attachment Scheme_1.
To go from 12V to 5V is done by the ywrobot board that outputs 700mA max. But that appears to be sufficient as all the relais were ON.
As a next step, I added the Arduino Mega with its own power-supply being the same type as the relay board power supply.
Now the VCC of the relay board is connected to the VCC of Arduino Mega.
The relay board's IN1 ... IN8 is connected from the Arduino pin 28 to 35.
Please find this in attachment Scheme_2.
The following sketch was loaded in the Arduino Mega, every second turning the next relay on and when they are all on, every second turning the next relay off in the same order.
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Time.h>
//Arduino1 - mac address
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//Arduino1 - ip number
IPAddress ip(192, 168, 111, 19);
//Arduino1 - local port
unsigned int localPort = 8888; // local port to listen on
void setup(){
Serial.begin(9600);
//start ethernet
Ethernet.begin(mac, ip);
for (int i = 28; i < 36; i++){
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}
}
void loop(){
for (int i = 28; i < 36; i++){
Serial.println ("Relay " + String(i-5) + " on");
digitalWrite(i, LOW);
delay (1000);
}
for (int i = 28; i < 36; i++){
Serial.println ("Relay " + String(i-5) + " off");
digitalWrite(i, HIGH);
delay (1000);
}
}
The results are as follows:
- the first time the relays are turned on one by one, everything goes well up until the 7th. Turning the 8th on rattles because it is switching on and off as quick as possible
- when the relays are then turned off one by one, the 8th no longer rattles as the first 2 relays are turned off.
- the second time the relays are turned on (because the program keeps running), the 7th relay goes nuts in the same way and so does the 8th.
- Once the first 2 relays are turned off, the rattling stops are those relays are just on as expected.
- This keeps going in the same way for the rest of the time.
Then I tested with another power supply to power the Arduino (12V - 1000mA). See attachment.
Executing the same sketch results in the first 7 relays being turned on as expected. The last relay was not turned and the led was not brightly shining. Once 1 or 2 relays were turned off, the 8th relay became on.
Thanks in advance for the help on clarifying this!