ESP8266-01 with MLX90614 (Using thingspeak) - AT commands no response

Done compiling, but serial monitor not consistent showing results. Even showing results, always shows wdt reset. This is the code:

#include <SoftwareSerial.h>
#define RX 0
#define TX 1
#include <Wire.h>
#include <Adafruit_MLX90614.h>
int red = 6;
int green = 5;
int buzzer = 11;
float arrayData[5];
int i = 0;
int j, k;
int x = 0;
String AP = "Wifi";       // AP NAME
String PASS = "12345"; // AP PASSWORD
String API = "3LWVPF4PXH079JPA";   // Write API KEY
String HOST = "";
String PORT = "80";
String field = "field1";
int countTrueCommand;
int countTimeCommand; 
boolean found = false; 
float valSensor = 1;
SoftwareSerial wifi(RX ,TX ); 

Adafruit_MLX90614 mlx = Adafruit_MLX90614(); 
void setup() {
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
  pinMode(red, OUTPUT);
  pinMode(red, LOW);
  pinMode(green, OUTPUT);
  pinMode(green, HIGH);


void loop() {
 valSensor = getSensorData();
 String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor);
 sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
 sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
  digitalWrite(green, HIGH); 
  for (int i = 0; i < 5; i++) {
      arrayData[i] = arrayData[i + 1];
  arrayData[4] = mlx.readObjectTempC();
  for (int i = 0; i < 5; i++) {

  for (int i = 0; i < 5; i++) {
    if (arrayData[i] < 37.5)break;
    if (i == 4) {
      digitalWrite(green, LOW);
      digitalWrite(red, HIGH);

      for (j = 0; j < 3; j++) {
        tone(buzzer, 300);
      digitalWrite(red, LOW);
    } else {
      digitalWrite(red, LOW);
      digitalWrite(green, HIGH);

float getSensorData(){
  Serial.print("Ambient = ");

  Serial.print("*C\tObject = ");

  return mlx.readObjectTempC(); 

void sendCommand(String command, int maxTime, char readReplay[]) {
  Serial.print(". at command => ");
  Serial.print(" ");
  while(countTimeCommand < (maxTime*1))
      found = true;
    countTimeCommand ++;
  if(found == true)
    countTrueCommand ++;
    countTimeCommand = 0;
  if(found == false)
    countTrueCommand = 0;
    countTimeCommand = 0;
    found = false;

Can I get some help? Thank you.

First you have to provide the necessary information. First start with links to the used hardware! The standard ESP8266-01 doesn't have a pin 11 so I guess you're using another board. Maybe you use some other Arduino and connect it to a ESP8266-01 only for WiFi connectivity but that's too much guessing. That's the reason we always expect you to provide a complete wiring diagram in addition to the code.

Given you use an Arduino UNO connected to the ESP8266-01, this cannot work because you activate the hardware serial on pins 0 and 1 (Serial.begin(9600):wink: and also activate a SoftwareSerial on the same pins. You cannot use the ESP8266's WiFi on the hardware serial pins and do debugging over the same pins.

Thanks for the input, pylon. Yes, i am using arduino UNO. However, if i change the connection of RX and TX to pin 3 and 4, it will show espcomm_sync failed. May I know why is it so?

warning: espcomm_sync failed
error: espcomm_open failed
An error occurred while uploading the sketch
error: espcomm_upload_mem failed

You probably selected the wrong board. espcomm is used to upload a sketch to an ESP processor. As you're using the UNO it shouldn't be used.

So, any suggestion what board should i use to replace my UNO? But why if i connect the RX and TX to pin 0 and 1 it wont show this error?

OMG, what a mess. If you wire esp8266 to RX and TX pin, the sketch will upload to esp8266. The Uno is then only a USB-to-TTL-Serial adapter.
but the uploaded sketch replaces the AT firmware.
on esp8266 Arduino you use the ESP8266WiFi library, not the AT commands. see the examples of the ESP8266WiFi library in IDE Examples menu

you would use AT commands if you had AT firmware in esp8266 and Uno as 'host' which sends AT commands to WiFi module.

Thank you Juraj for the replying. What should i do then? Connect the RX and TX pin to pin 0 and 1 or other digital pins? And also, i have tried to download AT firmware in esp8266. But the serial monitor show all AT commands fail. What should i correct?

what you want?
a) buy a Wemos D1 mini, wire the sensor to it
b) upload AT firmware into esp-01 and write a sketch for Uno with my WiFiEspAT library to use the esp-01 as WiFi adapter

c) advanced option: wire the sensor to esp-01

How does b and c can be done? May i know how does these two options work? :grin: :grin:

c) esp01 has esp8266 MCU and 4 pins are accessible. io 1 and io 3 are Serial RX and TX. io 2 and io 0 are boot config pins but can be used if the boot state is right. your current configuration uploads Arduino sketch to esp-01 using the USB chip of Uno.

b) GitHub - jandrassy/WiFiEspAT: Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.