Unable to connect to Home WIFI using Arduino UNO and ESP8266 ESP-01

Unable to connect to Home WIFI using Arduino UNO and ESP8266 ESP-01

  1. IF I upload empty Sketch and then USE AT commands I am able to get through everything.

However, when I do the same using the Sketch it does not work. Here is the sketch https://www.hackster.io/fanatic-series/water-level-meter-ba164b

#include <SoftwareSerial.h>
#define DEBUG true  
#define dbg Serial  // USB local debug
#define trigPin 10  //IO of Ultrasonic Sensor
#define echoPin 11 //IO of Ultrasonic Sensor
long duration;  
float distance;
const int max_hight=30;  // maximum deapth of the Water Tank. in my case its a bucket

SoftwareSerial Serial1(0,1); //RX, TX

String ssid = "pot";

String pass = "1985";
String ip = "192.168.1.8";  //desired IP Address
String ref="refresh";         //Text for refeshing the HTML Page  
String num_delay = "3";    // Delay is second to refresh the HTML Page 

String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  Serial1.print(command); // send the read character to the esp8266
  long int time = millis();
  while ( (time + timeout) > millis()) {
    while (Serial1.available()) {
      // The esp has data so display its output to the serial window
      char c = Serial1.read(); // read the next character.
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }

  return response;
}





void setup() {

  // Set baud rates
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  Serial1.begin(115200);
  dbg.begin(115200);
  dbg.println("DEBUG: Running Setup");



  sendData("AT+RST", 2000, DEBUG); // reset module
  sendData("AT", 2000, DEBUG); // reset module
  sendData("AT+CWMODE=3", 1000, DEBUG); // configure as access point
  sendData("AT+CWLAP", 1000, DEBUG);
sendData("AT+CWJAP=\""+ssid+"\",\""+pass+"\"", 6000, DEBUG); // configure as access point
sendData("AT+CIPSTA=\""+ip+"\"",1000,true); // configure softAPip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CIPSERVER=1,80",1000,DEBUG); // turn on server on port 80


delay(1000);


  dbg.println("DEBUG: Setup complete\n\n");
}


void loop()
{
  
  if(Serial1.available()) // check if the esp is sending a message 
  {
    Serial.println("hello");
    Serial.write(Serial1.println("AT+CIFSR"));
    //delay(1000);

    /*
    while(Serial1.available())
    {
      // The esp has data so display its output to the serial window 
      char c = Serial1.read(); // read the next character.
      Serial.write(c);
    } */
    
    if(Serial1.find("+IPD,"))
    {
     delay(1000);
     sensor_data();
     String data = String((int)distance);
     String webpage="";
 
     int connectionId = Serial1.read()-48; // subtract 48 because the read() function returns 
                                           // the ASCII decimal value and 0 (the first decimal num_delayber) starts at 48
String colorgreen="background-color:green;";  //#87F467- Green, #FF7979-Red
String colorred="background-color:red;";  //#87F467- Green, #FF7979-Red

  if(distance<=10 || distance>=90){webpage="<html><body style=\""+colorred+"\"></body>";}
  else {webpage="<html><body style=\""+colorgreen+"\"></body>";}
  webpage+="<meta http-equiv=\""+ref+ "\" content=\"" + num_delay+ "\"/> <h1><center>WATER LEVEL<\center></h1> <h2><center>"+String(data)+" %<\center></h2><\html>";


     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
     
//Serial.println(webpage);   


 
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);
    //Serial.println("send0");
    //delay(2000);
    }
    
  }
}
       
  
  // END - Borrowed Code


  void sensor_data()
  {
    
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
    distance=max_hight-distance;
    distance=(distance/max_hight)*100;
    
    
    }

SoftwareSerial on hardware Serial pins? Serial is on pins 0 and 1.

Suggest you run an example first as supplied with the 8266 library , then go from there.
Take note of how to set the 8266 into program mode. When I programmed mine up the AT commands no longer worked unless I re loaded that program, so you may not be uploading code ??

Thx for the response.

For starters I was using USB connection and tx and rx on 0,1

So I changed that to SoftwareSerial on A0, A1 it worked once and was able to see the connection and webpage.

However, after restarting once again I had the same issue Cannot get connection to WIFI. Not sure why it does not work now.

