Why my ESP 8266 cant turn on. what wrong with my coding. please help for my final project

// Blynk IOT Smart Agriculture Monitoring System
#define BLYNK_TEMPLATE_ID "TMPL6VFSTCsyx"
#define BLYNK_TEMPLATE_NAME "smart Irrigation System"
#define BLYNK_AUTH_TOKEN "tCKsEYb0Ho2kJecZhxxxxxxxx"
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>  // Including library for dht

char auth[] = "tCKsEYxxxxxxxxxx";     //Authentication code sent by Blynk
char ssid[] = "UNxxxGON";                        //WiFi SSID
char pass[] = "unoxxxxaee";                //WiFi Password

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN D4          //pin where the dht11 is connected
DHT dht(DHTPIN, DHT22);
#define ONE_WIRE_BUS D6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define buzzer D5 //Buzzer Pin D5 
#define rainPin D7
int rainState = 0;
int lastRainState = 0;
const int AirValue = 590;   //you need to replace this value with Value_1
const int WaterValue = 300;  //you need to replace this value with Value_2
const int SensorPin = A0;
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
int relay = D0;


#define pirPin D3
int pirValue;
int pinValue;

//Read value from blynk
BLYNK_WRITE(V0)
{
  pinValue = param.asInt();
}



void setup()
{
  Serial.begin(115200);
  delay(100);
  Blynk.begin(auth, ssid, pass);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  sensors.begin(); // Dallas temperature
  dht.begin();
}

void getPirValue(void)        //Get PIR Data
{
  pirValue = digitalRead(pirPin);
  if (pirValue)
  {
    Serial.println("Motion detected");
    Blynk.logEvent("Motion detected in your farm") ;
  }
}

