Im having problem with my esp8266 and my arduino. My project is gas sensor using arduino uno and when it detect gas it will produce alarm, and led will turn on also will send noti to blynk. Everything works fine before i adding blynk coding to my arduino. When i put esp8266 blynk coding, all of this doesnt work . when i upload the coding , it doesnt show any error. The output of serial monitor is esp8266 is not responding , can u help me, this is my coding
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2,3); // RX, TX
const int gasPin=A0;
int gasValue=0;
const int buzpin=11;
const int threshold=100;
const int ledPin=13;
char auth[] = "497b411df81c4be184a6b8478d0e7218";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "babablacksheep";
char pass[] = "taikmu123";
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
void setup()
{
Serial.begin(9600);
pinMode (gasPin,INPUT);
pinMode (buzpin,OUTPUT);
pinMode (ledPin, OUTPUT);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
gasValue=analogRead(gasPin);
Serial.println(gasValue);
if (gasValue>150)
{
digitalWrite (2,HIGH);
tone (buzpin,100);
digitalWrite (ledPin, HIGH);
delay(100);
Blynk.run();
}
else if (gasValue<50)
{
digitalWrite (2,LOW);
noTone(buzpin);
digitalWrite (ledPin, LOW);
}
}
connection from my esp8266 to my arduino
gnd>gnd
vcc>3.3v
tx>3
rx>2
and use blynkTimer to run the new function every 1 second (or whateverâŚ)
e.g.
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Setup a function to be called every second
timer.setInterval(1000L, runGasSensor);
}
void(runGasSensor)
{
gasValue=analogRead(gasPin);
Serial.println(gasValue);
if (gasValue>150)
{
digitalWrite (2,HIGH);
tone (buzpin,100);
digitalWrite (ledPin, HIGH);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
I dont know whether it is baud rate issue or not because when i.upload it doesnt show any error and success but still my led buzzer doesnt work and esp is not responding , if it was because baud rate issue , may i know how to solve it?
Youâre using the Software Serial library to create a dummy serial port for communication between your Arduino and ESP.
The problem is that the library used to do this works reasonably well at low baud rates, but not at the type of baud rate that youâre using.
People who insist on doing this Arduino/ESP combination say that 9600 is the highest baud rate that you should be using.
However, you canât just pick a random baud rate and expect communication between your Arduino and ESP to just work. You have to tell the ESP what baud rate it should use to communicate with your Arduino, then match this rate in your code. This is done by sending an AT command to the ESP to set it up at the correct rate. This only needs to be done once, but it does need to be done.
Searching this forum for Arduino + ESP-01 will give you more information than you could ever need!
It will work as a Wi-Fi modem if was shipped with AT firmware or you re-flash it with AT firmware.
However, the NodeMCU is much more powerful than the Arduino, so Iâm not sure why youâd bother using the Arduino/NodeMCU combination.
The only issue you may have is if you need to connect more than one analogue device to your NodeMCU, or if your gas sensor is a 5v logic device rather than 3.3v. If thatâs the case then a cheap and simple level shifter could be used to convert the 5v logic to 3.3v.
Umm may u also suggest me what pin should i connect from my esp8266 to my arduino to make the gas sensor works ? I think i connect the wrong pin ? Thats why its not working ,this is my arduino
The Tx and Rx pins on your Arduino are connected to the built-in UART, which are also connected to the large USB connector and which is defined in your code as âSerialâ. When you do commands like Serial.print, the data is sent to these pins.
If you were trying to communicate with your NodeMCU Wi-Fi modem using the same UART then the two sets of communication would clash with each other.
To give yourself an extra UART on the Arduino, youâre using the Software Serial library and in the line of code that I quoted youâre telling the software serial library that you want to use pins 2 and 3.
This second âdummyâ UART is referenced as âEspSerialâ in your code, and as Iâve said earlier, youâre trying to use a baud rate that is too high for the software serial library to be able to handle.
As Iâve also said before, your NodeMCU needs to be configured by an AT command to use the same baud rate as you specify for your software serial dummy UART.
I still think you should throw your Arduino in the bin and work exclusively with the NodeMCU.