Hi,
Im looking for some help with my project. I have an arduino uno which runs two timers to trigger a relay and two buttons to trigger the relay for either an hour or two hours. I’m using an offical Arduino Uno with ethernet shield and relay board. I have tried a relay shield and now using one that sits in the box with trailing leads to it.
My network keeps dropping out. I cannot ping the arduino, if I reset the arduino it comes back online, and whilst its offline another device in the same switch maintains network/internet.
One of my timers is currently set to 19:00-19:45 and for the last three days it drops at 19:39 (taken from the offline time in the blynk app) so not clashing with when the relay is triggering.
I have tried numerous boards and network shields so wondering if there can be an issue with my code?
Any help would be greatly appreciated.
See below for code:
// Following includes are for Arduino Ethernet Shield (W5100)
#include <SimpleTimer.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include <WidgetRTC.h> //blynk time server
//
byte arduino_mac[] = { 0xC0, 0x15, 0xC0, 0xFE, 0xEF, 0x81 };
IPAddress arduino_ip ( 192, 168, 1, 169);
IPAddress dns_ip ( 192, 168, 1, 254);
IPAddress gateway_ip ( 192, 168, 1, 254);
IPAddress subnet_mask(255, 255, 255, 0);
char auth[] = "**"; // Put your Auth Token here. (see Step 3 above)
int Seconds = 0;
int Minutes = 0;
int morninghourstart;
int morningminuetstart;
int eveninghourstart;
int eveningminuetstart;
int morninghourstop;
int morningminuetstop;
int eveninghourstop;
int eveningminuetstop;
int heatingtime = 0;
int heatingcontrol;
int ClockSwitch;
int Relay = A5;
int powercut = 1;
WidgetLED led2(V2);
WidgetLED led3(V3);
SimpleTimer timer;
WidgetRTC rtc;
void setup()
{
pinMode(Relay, OUTPUT); // Power On
digitalWrite(Relay, LOW); //set ssd relay off
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "blynk-cloud.com", 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
while (Blynk.connect() == false) {
// Wait until connected
}
Serial.print("Connected:");
// Begin synchronizing time
timer.setInterval(1000, CheckHeating); // check button state every second
rtc.begin(); //begin getting time-date
ClockSwitch = 0;
heatingcontrol = 0;
}
BLYNK_WRITE(5) {
powercut = 0;
Blynk.virtualWrite(5, LOW);
}
void CheckHeating() {
Seconds++;
if (powercut == 1) {
Blynk.virtualWrite(4, LOW);
Blynk.virtualWrite(5, HIGH);
Blynk.virtualWrite(0, LOW);
Blynk.virtualWrite(1, LOW);
}
if (digitalRead(Relay) == HIGH) {
led2.on();
led3.off();
}
else {
led2.off();
led3.on();
Blynk.virtualWrite(0, LOW);
Blynk.virtualWrite(1, LOW);
}
if (Seconds >= heatingtime && heatingcontrol == 0) { // Heating Off
digitalWrite(Relay, LOW); // relay off
heatingcontrol = 0;
}
if (ClockSwitch == 1) {
Serial.print(hour());
Serial.print(" ");
Serial.println(morninghourstart);
if (hour() == morninghourstart && minute() == morningminuetstart) { // time clock heating Morning
digitalWrite(Relay, HIGH);
heatingcontrol = 1;
}
else if (hour() == morninghourstop && minute() == morningminuetstop) {
digitalWrite(Relay, LOW);
heatingcontrol = 0;
}
if (hour() == eveninghourstart && minute() == eveningminuetstart) { // time clock heating Evening
digitalWrite(Relay, HIGH);
heatingcontrol = 1;
}
else if (hour() == eveninghourstop && minute() == eveningminuetstop) {
digitalWrite(Relay, LOW);
heatingcontrol = 0;
}
}
}
BLYNK_WRITE(0) { // One Hour
if (param.asInt()) {
digitalWrite(Relay, HIGH);
Blynk.virtualWrite(1, LOW);
Seconds = 0;
heatingtime = 3600;
} else {
digitalWrite(Relay, LOW);
}
}
BLYNK_WRITE(1) { // Two Hours
if (param.asInt()) {
digitalWrite(Relay, HIGH);
Blynk.virtualWrite(0, LOW);
Seconds = 0;
heatingtime = 7200;
} else {
digitalWrite(Relay, LOW);
}
}
BLYNK_WRITE(4) { // Clock Switch
if (param.asInt()) {
ClockSwitch = 1;
}
else {
ClockSwitch = 0;
}
}
BLYNK_WRITE(V6) { //Time Clock Morning
TimeInputParam t(param);
// Process start time
if (t.hasStartTime())
{
morninghourstart = t.getStartHour();
morningminuetstart = t.getStartMinute();
//t.getStartSecond());
}
else
{
// Do nothing
}
// Process stop time
if (t.hasStopTime())
{
morninghourstop = t.getStopHour();
morningminuetstop = t.getStopMinute();
//t.getStopSecond());
}
else
{
// Do nothing: no stop time was set
}
}
BLYNK_WRITE(V8) { //Time Clock Evening
TimeInputParam t(param);
// Process start time
if (t.hasStartTime())
{
eveninghourstart = t.getStartHour();
eveningminuetstart = t.getStartMinute();
//t.getStartSecond());
}
else
{
// Do nothing
}
// Process stop time
if (t.hasStopTime())
{
eveninghourstop = t.getStopHour();
eveningminuetstop = t.getStopMinute();
//t.getStopSecond());
}
else
{
// Do nothing: no stop time was set
}
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
timer.run();
}