SoftwareSerial not working properly

I have made a code for a temperature and hunidity controller that also transmits data to ThingSpeak through WiFi. However, when trying to initialize the ESP module, all I get in serial monitor is this:

[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
WiFi shield not present

This is how my code looks like.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 7     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Uncomment to get temperatures in fahrenheit
//#define USE_FAHRENHEIT

#define WARMRELAYPIN 2
#define COOLRELAYPIN 3
#define HUMIDRELAYPIN 4
#define DRYRELAYPIN 5
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
#include "ThingSpeak.h"

// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Ethernet shield, WiFi101 shield, esp8266, ESP32, and MKR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************


#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(9, 8); // RX, TX
#endif

char ssid[] = "TAH_2.4GEXT";
char pass[] = "28.Januar1951";
int status = WL_IDLE_STATUS;
unsigned long ChannelNumber = 557790;
char WriteAPIkey[] = "A71VMEADZDSF5ISQ";
char ReadAPIKey[] = "JQ05PV694PGR4L3A";

void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD);{
    Serial.println("WiFi shield not present");
    while(true);
  }
  while (status != WL_CONNECTED){
    Serial.println("Attempting to connect to SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);
  }
  Serial.println("You're connected to the network");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  
  Serial.println("DHTxx test!");
  pinMode(WARMRELAYPIN, OUTPUT);
  pinMode(COOLRELAYPIN, OUTPUT);
  pinMode(HUMIDRELAYPIN, OUTPUT);
  pinMode(DRYRELAYPIN, OUTPUT);
  digitalWrite(WARMRELAYPIN, HIGH);
  digitalWrite(COOLRELAYPIN, HIGH);
  digitalWrite(HUMIDRELAYPIN, HIGH);
  digitalWrite(DRYRELAYPIN, HIGH);
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(500);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  //Now send the data to ThingSpeak
  ThingSpeak.setField(1,t);
  ThingSpeak.setField(2,h);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  delay(500);
  if (t <= 12.00){
    digitalWrite(WARMRELAYPIN, LOW);
  } else {
    digitalWrite(WARMRELAYPIN, HIGH);
  }
  
  if (t >= 13.00){
    digitalWrite(COOLRELAYPIN, LOW);
  
  } else {
    digitalWrite(COOLRELAYPIN, HIGH);  
  }
  if (h < 72){
    digitalWrite(HUMIDRELAYPIN, LOW);
  } else {
    digitalWrite(HUMIDRELAYPIN, HIGH);
  }
  if (h > 73){
    digitalWrite(DRYRELAYPIN, LOW);
  } else {
    digitalWrite(DRYRELAYPIN, HIGH);
  }

  ThingSpeak.writeFields(ChannelNumber, WriteAPIkey);
  
}

Also, the board I am using is a Pro Micro.

Any idea why I keep getting this error instead of it working properly?

Why are you using SoftwareSerial on a ProMicro when it has a perfectly good spare HardwareSerial (Serial1) on pins 0 and 1?

…R

Any idea why I keep getting this error instead of it working properly?

