@PeteKnight @John93 Can I know why both of you comment this line?
//SoftwareSerial EspSerial(2, 3); // RX, TX
@PeteKnight @John93 Can I know why both of you comment this line?
//SoftwareSerial EspSerial(2, 3); // RX, TX
@John93 when I tried to run yours code. It seems they get the same result with @PeteKnight one.
Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"
From_Community:30:15: error: 'EspSerial' was not declared in this scope
ESP8266 wifi(&EspSerial);
^~~~~~~~~
C:\Users\user\Documents\Arduino\From_Community\From_Community.ino:30:15: note: suggested alternative: 'Serial'
ESP8266 wifi(&EspSerial);
^~~~~~~~~
Serial
C:\Users\user\Documents\Arduino\From_Community\From_Community.ino: In function 'void setup()':
From_Community:66:3: error: 'EspSerial' was not declared in this scope
EspSerial.begin(ESP8266_BAUD);
^~~~~~~~~
C:\Users\user\Documents\Arduino\From_Community\From_Community.ino:66:3: note: suggested alternative: 'Serial'
EspSerial.begin(ESP8266_BAUD);
^~~~~~~~~
Serial
Multiple libraries were found for "DHT.h"
Used: C:\Users\user\Documents\Arduino\libraries\DHT_sensor_library
Not used: C:\Users\user\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
exit status 1
'EspSerial' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Itâs a standard Arduino + ESP-01 sketch designed to be used with a variety of Arduino boards.
The Mega has multiple hardware serial ports, the Uno has just one. So, the Mega doesnât need to use SoftwareSerial, because the ESP-01 can be connected to Serial 1. To use the sketch with an Uno the Mega option has to be commented out, and the SoftwareSerial option has to be un-commented.
Itâs all explained in the comments, you just have to read themâŚ
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
You also have to connect the ESP-01 to pins 2 & 3, or amend the SoftwareSerial command to use the pins that you have your ESP-01 attached to.
The more I read this topic, the more I think that you are wasting your time with this hardware setupâŚ
Pete.
If youâre going to ignore the advice that people are giving you, and use a sketch which doesnât actually do anything - which I assume youâve found somewhere rather than written yourself from scratch - then Iâm going to allocate my time to supporting Blynk users who actually want my input.
Good luck with your project!
Pete.
@PeteKnight I am so sorry for my speech. After following your advice, I think my connectivity become very stable. Now I am moving forward to use the virtual pin to control my motor/led. Thank you. I think the problem of ESP not responding is the baud rate. I changed my baud rate to 9600 yesterday. After i changed it to 9600 with your code. It works fine with any disconnect.
@PeteKnight I still have something that i dont understand about your code.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
what is this 2 line doing actually??
I know you are writing h & t to Blynk with vitual pin 5&6. What if I only want v0 to control the fan?
I followed your advice before about vitual pin and added the following code.
void Fan_on() {
digitalWrite(8, HIGH); // Set digital pin 8 HIGH
}
void Fan_off() {
digitalWrite(8, LOW); // Set digital pin 8 LOW
}
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
Fan_on();
}
else
{
// execute this code if the switch widget is now OFF
Fan_off();
}
}
and 1 more sentense in setup
pinMode(8, OUTPUT)
Am I doing correct??
There are some strange things happening. I successful connect to the server and can control with a virtual pin(just dont know why can only on but cant off). However, when I tried to reupload the code to UNO. It said ESP is not respondingâŚon the serial monitor. Then I am not able to reconnect it againâŚ
This is solved when I restart the computer⌠and the swith in blynk can now control it.
Iâm so glad your problem has been solved.
just one more problem, can I show the dht result on the label of Blynk?? If yes, is it based on this 2 code??
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
then why my label always showing 1âŚ
Show me a screenshot please
it keep showing this on serial monitor
16:07:31.812 -> 43.70
16:07:31.812 -> 22.10
16:07:32.837 -> 43.60
16:07:32.837 -> 22.10
but in blynk
How did you configure your datastream ?
I am not sure what are you talking about. Sorry my English is not that good. I am trying to display that 2 data on 2 label. they are captured by dst22.
it seems I am missing sth like this??
BLYNK_READ(V5) //Blynk app has something on V5
{
sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}
therefore I changed my code to this
#define BLYNK_TEMPLATE_ID "TMPL5vzGTnYc"
#define BLYNK_DEVICE_NAME "DHT22"
#define BLYNK_AUTH_TOKEN "";
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "GoCO";
char pass[] = "2982";
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600 //I have changed the baud rate of my 8266 to 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 10 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void Fan_on() {
digitalWrite(8, HIGH); // Set digital pin 8 HIGH
}
void Fan_off() {
digitalWrite(8, LOW); // Set digital pin 8 LOW
}
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
if (param.asInt() == 1)
{
// execute this code if the switch widget is now ON
Fan_on();
}
else if (param.asInt() == 0)
{
// execute this code if the switch widget is now OFF
Fan_off();
}
}
// 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.
Serial.println(h);
Serial.println(t);
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
BLYNK_READ(V5);
{
float h = dht.readHumidity();
Blynk.virtualWrite(V5, h);
}
BLYNK_READ(V6);
{
float t = dht.readTemperature();
Blynk.virtualWrite(V6, t);
}
void setup()
{
pinMode(8, OUTPUT);
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
No, you donât need to add those, you already did
In the void sendsensor
Go to datastream and Show me a screenshot please
Itâs okay, you should be able to get the data.
Try the app