Code don't work on ESP8266 e01

Hello,
I’ve got a problem with my project. I have written a code (see below), it works without problems on the Wemos R1 mini. But when I load the sketch on the ESP8266 e01 it doesn’t work.

I can upload the sketch without any problems and the IDE says every thing is fine.
The ESP is connected to my Lab Bench power supply, so it has enough power (current), but it only takes 30 to 50 mA

Could it be the dalay() function? But why it works on the Wemos R1?

Could anybody please help?

#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[] = "my key";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my Wifi";
char pass[] = "*************";

int Sensor = 2;
int Status = 0;
int Validierung = 0;

void setup()
{
  pinMode(Sensor, INPUT);
  
  Serial.begin(9600);
  
  Blynk.begin(auth, ssid, pass);

  Blynk.run();

}

void loop()
{
  Status = digitalRead(Sensor);
  Serial.print(Status);

  
  if(Status == HIGH)
  {
    Validierung = Validierung + 1;
    delay(1000);
  }
  
  if(Status == HIGH)
  {
    Validierung = Validierung + 1;
  }

  if(Validierung == 2)
  {
    Serial.print("Feuer");
    Blynk.notify("Feuer");
  }
  

  Serial.print("Deep Sleep");
  ESP.deepSleep(0);

  
}

What doesn’t work?

Can you use that function directly with the ESP-01? I guess you can’t without hacking the ESP…

On the other side, your Loop looks bad to do it work with Blynk.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Modifying an ESP-01 to deep sleep takes a steady hand with the soldering iron. Are you sure that when you soldered the wire on to the GPIO16 pin of the ESP chip you didn’t kill it?

By the way, you you should edit your post (using the pencil icon at the bottom) and add back-ticks to our code so that it displays correctly.
Blynk%20-%20FTFC

Pete.

I fixed the code formatting already… and was about to mention possible sleep issues with the ESP-01… :stuck_out_tongue_winking_eye:

Bad coding practice with the delay()… but that has also been mentioned (although I guess since it is supposed to sleep, thus loose connection anyhow… :thinking: )

Duplicated if() ??

And no Blynk.run() in loop… so if it is waiting for sensor, it would loose connection even if no delay()

1 Like

Hello everybody,
You are right, you need some more informations :slight_smile:

The esp8266 e01, does not display anything readable over the serial monitor, like the wemos did. If you need pictures I will upload them.

I want to use it as a fire alarm modul. If the the fire sensor detect smoke the signal on pin (2) is pulled high. The reason for the two if() functions is that, when the battery get empty the pin is also pulled high but not for the hole time. It is only pulled high in intervals. The two if stages should work as an control. But you are right I could pack this in a void detect() function.

About the deep sleep function:I want that the esp8266 is in constant deep sleep until a reset. So the question is, do I need a connection from pin 16 to reset? because I take the reset signal from the fire sensor.

Okay I will search for another solution for the delay function.

But why does the code not work on the ESP8266 e01?

Sorry for the wrong displaying of the code.

Thank for the help

BlynkTimer… you can do some neat things with timeout timers…

ESP-01 and ESP8266 are slightly different boards… and the ESP-01 in particular is really persnickety about the state of its few available pins at boot… well more like “this is all you gots… but don’t do this, or this, or this…” :stuck_out_tongue:

I think you are almost better off looking for an ESP8266 SMT for low power application… low current needs, more pins.

Have you looked at this:

Pete.