The problem has NOTHING to do with SoftwareSerial. Why do you think it does?

  if (WiFi.status() == WL_NO_SHIELD);{

Have you EVER seen another if statement with a semicolon shoe-horned in between the ) and the {?

PaulS:
The problem has NOTHING to do with SoftwareSerial. Why do you think it does?

  if (WiFi.status() == WL_NO_SHIELD);{

Have you EVER seen another if statement with a semicolon shoe-horned in between the ) and the {?

Got rid of the semicolon, however, the issue is still present, even after switching over to Arduino Uno board

eirikh1996:
Got rid of the semicolon, however, the issue is still present, even after switching over to Arduino Uno board

Post the program you have uploaded to the Uno.

...R

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 8     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Uncomment to get temperatures in fahrenheit
//#define USE_FAHRENHEIT

#define WARMRELAYPIN 2
#define COOLRELAYPIN 3
#define HUMIDRELAYPIN 4
#define DRYRELAYPIN 5
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
#include "ThingSpeak.h"

// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Ethernet shield, WiFi101 shield, esp8266, ESP32, and MKR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************


#include "WiFiEsp.h"


#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX


char ssid[] = "TAH_2.4GEXT";
char pass[] = "28.Januar1951";
int status = WL_IDLE_STATUS;
unsigned long ChannelNumber = 557790;
char WriteAPIkey[] = "A71VMEADZDSF5ISQ";
char ReadAPIKey[] = "JQ05PV694PGR4L3A";

void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD){
    Serial.println("WiFi shield not present");
    while(true);
  }
  while (status != WL_CONNECTED){
    Serial.println("Attempting to connect to SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);
  }
  Serial.println("You're connected to the network");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  
  Serial.println("DHTxx test!");
  pinMode(WARMRELAYPIN, OUTPUT);
  pinMode(COOLRELAYPIN, OUTPUT);
  pinMode(HUMIDRELAYPIN, OUTPUT);
  pinMode(DRYRELAYPIN, OUTPUT);
  digitalWrite(WARMRELAYPIN, HIGH);
  digitalWrite(COOLRELAYPIN, HIGH);
  digitalWrite(HUMIDRELAYPIN, HIGH);
  digitalWrite(DRYRELAYPIN, HIGH);
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(500);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  //Now send the data to ThingSpeak
  ThingSpeak.setField(1,t);
  ThingSpeak.setField(2,h);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  delay(500);
  if (t <= 12.00){
    digitalWrite(WARMRELAYPIN, LOW);
  } else {
    digitalWrite(WARMRELAYPIN, HIGH);
  }
  
  if (t >= 13.00){
    digitalWrite(COOLRELAYPIN, LOW);
  
  } else {
    digitalWrite(COOLRELAYPIN, HIGH);  
  }
  if (h < 72){
    digitalWrite(HUMIDRELAYPIN, LOW);
  } else {
    digitalWrite(HUMIDRELAYPIN, HIGH);
  }
  if (h > 73){
    digitalWrite(DRYRELAYPIN, LOW);
  } else {
    digitalWrite(DRYRELAYPIN, HIGH);
  }

  ThingSpeak.writeFields(ChannelNumber, WriteAPIkey);
  
}

Please post a link to the documentation for the WiFiEsp library - that's where the problem seems to be.

Have you any other program that works with that library? If so please post it.

What ESP module are you using?
What program is loaded onto the ESP module?

...R

Robin2:
Please post a link to the documentation for the WiFiEsp library - that's where the problem seems to be.

Have you any other program that works with that library? If so please post it.

What ESP module are you using?
What program is loaded onto the ESP module?

...R

https://www.arduino.cc/en/Reference/SoftwareSerial

I do run an EspDebug program that came with the WiFiEsp.h library.

I am using an ESP8266

as for the last question, do you mean Arduino sketch or firmware?

eirikh1996:
Arduino - SoftwareSerial

I am familiar with that. It is not what I asked you to post.

I do run an EspDebug program that came with the WiFiEsp.h library.

I did ask you to post that program

I am using an ESP8266

There are several variants - which one have you got?

as for the last question, do you mean Arduino sketch or firmware?

I'm not sure. If you post the link to the WiFiEsp library it may become clear.

Have YOU loaded an Arduino program onto your ESP8266?

...R

Here is the link to the library for WiFiEsp

eirikh1996:
Here is the link to the library for WiFiEsp

https://github.com/bportaluri/WiFiEsp

Thank you. As also requested please post the program that works.

…R

I'm aware that this is an older post, but there came never a formal answer.

I struggled with the same issue and find a solution on an other forum.

The problem: You want to use an Arduino uno or nano with an ESP-01, but you have no other I/O left to use! So the ESP-01 needs to be connected to PIN 0 & 1 by hardware serial. (TX & RX)

The solution:
"I would recommend you to use this library:

It's very good and does support software as hardware serial but unfortunately the author insists on leaving debug output turned on, which prints to Serial. Since the ESP8266 is also connected to the Serial pins (PIN 0 & 1) this causes the library to not work unless you make the following change in your library file debug.h: (Use notepad / Notepad++ to open the *.h file)
Logging disabled by default by per1234 · Pull Request #46 · bportaluri/WiFiEsp · GitHub"

Furthermore you need to comment the software serial definition and the serial (debugging) communication and define serial1 as serial in your sketch.

#define Serial1 Serial
/*
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(1, 0); // RX, TX
#endif*/

void setup() {
//Serial.begin(115200);
Serial1.begin(115200);  //YES HARDWARE SERIAL AT 115200 IS NOW USEABLE!

Finally and important you need to upload the sketch to the Arduino without the ESP-01 RX & TX connected!