void loop() {
  Blynk.run();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);

  Serial.print("Soil Temperature: ");
  Serial.println(temp);
  Serial.print("Temperature: ");
  Serial.println(t);
  Serial.print("Humidity: ");
  Serial.println(h);

  Blynk.virtualWrite(V3, t);  //V3 is for Temperature
  Blynk.virtualWrite(V4, h);  //V4 is for Humidity
  Blynk.virtualWrite(V2, temp); //Dallas Temperature

  soilMoistureValue = analogRead(SensorPin);  //put Sensor insert into soil
  Serial.println(soilMoistureValue);

  soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);

  Blynk.virtualWrite(V1, soilmoisturepercent); //Soil Moisture sensor

  if (soilmoisturepercent > 100)
  {
    Serial.println("100 %");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print("100");
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  else if (soilmoisturepercent < 0)
  {
    Serial.println("0 %");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print("0");
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  else if (soilmoisturepercent >= 0 && soilmoisturepercent <= 100)
  {
    Serial.print(soilmoisturepercent);
    Serial.println("%");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print(soilmoisturepercent);
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  if (soilmoisturepercent >= 0 && soilmoisturepercent <= 30)
  {
    Serial.println("needs water, send notification");
    //send notification
    Blynk.logEvent("Plants need water... Pump is activated") ;
    digitalWrite(relay, LOW);
    digitalWrite(buzzer, HIGH);
    Serial.println("Motor is ON");
    WidgetLED PumpLed(V5);
    PumpLed.on();
    delay(1000);
  }
  else if (soilmoisturepercent > 30 && soilmoisturepercent <= 100)
  {
    Serial.println("Soil Moisture level looks good...");
    digitalWrite(relay, HIGH);
    digitalWrite(buzzer, LOW);
    Serial.println("Motor is OFF");
    WidgetLED PumpLed(V5);
    PumpLed.off();
    delay(1000);
  }

  rainState = digitalRead(rainPin);
  Serial.println(rainState);

  if (rainState == 0 && lastRainState == 0) {
    Serial.println("It's Raining outside!");
    Blynk.logEvent("It's Raining outside!") ;
    lastRainState = 1;
    delay(1000);
    //send notification

  }
  else if (rainState == 0 && lastRainState == 1) {
    delay(1000);
  }
  else {
    Serial.println("No Rains...");
    lastRainState = 0;
    delay(1000);
  }

  if (pinValue == HIGH)
  {
    getPirValue();
  }
  delay(100);
}

Please explain further.

If your board will not switch on, it cannot run any code. You will not be able to upload your code to it. Changing the code won't make any difference.

Also please post a link to the specs of the board you are attempting to use. Your title says "ESP8266" but there are many board designs that feature ESP8266.

Even more confusingly, you have posted your topic in the "Nano ESP32" forum section. The Nano ESP32 is not an ESP8266 board.

The ESP8266 has certain pins that must be in a particular state (high or low) at power up otherwise it won't start. I am away from my computer, using a mobile phone, at the moment so it's a pain to search for a reference for you. Search for a guide to using the ESP8266, especially look for a table that shows which pins can be used for what purpose.

Hi, @kevin2319
Welcome to the forum.

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Indeed.
On quick inspection:
D0 is not really suitable for a relay because it will be high at boot time. You may not want the relay chattering on start up.
D3 is not suitable for a PIR because, if at boot time the PIR is not detecting anything and thus pulling the pin low, then the boot will fail.
D4 may be unsuitable for a DHT device because the pin must be pulled high at boot time.

Look here for suitable pins and remember that the GPIO number is not the same as the D number: ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

I moved your topic to a more appropriate forum category @kevin2319.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

hello thank you for the answer, sorry for the category because option in the category for esp 8266 not available so i choice for esp 32

maybe if i use ESP 32 for my program , can anyone help to write new coding because i cant understand about the coding its for my task.
Automatic plant irrigation and watering system project It has 5 sensors (soil moisture sensor, pear sensor, rain sensor, dht 22, ds18b20) 1 lcd OLED display 0.96 inch, buzzer, push button, 4 gnd, esp 32, SD card, mini pump motor, single channel relay module, resistor 4.75 k ohm Principle of operation: Dht 22 (room temper ) Rain sensor (to detect rain) DHT 22 (moisture of air) Capasitive soil (measuring soil water content) Ds 18b20 (measured water level) pir (detection of plant movement when there is disturbance) DS18B20 (mengukur suhu tanah)

thank you everyone, i hope you can help me

You're going to have to tell us a lot more about exactly what the problem you're having is before anyone can begin to venture a guess as to what might be going wrong.

To begin with, what do you mean by "my ESP 8266 can't turn on"?

Is the power shorting out? Do you have a power LED that's not coming on?

Or do you mean that your program isn't running? If so, what debugging have you done? I don't see any Serial.print(...) stuff in setup to let you know how far you're getting. Why is that? And why aren't you checking any of the possible return values from the various .begin calls you're making in setup? That could really narrow down where things are going wrong.

Please keep in mind that no one can see what you are seeing in front of you; and none of us can read minds. We only know what you show us and tell us. And so far, the only thing you've told us is that it doesn't work. Which is not helpful in any way, shape or form in moving towards a resolution of your problem(s).

A schematic diagram would also go a long way towards helping us understand what's going on. Even a photo of a pen and paper schematic would be helpful.

sorry, because i copy,paste from internet . sorry for misundertand.

yes, for the coding its running and not error. but when program upload to esp 8266, the ESP not turn on even LED cant turn on

i use ESP 32 for my program , can anyone help to write new coding and schematic because i cant understand about the coding its for my task.
Automatic plant irrigation and watering system project It has 5 sensors (soil moisture sensor, pear sensor, rain sensor, dht 22, ds18b20) 1 lcd OLED display 0.96 inch, buzzer, push button, 4 gnd, esp 32, SD card, mini pump motor, single channel relay module, resistor 4.75 k ohm Principle of operation: Dht 22 (room temper ) Rain sensor (to detect rain) DHT 22 (moisture of air) Capasitive soil (measuring soil water content) Ds 18b20 (measured water level) pir (detection of plant movement when there is disturbance) DS18B20 (measure soil temperature)

What have you done to prepare to do this project. It looks like you purchased a bunch of parts and need a project to use them. Post your rough schematic and code. Also post links to technical information on each of the hardware items. Links from Azon and Aliexpress are normally just sales info. What background do you have in electronics and programming? Is this your first project? I highly recommend you get a copy of the Arduino Cookbook and skim it from cover to cover then read the sections that apply to the parts you have.

So by "help" do you mean write it for you?

Is this task a class assignment or project to advance you academically?

Check the international section of the forum. Perhaps there is a language you know in which you can express yourself with more clarity. Good luck with your project.

@kevin2319

you cannot expect people in this forum to make your school project.
please go to google, search for something like "plant watering system with sensors based on esp32" and you'll find a ton of projects

good luck

I have merged your topics due to them having too much overlap on the same subject matter @kevin2319.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

sorry everyone for this. i create this prorgam and can run but the oled not turn. maybe anyone can help fix this problem.


this is the schematic