i’m making automatic feed for cats using nodemcu and servo, using blynk timer. but when the timer is running, the servo does not move. what is there anything missing with this program, because I am just learning
i am using the old version of blynk app. thanks in advance
#define BLYNK_AUTH_TOKEN "abE-9rDY3Yd1tP3YjptNucxPsLk5jVkT"
//Token dan SSID WiFi
char auth[] = "abE-9rDY3Yd1tP3YjptNucxPsLk5jVkT";
char ssid[] = "Redmi Note 9";
char pass[] = "12345678901";
//BLYNK
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//RTC
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
//SERVO
#include <Servo.h>
Servo servo;
int servo = 12;
/* 2- Display refresh*/
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
BLYNK_CONNECTED()
{ rtc.begin(); }
//-----------------------------------------------------------------------------------------------------------
void setup()
{
/* 0 - General */
Serial.begin(9600);
pinMode(2,OUTPUT);
/* 1- Blynk Server and Wifi Connection */
setSyncInterval(1);
Blynk.begin(auth,ssid,pass, "iot.serangkota.go.id", 8080);
while (Blynk.connect() == false ) {}
setSyncInterval(10*60);
/* 2- Display refresh*/
startMillis = millis();
//SERVO
servo.attach(D6);
servo.write(0);
}
BLYNK_WRITE(V4){
servo.write(param.asInt());
if (param.asInt()){
digitalWrite(12, HIGH);
Blynk.virtualWrite(V12,255);
Blynk.notify("Pakan diberikan");
} else {
digitalWrite(12, LOW);
Blynk.virtualWrite(V12,0);
Blynk.notify("pemberian pakan selesai");
}
}
BLYNK_WRITE(V5){
if (param.asInt()){
digitalWrite(12, HIGH);
Blynk.virtualWrite(V12,255);
Blynk.notify("Pakan diberikan");
} else {
digitalWrite(12, LOW);
Blynk.virtualWrite(V12,0);
Blynk.notify("pemberian pakan selesai");
}
}
BLYNK_WRITE(V6){
if (param.asInt()){
digitalWrite(12, HIGH);
Blynk.virtualWrite(V12,255);
Blynk.notify("Pakan diberikan");
} else {
digitalWrite(12, LOW);
Blynk.virtualWrite(V12,0);
Blynk.notify("pemberian pakan selesai");
}
}
//-------------------------------------------------------------------------------------
void loop(){
/* 1- Blynk Server and Wifi Connection */
Blynk.run();
timer.run();
/* 2- Display refresh*/
currentMillis = millis();
if(currentMillis - startMillis > period)
{
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V1, currentTime);
Blynk.virtualWrite(V2, currentDate);
int getSecond = second();
if (getSecond > 30)
{ digitalWrite(2,HIGH);} /* Turn OFF the LED if seconds count is more than 30 */
if (getSecond < 30)
{ digitalWrite(2,LOW); } /* Turn ON the LED if the seconds count is less than 30 */
startMillis = millis(); /* Reset time for the next counting cycle */
}
}