How to communicate with ESP8266 ESP01 by sending data through softwareserial on Arduino Uno? I am able to send AT commands when connecting to the software through the TX/RX pins (1, 0) and the ESP01 communicates perfectly. However, as soon as I start doing that same thing with code I can't get the ESP01 to respond whatsoever. All I'm trying to do is get an OK back from the serial monitor. I changed the baudrate on the ESP01 as well as my serial monitor from 115200 to 9600, 19200 using this command:

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

Troubleshooting steps taken:


Tried upping the voltage in case it wasn't getting enough current.
Tried different ESP01s.
Tried switching TX and RX pins.
Tried using different pins on the Uno (2 and 3, 10 and 11, 7 and 8).
tried changing myESP.println("AT"); to myESP.write("AT\n\r");.


Nothing works. I've done a ton of research and I haven't found anything wrong with what I'm doing, do you guys have any ideas?

#define TX 3
#define RX 2
String ssid = "*****";
String password = "******";

#include "SoftwareSerial.h"

SoftwareSerial myESP(RX,TX);

void setup() {
  pinMode(RX, INPUT);
  pinMode(TX, OUTPUT);
  myESP.begin(19200);
  Serial.begin(19200);
}

void loop() {
  myESP.println("AT");
  delay(5000);
}


Schematic is as follows:
TX -> pin 3
RX -> pin 2
Vcc -> 3.3v
GND -> Ground
CH_PD -> Vcc
How about this:

void loop() {
  while(Serial.available() &gt; 0) {
     myESP.write(Serial.read());
  }
  while(myESP.available() &gt; 0) {
     Serial.write(myESP.read());
  }
}


That code will continue to load data to and from the software serial not just one byte. You can also use string concatenation:

String data = "";
while(Serial.available() &gt; 0) {
   data += Serial.read();
}


Or arrays:

int data_max = 4096;
int data_size = 0;
char data[data_max];
while(Serial.available() &gt; 0) {
   if(data_size &lt; data_max) data[data_size++] = Serial.read();
}