I’m new with arduino but I have have made a fish feed machine running a sequence of opening a door first and then running a snail and then closing it again.
I can start it with a push button and with a time input from the blynk app.
It seems fine, but once it has run the first loop of the sequence.
The connection is lost and continues to write
[177810] Connecting to blynk-cloud.com:8442 in the serial monitor.
Is there anyone who has encountered that problem?
My code is here.
/*
Name: Koifeeder1.ino
Created: 12/26/2017 7:05:09 PM
Author: Lars
*/
// Reference URL for L298N https://forum.arduino.cc/index.php?action=dlattach;topic=366727.0;attach=147606
// Ethernet opkobling
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define W5100_CS 10
#define SDCARD_CS 4
// DS3231 RTC Modul clock
#include <DS3231.h> //RTC MODUL DS3231
DS3231 rtc(SDA, SCL); // UR RTC DS3231 pin SDA, SCL
// Kode til Blynk
char auth[] = “d462d305896044b0b7f01394ff7693a6”;
// UR og instillinger af tider
String timeSet; // Indstilling af Ur på App
String feeding1Start; // start tid af fodring 1 tid på App
String feeding1Stop; // stop tid af fodring 1 tid på App
String DS3231RTC;// Aktuelle tid på DS3231 modul
// Snegl motor
#define in1 8 // Pin 8 = Snegl motor output 1
#define in2 9 // Pin 9 = Snegl motor output 2
#define enA 10 // Pin 10 = snegl hastighed
// Door motor
#define in3 4 // Pin 4 = Door motor output 1
#define in4 3 // Pin 3 = Door motor output 2
#define enB 2 // Pin 2 = Door hastighed
// sensors og buttons
const int SwicthOpen = 7; // Pin 7 = Swicht door open
const int SwicthClosed = 6; // Pin 6 = Swicht door closed
const int buttonPin = 5; // Pin 5 = knappen
// Global variabler
int DoorOpen = 0; // variable for dør åben
int DoorClosed = 0; // variable for dør lukket
int buttonState = 0; // Start knap
int feeding = 3; // Hvor mange fodringer pr gang
int startAuger = 0; // Starter Auger loop
float SPEED = 250; // Hastigheden på motorne
int aut;
void setup() {
Serial.begin(9600);
// Motor Snegl
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enA, OUTPUT);
// Motor Door
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(SwicthOpen, INPUT); // Swicth open door
pinMode(SwicthClosed, INPUT); // Swicth closed door
pinMode(buttonPin, INPUT); // Button
// DC3231 RTC Clock
rtc.begin(); // STARTER UR
Blynk.begin(auth);
}
void loop()
{
// Flyt tid fra rtc.getTimeStr til DS3231RTC
DS3231RTC = String(rtc.getTimeStr());
delay(1000);
buttonState = digitalRead(buttonPin); // Er Button trykket på ?
DoorClosed = digitalRead(SwicthClosed); // Er døren lukket ?
DoorOpen = digitalRead(SwicthOpen); // Er Døren åben ?
Blynk.virtualWrite(V4, DS3231RTC);
//Hvis dør er lukket og Button er trykket eller AUT er on!
if (DoorClosed == HIGH && buttonState == HIGH || feeding1Start <= DS3231RTC && feeding1Stop >= DS3231RTC)
{
startAuger = doorOpen();
}
// Hvis dør er åben og startAguer == 1 start snegl
else if (DoorOpen == HIGH && startAuger == 1)
{
auger();
startAuger = 0;
}
// Hvis døren er lukket og åben så skal den lukke døren
else if (DoorClosed == LOW && startAuger == 0)
{
doorClose();
}
else {
//gør ingen ting
}
DS3231rtc();
Blynk.run();
}
int doorOpen()
{
while (DoorOpen == LOW)
{
DoorOpen = digitalRead(SwicthOpen); // Er Døren åben ?
// Kør dør op
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB, SPEED);
}
// sluk for motor
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
return 1;
}
void auger()
{
for (int i = 0; i < feeding; i++)
{
// kør sneglen frem
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, SPEED);
delay(1000); // Vent 500 msek
// kør sneglen tilbage
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, SPEED);
delay(500); // Vent 500 msek
}
// stop snegl
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
Blynk.run();
}
void doorClose()
{
while (DoorClosed == LOW)
{
DoorClosed = digitalRead(SwicthClosed);
// kør dør ned
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enA, SPEED);
}
// sluk for motor
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
Blynk.run();
}
void DS3231rtc()
{
// Flyt tid fra rtc.getTimeStr til DS3231RTC
DS3231RTC = String(rtc.getTimeStr());
delay(1000);
Blynk.run();
}
// Indstilling af UR på Iphone app
BLYNK_WRITE(V5)
{
TimeInputParam t(param);
if (t.hasStartTime())
{
timeSet = String( t.getStartHour()) + “:” + t.getStartMinute() + “:” + t.getStartSecond();
Serial.print(timeSet);
rtc.setTime((t.getStartHour()), (t.getStartMinute()), (t.getStartSecond())); // Sender RTC time fra DS3231 til Iphone App
{
}
}
Blynk.run();
}
// Indstilling af fodring 1 på Iphone app
BLYNK_WRITE(V6) {
TimeInputParam t(param);
feeding1Stop = String( t.getStartHour()) + “:” + t.getStartMinute() + “:” + t.getStartSecond()+1;
Serial.print(" Stop: ");
Serial.print(feeding1Stop);
if (t.hasStartTime())
{
feeding1Start = String( t.getStartHour()) + “:” + t.getStartMinute() + “:” + t.getStartSecond();
Serial.print(" Start: ");
Serial.print( feeding1Start);
}
Blynk.run();
}