Hello,
We've been experiencing some broadband issues recently and after lengthy investigation with our provider's engineers, we have discovered excessive RF noise is being caused by my Arduinos and Ethernet shields, and this can cause broadband faults and connection dropouts.
I have created a basic lighting automation system and duplicated it for the upstairs and downstairs lighting circuits. They are in their own enclosure to keep upstairs and downstairs separate. It uses an Arduino Mega (clone) and Ethernet Shield (genuine Arduino) in each case, powered by an external power supply (one per Arduino). The Megas simply switch relay boards with digital outputs to operate the lights. This bit all works fine.
The network is standalone and uses an old Netgear router. There is a Raspberry Pi as an MQTT broker and two of these lighting control boxes I've just described. The MQTT commands are sent from an Android tablet until I sort out a hardware solution for this element.
The RF noise can be heard using a handheld radio tuned to 612KHz. I can even hear it in the car while driving away from the property!!
The noise is present when only both Arduinos are connected to the network. Individually they don't cause an issue and the noise is not present.
Unplugging either Arduino makes the noise stop immediately.
Using a different router (Zyxel) has no impact, the noise is the same and behaves the same.
Using a different transformer for the routers makes no difference.
Using different cables makes no difference.
Using different cable routes makes no difference.
I've seen another person's article describing a similar problem back in 2014 but there was no reply so I don't know if it was solved - link below
Can anybody shed any light on this???
Thanks in advance, code now added below...
Mark.
// Arduino IP 192.168.0.104
// Downstairs Lights Relay Controller
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <MQTTClient.h>
#include <system.h>
/* ---------- DO NOT EDIT ANYTHING ABOVE THIS LINE ---------- */
//Only edit the settings in this section
/* MQTT Settings */
// Topic which listens for commands
char* subscribeTopic = "Lights/Downstairs";
//MQTT Server IP Address
const char* server = "192.168.0.2";
//Unique device ID
const char* mqttDeviceID = "DownLightsMEGA";
IPAddress ip(192, 168, 0, 104);
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
/* ---------- DO NOT EDIT ANYTHING BELOW THIS LINE ---------- */
//MQTT
EthernetClient net;
MQTTClient client;
unsigned long lastMillis = 0;
//Connect to MQTT
void connect();
// pin assignments
int vccA = 21;
int relay1A = 37;
int relay2A = 35;
int relay3A = 33;
int relay4A = 31;
int relay5A = 29;
int relay6A = 27;
int relay7A = 25;
int relay8A = 23;
int groundA = 39;
int vccB = 20;
int relay1B = 36;
int relay2B = 34;
int relay3B = 32;
int relay4B = 30;
int relay5B = 28;
int relay6B = 26;
int relay7B = 24;
int relay8B = 22;
int groundB = 38;
//Setup pins, wifi, webserver and MQTT
void setup()
{
Serial.begin(9600);
delay(200);
Serial.println("Serial ready...");
Serial.println("Configuration:");
Serial.print("MQTT Server IP: ");
Serial.println(server);
Serial.print("MQTT Topic: ");
Serial.println(subscribeTopic);
Serial.print("MQTT Device ID: ");
Serial.println(mqttDeviceID);
Serial.println("Node IP Address: ***///still needs configuring to display this///***");
// set pin modes
pinMode(LED_BUILTIN, OUTPUT);
pinMode(vccA, OUTPUT);
pinMode(relay1A, OUTPUT);
pinMode(relay2A, OUTPUT);
pinMode(relay3A, OUTPUT);
pinMode(relay4A, OUTPUT);
pinMode(relay5A, OUTPUT);
pinMode(relay6A, OUTPUT);
pinMode(relay7A, OUTPUT);
pinMode(relay8A, OUTPUT);
pinMode(groundA, OUTPUT);
pinMode(vccB, OUTPUT);
pinMode(relay1B, OUTPUT);
pinMode(relay2B, OUTPUT);
pinMode(relay3B, OUTPUT);
pinMode(relay4B, OUTPUT);
pinMode(relay5B, OUTPUT);
pinMode(relay6B, OUTPUT);
pinMode(relay7B, OUTPUT);
pinMode(relay8B, OUTPUT);
pinMode(groundB, OUTPUT);
// set pin intial states
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(vccA, HIGH); // VCC pin set for relay bank
digitalWrite(relay1A, HIGH); // Start with the relay switched off
digitalWrite(relay2A, HIGH); // Start with the relay switched off
digitalWrite(relay3A, HIGH); // Start with the relay switched off
digitalWrite(relay4A, HIGH); // Start with the relay switched off
digitalWrite(relay5A, HIGH); // Start with the relay switched off
digitalWrite(relay6A, HIGH); // Start with the relay switched off
digitalWrite(relay7A, HIGH); // Start with the relay switched off
digitalWrite(relay8A, HIGH); // Start with the relay switched off
digitalWrite(groundA, LOW); // Ground pin set for relay bank
digitalWrite(vccB, HIGH); // VCC pin set for relay bank
digitalWrite(relay1B, HIGH); // Start with the relay switched off
digitalWrite(relay2B, HIGH); // Start with the relay switched off
digitalWrite(relay3B, HIGH); // Start with the relay switched off
digitalWrite(relay4B, HIGH); // Start with the relay switched off
digitalWrite(relay5B, HIGH); // Start with the relay switched off
digitalWrite(relay6B, HIGH); // Start with the relay switched off
digitalWrite(relay7B, HIGH); // Start with the relay switched off
digitalWrite(relay8B, HIGH); // Start with the relay switched off
digitalWrite(groundB, LOW); // Ground pin set for relay bank
Ethernet.begin(mac, ip); // initialize Ethernet
client.begin(server, net);
client.onMessage(messageReceived);
connect();
}
void connect()
{
while (!client.connect(mqttDeviceID))
{
delay(1000);
}
client.subscribe(subscribeTopic);
}
void loop()
{
client.loop();
// Make sure device is connected
if(!client.connected())
{
connect();
}
}
// Change the state of a relay based on the MQTT Message
void messageReceived(String &topic, String &payload)
{
String msgString = payload;
Serial.print("Message received: ");
Serial.println(msgString);
if (msgString == "LEDON")
{
digitalWrite(LED_BUILTIN, HIGH);
}
else if (msgString == "LEDOFF")
{
digitalWrite(LED_BUILTIN, LOW);
}
if (msgString == "LIGHT17ON")
{
digitalWrite(relay1A, LOW);
}
else if (msgString == "LIGHT17OFF")
{
digitalWrite(relay1A, HIGH);
}
if (msgString == "LIGHT18ON")
{
digitalWrite(relay2A, LOW);
}
else if (msgString == "LIGHT18OFF")
{
digitalWrite(relay2A, HIGH);
}
if (msgString == "LIGHT19ON")
{
digitalWrite(relay3A, LOW);
}
else if (msgString == "LIGHT19OFF")
{
digitalWrite(relay3A, HIGH);
}
if (msgString == "LIGHT20ON")
{
digitalWrite(relay4A, LOW);
}
else if (msgString == "LIGHT20OFF")
{
digitalWrite(relay4A, HIGH);
}
if (msgString == "LIGHT21ON")
{
digitalWrite(relay5A, LOW);
}
else if (msgString == "LIGHT21OFF")
{
digitalWrite(relay5A, HIGH);
}
if (msgString == "LIGHT22ON")
{
digitalWrite(relay6A, LOW);
}
else if (msgString == "LIGHT22OFF")
{
digitalWrite(relay6A, HIGH);
}
if (msgString == "LIGHT23ON")
{
digitalWrite(relay7A, LOW);
}
else if (msgString == "LIGHT23OFF")
{
digitalWrite(relay7A, HIGH);
}
if (msgString == "LIGHT24ON")
{
digitalWrite(relay8A, LOW);
}
else if (msgString == "LIGHT24OFF")
{
digitalWrite(relay8A, HIGH);
}
if (msgString == "LIGHT25ON")
{
digitalWrite(relay1B, LOW);
}
else if (msgString == "LIGHT25OFF")
{
digitalWrite(relay1B, HIGH);
}
if (msgString == "LIGHT26ON")
{
digitalWrite(relay2B, LOW);
}
else if (msgString == "LIGHT26OFF")
{
digitalWrite(relay2B, HIGH);
}
if (msgString == "LIGHT27ON")
{
digitalWrite(relay3B, LOW);
}
else if (msgString == "LIGHT27OFF")
{
digitalWrite(relay3B, HIGH);
}
if (msgString == "LIGHT28ON")
{
digitalWrite(relay4B, LOW);
}
else if (msgString == "LIGHT28OFF")
{
digitalWrite(relay4B, HIGH);
}
if (msgString == "LIGHT29ON")
{
digitalWrite(relay5B, LOW);
}
else if (msgString == "LIGHT29OFF")
{
digitalWrite(relay5B, HIGH);
}
if (msgString == "LIGHT30ON")
{
digitalWrite(relay6B, LOW);
}
else if (msgString == "LIGHT30OFF")
{
digitalWrite(relay6B, HIGH);
}
if (msgString == "LIGHT31ON")
{
digitalWrite(relay7B, LOW);
}
else if (msgString == "LIGHT31OFF")
{
digitalWrite(relay7B, HIGH);
}
if (msgString == "LIGHT32ON")
{
digitalWrite(relay8B, LOW);
}
else if (msgString == "LIGHT32OFF")
{
digitalWrite(relay8B, HIGH);
}
}