-->
Page 1 of 2

ESP266 Relay Timer

PostPosted: Tue May 10, 2022 1:47 pm
by cmbk
hello. I am new to the community.
I have an ESP2866 + relay module, which I bought on Aliexpress, in order to place a timer on some electric stoves that I have in my house. The relay cuts off the flow of current to the stove after 40 minutes. It is something very simple.
Initially I did it through Blink to be able to control them over the internet, but after a while it was more useful and faster to just reset the ESP2866 using the reset button, since when resetting, the module connects to Wi-Fi again and reconnects the relay up to 40 minutes, so I hardly use the blynk app anymore.

The issue is that I want to unlink the modules from the internet, that is, since I am not using the blynk app, I do not need them to connect to wifi. I tried to do it by modifying the code they currently use, but it doesn't work for me. For some reason the ESP2866 doesn't do what I want if it's not connected to wifi.
This is the code I have

Code: Select all#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "XXXXXXXXXXXXXXXXXX";

char ssid[] = "XXXXX";
char pass[] = "XXXXXX";


const int buttonPin = 0;
int buttonState = 0;
unsigned long tiempo1 = 0;
unsigned long tiempo2 = 0;
unsigned long tiempoSegundos = 0;
int GPIO_0 = 0; //To control Device
int GPIO_0State; //State of device

void setup()
{
Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
GPIO_0State = digitalRead(GPIO_0); //State of device 2 (on/Off)
  if (GPIO_0State == 0) {
     tiempo2 = millis(); 
  }     else{
     tiempo1 = millis();
  }

   if  ((tiempo2 - tiempo1) > 2400000){ //40 minutos de uso
     digitalWrite(GPIO_0, HIGH);
   
    }
 Serial.println(tiempo1);
 Serial.println(tiempo2);
 Serial.println(GPIO_0State);
}



I have tried to eliminate everything related to blink but it does not work. What I need is that the module, after turning it on/reset it, connects the relay for 40 minutes and then turns it off. No internet, no wifi, nothing, just that.

Can the module work without Wi-Fi or does it need to be connected? I do not think so...
Can you help me please? THANKS!!

Re: ESP266 Relay Timer

PostPosted: Wed May 11, 2022 3:32 am
by QuickFix
The ESP is a MCU with a WiFi stack and hardware. If you don't need WiFi, you should pick an MCU without it, for instance an ATMEL and since you're using Arduino code, you should be able to flash your code (slightly modified) to an Arduino board (or one of the many clones). :idea:

Re: ESP266 Relay Timer

PostPosted: Wed May 11, 2022 4:05 pm
by btidey
You could certainly use an alternative non wifi module for this. A Digispark / Digistump module with an ATTiny85 would be quite a neat choice as being very small / low power and pretty easy to program over USB.

If you already have the esp8266 and want to continue to use it without wifi then just
WiFi.mode(WIFI_OFF);
in setup

Re: ESP266 Relay Timer

PostPosted: Thu May 12, 2022 9:54 am
by cmbk
Thanks for your reply

Yes, the idea of ​​using a nodemcu was to use it through the internet, but in daily use the simplest thing was to go to the stove and simply turn it on. I'm going to try WIFI OFF.