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.
#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();
}
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.
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.
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.
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.