Esp01 relay is powered on after reboot

Hi I’ve been trying to figure out how to fix a problem. I’m a noob and I’m working on a simple project to turn a relay on and off with a esp01 relay and a simple button in the blynk app. The sketch for the esp01 is the stock blynk example and it works great but upon power up the relay turns on and stays on until I hit the push button one time and then it works correctly. Push the on pushbutton the relay turns on and vice versa. I would like to use this with a program I modified for a arduino nano to water my plants.I’m using gpio0 for the relay trigger. Momentarily turn on for 2 seconds then off until I trigger next event. I would prefer to use the NO contact as a safety measure in case the relay goes bad but if there’s a power outage the relay will remain on until I discover a gallon of water on the floor. I’m pretty sure I’m current on the version of blynk
I’m using iPhone 7 with latest OS
I’m using ai thinker esp01 board
The relay board has a larger regulator chip on it
I have great power to board
I’m using a stock example from blynk application
I’ve been chasing around the Internet all night.
Please forgive me for rambling on here but I’m new and I’m asking if someone can point me in right direction.


void loop()

Post your sketch and we’ll have a look.

Basically in setup() you need to be setting your relay pin to the state that you want (HIGH or LOW depending on how you are using it.)

You cold also use Blynk.syncAll() to sync the relay pin to the same state as the Blynk button widget.

cul
billd

Hi thank you for the quick reply. I’ll have to read up so I can post what info you’ve requested. Morning in this household is a bit crazy. Thank you for your hard work!

hopefully i read this correctly
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest

Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.

Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator:           http://examples.blynk.cc
Blynk community:            http://community.blynk.cc
Follow us:                  http://www.fb.com/blynkapp
                            http://twitter.com/blynk_app

Blynk library is licensed under MIT license
This example code is in public domain.


This example runs directly on ESP8266 chip.

Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino

Please be sure to select the right ESP8266 module
in the Tools -> Board menu!

Change WiFi ssid, pass, and Blynk auth token to run :slight_smile:
Feel free to apply it to any other example. It’s simple!
*************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
 

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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "-GHY-3cpgOZ8i";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "2"; 
char pass[] = "7";

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

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

@jmartens2 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

sorry i learned something new. i never knew what a backtick was.lol
thank you

I’m guessing that you didn’t understand what @Bill_Donnelly said, and that you haven’t read/understood the link that you were given?

Pete.

im currently reading up on the syncall command. and i dont have the sketch i used for the nano to control the relays. i was going to experiment with setting the bit hi in the sketch.
i must admit i also need to read up a lot more on blynk coding. i see there a ton of new stuff added at the github page. its been a while since i last visited
thank you

All the information you require is in the link that was provided, including the two lines of code that you can copy/paste.

Pete.

hi, ive been caught in a vortex of info. everything points to a virtual pin being updated/synced.
im using gp0 to turn the relay on and off. so i figure the sync command will not work. im currently trying to work this out. either i figure out how to trigger relay with virtual pin in e4sp01 blynk app or i need to work in my nano sketch. thank you for your help!! im trying hard

You figure incorrectly.

All you have to do is read the link that was provided…

All analog/digital/virtual pin values and states will be set to the latest stored value

Pete.

this is what ive tried…

#define BLYNK_PRINT Serial


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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Y-3cpgOZ8i";

// This function will run every time Blynk connection is established
  BLYNK_CONNECTED() {
  // Request Blynk server to re-send latest values for all pins
  Blynk.syncAll();
  }

  // Your WiFi credentials.
  // Set password to "" for open networks.
  char ssid[] = "2";
  char pass[] = "7";


  void setup()
  {
    // Debug console
    Serial.begin(9600);

    Blynk.begin(auth, ssid, pass);

  }
ive tried leaving the widget off
ive tried the widget on 
ive inverted the 1 on pushbutton to 0 and back but all that happens is as soon as it connects it turns the relay on (led is lit and relay NO is closed) and i have to toggle blynk pushbutton to get relay to correct state.im beginning to wonder if theres a hardware problem at bootup thats causing this problemn. thank you so much for your patience. 


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

Well, as @Bill_Donnelly said, if you always want your device to start-up with the relay off, regardless of what is set in the app, then you should do this in your void setup.
You’ll need a pinMode declaration for whichever oin you are using, and a digitalWrite to set that pin to the desired state (HIGH or LOW).

Pete.

this seems to work for bootup…

[Unformatted code removed by moderator]

but now the timer in app will turn on at start time but will not turn off after 2 second stop time.
is there a limit of time needed to update the stop time?
thank you for being so patient, i havent been helped like this in other forums.

hi, ive added another timer after the first (start)timer and the toggle causes the first (start)timer to shut off. things are a bit weird. there must be some kind of time issue. im going to continue to work at it later

I’m not going to keep repeating the triple backtick thing. Your unformatted code has been removed.

Pete.

i must apologize. in my over zealous attempt in trying to work this problem out ive forgotten my manners. please forgive me.

in case anyone might have same problem, the timer needs at least 20 to 30 seconds of time between on and off commands. then timer acts correctly

Hello friend @jmartens2 , I would like to carry out the same project as you for irrigation. I hardly know about code, what little I do I get based on a lot of trying and many tests. Could you pass me your code to make my modifications regarding my internet and the times? I would appreciate. All the best.

Hi friend. I would love to help you. I think I could do that for you but I’m not sure of the rules here. Give me some time to read the rules on this forum. If I can post it here I will. Are you sure that you understand I have 2 programs here that work two different boards? I use the blynk app to trigger the event each day.
That may not make a lot of sense but I’m a noob also.but I will try to answer your questions.