Text Input widget as an event trigger

I’m trying to create an application that open and close the servos automatically when the date/time/motor i wanted to rotate from the input text widget is the same as the time from the RTC. I want it to rotates servo to 90 degree and stays there for 2 seconds before rotates back to 0 degree. I have 2 motors so there will be 3 cases (motor no.1/2 or both). But when i tried, when the date/time is correct the servo turns to 90 degree but its not turning back. I changed the code to millis() but also yield the same result. Is it something wrong with my code? or is there any better widget to use in the iOS?

I’m using WEMOS D1 R2, IDE 1.8.6, Blynk application in the iOS.

Thanks in advance.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h> //WIFI 

#include <TimeLib.h> 

#include <DS1302.h> // RTC module

DS1302 rtc(16,5,4); // gpio pin 16,5,4 (D2, 3, 4) (RST DAT CLK) 

#include <Blynk.h>
#include <Servo.h> 

char auth[] = "xxx";
char ssid[] = "yyy";
char pass[] = "zzz";
String datetext = ""; 
String timetext = ""; 
String inputMotor = "";                                                                                                                                    

Servo servo_1;
Servo servo_2;
BlynkTimer timer;

                                                       

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  servo_1.attach(13); //D7
  servo_2.attach(2); //D8 
}

void inputCheck() {  
  String rtcDate = rtc.getDateStr(); // get date from rtc
  rtcDate.trim();
  String rtcTime = rtc.getTimeStr(); // get time from rtc
  rtcTime.trim();

if (datetext == rtcDate && timetext == rtcTime && inputMotor == "1") { 
    servo_1.write(90);
    timer.setTimeout(2000L, Servo1zero); }   
          //servo 1 to 0 in 2 seconds
else if (datetext == rtcDate && timetext == rtcTime && inputMotor == "2") {
      servo_2.write(90);
      timer.setTimeout(2000L, Servo2zero); }
else if (datetext == rtcDate && timetext == rtcTime && inputMotor == "B") {
      servo_1.write(90);
      timer.setTimeout(2000L, Servo1zero);
      timer.setTimeout(500L, Servo2ninety);
      timer.setTimeout(2000L, Servo2zero); }        
    
}

void Servo1zero() {
      servo_1.write(0); } 

void Servo1ninety() {
      servo_1.write(90); }

void Servo2zero() {
      servo_2.write(0); } 

void Servo2ninety() {
      servo_2.write(90); }

void loop() {
  Blynk.run();
  timer.run();
  inputCheck();
}

BLYNK_WRITE(V4) { //text input from blynk
   datetext = param.asStr(); // get date from blynk text input in the format "DD.MM.YYYY"
  
}

BLYNK_WRITE(V5) {
  timetext = param.asStr(); // get time from blynk text input in the format "HH:MM:SS"
}

BLYNK_WRITE(V6) {
   inputMotor = param.asStr(); // get motor no. to rotate from blynk text input in the format "1", "2" or "B" for both
}

Not sure but you’re missing a } in your setup as inputCheck should be out of it

1 Like

you are right @ldb
Left bracket is missing

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  servo_1.attach(13); //D7
  servo_2.attach(2); //D8
} //<===

ah i forgot to add it in the post sorry :smile:

very intersting, can you post your blynk aplication qr code?