Using ESP8266 with Arduino Uno

Hello there, would be brilliant if anyone could help me with my issue.

I have been looking around the internet and used tutorials for the ESP8266 setup. I am using a 5v to 3.3v regulator and if I manually send AT commands in the serial monitor the ESP8266 responds correctly and I can manually connect to the wifi router. (The end goal is to send sensor data to a webpage such as in this tutorial-https://www.instructables.com/id/Arduino-Esp8266-Post-Data-to-Website/)

I have tried various example code including the one in the tutorial. Yet when I try to use the code the ESP8266 seems to be unresponsive and no response is visible on the serial monitor. Why might this be??

Lewis

#include "SoftwareSerial.h"

String ssid ="My Router Name";
String password="Router Password";
SoftwareSerial esp(0, 1); // RX, TX

String data;
String server = "lidiotnodal-monitors.000webhostapp.com/";
String uri = "/esppost.php"

int DHpin = 8;//sensor pin
byte dat [5];
String temp ,hum;

void setup() {

pinMode (DHpin, OUTPUT);
esp.begin(9600);
Serial.begin(9600);

reset();
connectWifi();
}

//reset the esp8266 module

void reset() {
esp.println("AT+RST");
delay(1000);

if(esp.find("OK") ) Serial.println("Module Reset");
}

//connect to your wifi network
void connectWifi() {
String cmd = "AT+CWJAP="" +ssid+"","" + password + """;
esp.println(cmd);
delay(4000);

if(esp.find("OK")) {
Serial.println("Connected!");
}

else {

connectWifi();
Serial.println("Cannot connect to wifi"); }
}

byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {

if (digitalRead (DHpin) == LOW) {

while (digitalRead (DHpin) == LOW); // wait for 50us

delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'

if (digitalRead (DHpin) == HIGH)

data |= (1 << (7-i)); // high front and low in the post

while (digitalRead (DHpin) == HIGH);

// data '1 ', wait for the next one receiver

}

} return data; }

void start_test () {

digitalWrite (DHpin, LOW); // bus down, send start signal

delay (30); // delay greater than 18ms, so DHT11 start signal can be detected

digitalWrite (DHpin, HIGH);

delayMicroseconds (40); // Wait for DHT11 response

pinMode (DHpin, INPUT);

while (digitalRead (DHpin) == HIGH);

delayMicroseconds (80);

// DHT11 response, pulled the bus 80us

if (digitalRead (DHpin) == LOW);

delayMicroseconds (80);

// DHT11 80us after the bus pulled to start sending data

for (int i = 0; i < 4; i ++)

// receive temperature and humidity data, the parity bit is not considered

dat = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH);
// send data once after releasing the bus, wait for the host to open the next Start signal
}
void loop () {
start_test ();
// convert the bit data to string form
hum = String(dat[0]);
temp= String(dat[2]);
data = "temperature=" + temp + "&humidity=" + hum;// data sent must be under this form //name1=value1&name2=value2.
httppost();
delay(1000);
}
void httppost () {
esp.println("AT+CIPSTART="TCP","" + server + "",21"); //start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: " + "/" + "\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
esp.print(sendCmd);
esp.println(postRequest.length() );
delay(500);
if(esp.find(">")) { Serial.println("Sending.."); esp.print(postRequest);
if( esp.find("SEND OK")) { Serial.println("Packet sent");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
// close the connection
esp.println("AT+CIPCLOSE");
}
}}
[/quote]

We can't see your code.
Don't forget code tags.

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

Those are the hardware serial pins. It makes no sense to try to use them for soft serial as well. Use different pins for software serial.

delay(1000);

Unresponsive, you say?

(See what I did with the code tags?)

Hi,

ah yes that makes sense, I have moved the from 0,1 to 6,7 now. Yet Still have the same issue occurring.

After uploading the code to the arduino Uno, I open the serial monitor and it is just blank and does not print any messages which is weird. I have it on 9600 Baud and NL & CR. (The ESP8266 responded to AT command whens I was on this).

Do you have the ESP TX to Uno software serial RX. And ESP RX to Uno software serial TX through a level shifter or voltage divider?

I have the ESP TX going to the Arduino TX and so on, is that wrong? and yes I am using an voltage divider

I have the ESP TX going to the Arduino TX and so on, is that wrong?

Yes.

The connections should be TX to RX: what one end transmits, the other end receives.

Use The hardware Serial port 0 and 1, as the baud rate needs to be set at 115200 and the software serial can not deliver such speeds reliably, You need to do this because the ESP comes as standard at 115200, so trying at 9600 will not work until you change the baud rate, thus why you are getting no response.

Change the pins to 0 and 1 and don't use software serial, then set the speed to 115200 and try just sending AT and see if you get the response OK.

then i suggest you send this command:

AT+UART_DEF=9600,8,1,0,0

Which shall change the ESP baud rate to 9600, to which your then need to change your code - serial monitor to 9600.

Why not to use softwareserial on uno? How to debug? Pull wires out and in everytime debugging is needed? If it was mega then i would agree to use hardware serial.

This is my system running on uno with esp via softwsreserial 115200bps. http://72.140.195.6
I did public stress test and it withstands requests without restarting. One bug only with ntp server which is very slow.

No matter the field one works in, troubleshooting is easy; break it down into steps. The first step I would perform is --- delete all code which was not necessary to connect to wifi and Serial.println the IP address. Once that has been confirmed, slowly introduce your added code and monitor the results.