ESP8266 not responding with arduino uno

I need help with esp8266, I’m using arduino uno with esp8266 and in the starting it was working like a charm then suddenly esp was lagging. Lagging means wasnt connecting and was just showing red led not both the red and blue. Im using hardware serial. Please help me with it. Sometiimes esp connects sometimes it doesnt connect and I’ve to do hard work to get it connected.
my connection is in the picture.
start_arduino_esp_cloud_scheme

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
char auth[] = "43a95706bee04ff78250212ce9f755cc";

char ssid[] = "TVARS";
char pass[] = "time1234";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

//#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
#define rpwr 12
#define high 11
#define DHTPIN 2          // What digital pin we're connected to

#define DHTTYPE DHT11     // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

int Sensorvalue = 0;
int sensorPin = A0;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void getSoilMoistureData()

{
  Sensorvalue = analogRead(A0);
  Sensorvalue = map(Sensorvalue, 0, 1023, 1023, 0);
  Blynk.virtualWrite(V7, Sensorvalue);
  Serial.print("Sensor Val: ");
  Serial.println(Sensorvalue);
  
}


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

  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);
  
  pinMode(rpwr, OUTPUT);
  digitalWrite(rpwr, HIGH);
  pinMode(high, OUTPUT);
  digitalWrite(high, HIGH);
 
  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);
  
  dht.begin();
  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
  timer.setInterval(1000L, getSoilMoistureData);
  }

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

You are using one serial port for both hardware and debugging output, this is never going to work. Use softserial for one of them …

It used to work before. Im new to this thing can you please be more specific about what you said?

You need this: https://examples.blynk.cc/?board=Arduino%20Uno&shield=SoftwareSerial&example=GettingStarted%2FBlynkBlink example.

Mind you, you have to set the ESP to 9600 Baud (or use the SwSerial port for Blynk debugging output).

I’d highly recommend ditching the Arduino and just use the ESP for all your things, something like the Wemos D1 Mini. So much easier…

So by this my rx and tx will change right? from 0,1 to 10,11?

and can you check in the picture given that Im using voltage divider at 3.3 of arduino is that okay?

Yes, what @Lichtsignaal said. Throw away the Arduino and upload your code straight to the ESP8266. Better still, buy a NodeMCU or Wemos D1 Mini so that you have more pins to work with in an easily accessible package.

Pete.

And then how will I get my output on blynk app then?as there is no connectivity as you removed the esp connection?

I cant do this, as this is one of my college project which im working on and i’ve already given them the synopsys that im usiing an arduino.
So plz suggest about uno and esp only as the rest is no option.

That’s the joy of using an Arduino for an iOT project. Shop around and plug and play hardware exists for $3.

But I purchased a new esp and it is not connecting from the start only.

But why the ESP01 for $2 when a real ESP with analogue port, usb connector and additional pins is available for $3?

I will paraphrase the docs “don’t use ESP’s as a shield unless you are sadomasochist”.

but i’ve to make an IoT project so i have to use it as a shield only na?

You can use a decent ESP as a shield but ESP’s are better as standalone MCU’s.

Use SoftwareSerial @ 9600 BAUD to connect your UNO to your ESP… pins 2 & 3 (or 10 & 11) should work fine for that.

// Load SoftwareSerial Library
#include <SoftwareSerial.h>

 // Set RX, TX pins for ESP connection
SoftwareSerial EspSerial(2, 3);

// Direct ESP connection to SoftwareSerial port
ESP8266 wifi(&EspSerial);

// Set ESP8266 baud rate
EspSerial.begin(9600);

Then your UNO will connect via the ESP through to the Blynk Server just fine. This leaves your “normal” hardware Serial port for programming and debug.

1 Like

This is why government IT projects drag on for years and cost $$$$ then eventually get scrapped.
Acknowledge the fact that your initial synopsis was flawed, and/or that technological developments and cost-saving considerations have lead you to re-evaluate the solution and throw away the unnecessary and costly Arduino hardware.
The ESP/NodeMCU will run the same code as the Arduino, so you’re still using an Arduino compatible device which is written, debugged, edited and uploaded via the Arduino IDE, so you’re not straying very far from the initial spec.

Pete.

1 Like