My esp8266 is not responding

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

move everything out of your loop

Leave it blank void loop ?

hope this helps: http://docs.blynk.cc/#troubleshooting-delay

copy that loop ^

Im sory but where must i put this if i move all of this out of the loop ?

gasValue=analogRead(gasPin);
  Serial.println(gasValue);
  if (gasValue>150)
  {
    digitalWrite (2,HIGH);
    tone (buzpin,100);
    digitalWrite (ledPin, HIGH);
    delay(100); 
    Blynk.run();

into a function called:

void (readGasSensor)

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
}

How to declared runGasSensor ? Sory im just newbie in this such thing.

Whoops

Should be

Void runGasSensor()

Ok done but i got error from void loop

Void loop()
{
blynk.run();
timer.run();
}

It said a function dedinition is not allowed here before { token
How ? ;<

Make sure all your curly braces { } all have openings and closings…

ok done all coding can be upload without error but still my buzzer,led and esp8266 didnt work
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;
BlynkTimer timer;
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);

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

and the serial monitor say the esp is not responding hmm ;<

Baud rate issue?

2 Likes

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!

Pete.

I use this esp8266 and im scare if this device doesnt support and cant connect to my arduino

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.

Pete.

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

Arduino Pin 2 —> NodeMCU Pin Tx
Arduino Pin 3 —> NodeMCU Pin Rx

Pete.

wait hmm in my arduino 2 and 3 is not tx rx, but 1 and 0 is tx rx , so i still.need to connect 2 and 3 ?

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.

Pete.

2 Likes