Also if we upload the same sketch and connect to External Power supply and no serial connection from Laptop will the sketch work or does it depend of USB serial connection

sjbosco:
Thx for the response.

For starters I was using USB connection and tx and rx on 0,1

So I changed that to SoftwareSerial on A0, A1 it worked once and was able to see the connection and webpage.

However, after restarting once again I had the same issue Cannot get connection to WIFI. Not sure why it does not work now.

Also if we upload the same sketch and connect to External Power supply and no serial connection from Laptop will the sketch work or does it depend of USB serial connection

The best tutorial I have found on this is if you intend to use the default AT firmware that comes with the ESP-01 is Arduino to ESP8266 By Serial Communication | Martyn Currey

SoftwareSerial should be used at 9600 baud. 115200 will not work.

It must be emphasized that you need a good 3.3V power supply for the ESP-01 module.
The Arduino Uno's 3.3V is not adequate and can cause all sorts of flaky behavior.

.

Hi, I got the same problem when coding this project, I use the original schematic with hardware RX - TX of Arduino Pro Micro connect to TX - RX of ESP8266 . Please help.

  • I code only the SRF05 and it works, but both the led light in ESP8266 always on.
  • Tried to send AT command from the COM3 console but it seems the ESP8266 does not work.
  • Checked the Router and IP, it seems the ESP8266 has not registered successfully, then no reply from ping.

testerhn2005:
Hi, I got the same problem when coding this project, I use the original schematic with hardware RX - TX of Arduino Pro Micro connect to TX - RX of ESP8266 . Please help.

  • I code only the SRF05 and it works, but both the led light in ESP8266 always on.
  • Tried to send AT command from the COM3 console but it seems the ESP8266 does not work.
  • Checked the Router and IP, it seems the ESP8266 has not registered successfully, then no reply from ping.

do you have a SerialPassthrough sketch uploaded to Micro?

Juraj, thanks for your quick response. I am a newbie on this area, that said I am trying to copy paste with the original project with minimum modification before next phase. After Googling "SerialPassthrough" I assume you mention about mod firm? If yes, I have not seen that in the orginal post, could you please provide further steps?

Update:

  • I have tried to change the serial connection from 9600 - 57600 - 115200 in code and in device manager, the COM console does show different result but still stuck somewhere.
  • I tried to upload the "void setup" only to test the SSID connect, and it seems the ESP8266 could not connect to the SSID.
  • Let's me test with another ESP8266 for sure, and try to move from hardware serial to software serial A0-A1 to ensure it is still alive.

you have a Micro with ATmega32u4. It has two serial interfaces USB Serial and RX/TX Serial1. the Serial Monitor is connected to Serial and the esp8266 to Serial1. the data will not magically flow over the MCU to get the AT commands from Serial Monitor to esp8266. you must bridge the serials with a sketch.

SerialPassthrough is an example sketch in IDE Examples menu

Thanks for the SerialPassthrough, further reading on that drive me to connect RX-RX TX-TX and able to send AT command from Arduino COM Console but unable to receive response.

It seems the coding having problem (similar as code in Post #1) because I have swapped two other ESP8266 and the problem is still existed.

I have two screenshots following:

you don't have an Uno, where the RX to RX connects esp8266 to the USB chip on board.
on Micro the MCU handles the USB
so RX to TX and SerialPassthrough, will connect esp8266 to Serial Monitor

Thanks a lot for your support. I found the problem and fixed by reflashing the ESP8266 firmware!
May I ask as if someone could help me with the coding to reduce the power consumption of this project?

I am trying to:

  1. Intergrating the NewPing Library code instead of PulseIn.
  2. Power saving for this project via putting the whole kit in sleep mode, only activating the sensor by specific period and emailing the result to specific address.

Thanks!

testerhn2005:
Thanks a lot for your support. I found the problem and fixed by reflashing the ESP8266 firmware!
May I ask as if someone could help me with the coding to reduce the power consumption of this project?

I am trying to:

  1. Intergrating the NewPing Library code instead of PulseIn.
  2. Power saving for this project via putting the whole kit in sleep mode, only activating the sensor by specific period and emailing the result to specific address.

Thanks!

better start a new thread