I plugged in the Arduino Uno and the ESP8266 following this schema:

enter image description here

When I enter "AT" in the serial monitor, I get an "OK". I can also connect to my wifi using typical ESP8266 commands.

enter image description here

What doesn't work is passing these commands using an Arduino Script. For example, if I use this script, I don't get an "OK" from the ESP8266.

void setup() {
  // put your setup code here, to run once:

 void loop() {
  // put your main code here, to run repeatedly:
     Serial.println("NOT OK");

I tried a bunch of different codes,and nothing works. What am I doing wrong?

  • With the code above, how can you say that you don't receive "OK" from ESP8266? Your code contains no read from Serial, so if "OK" is sent, you cannot know it.
    – jfpoilpret
    Oct 30, 2016 at 18:51
  • Ok so my question was stupid i guess. What do I need to add so that I display the "OK"?
    – Test Test
    Oct 30, 2016 at 18:53
  • For that you'll need to check Serial.available() and then use Serial.readString() or other Serial methods. Then you will have to decide how you "debug" your sketch, that could be lighting a LED (quite limited) or printing to another serial port (for that you will need to use SoftwareSerial. I think you can easily find simple examples that just do that.
    – jfpoilpret
    Oct 30, 2016 at 18:59
  • I updated the code above using serial.find(). It still displays "NOT OK". What I don't understand is when I type in the command "AT" everything works fine. When I try to pass it programatically, then it stops working.
    – Test Test
    Oct 30, 2016 at 19:04

1 Answer 1


What you are doing wrong is:

If sending AT commands from PC to ESP and receiving OK ,as you said, works - that means you connected TX output from USB --> RS232 IC on the board to both RX pin of the ATmega328 and RX pin of the ESP8266 - not as in your picture. Similarly, you connected RX input of the USB --> RS232 IC on the board to both ATmega328 TX and ESP8266 TX pin of the ESP8266. If communication between PC and ESP works, then you connected TX Arduino pin with TX ESP pin and RX Arduino pin with RX ESP pin and not as shown in the picture.

When you send AT command from PC both ATmega328 and ESP8266 are getting the signal from USB --> RS232 IC in their RX pins. As your firmware in the first 10 seconds doesn't read the RS232 data, ATmega328 just ignores the packets sent by PC but ESP8266 receives the packets and responds with OK.

Since you shorted RX on ATmega328 and RX on ESP8266 and you shorted TX on ATmega328 and RX on ESP8266, ATmega328 can not send the data to ESP and vice versa so there is no OK.

In the other case, if you connected ATmega328 TX with ESP8266 RX and ATmega328 RX with ESP8266 TX (as shown in the picture) then you would have shorted USB --> RS232 IC's TX with ESP's TX and you would have shorted USB --> RS232 IC's RX with ESP's RX.

In that case ATmega328 might be able to send AT command to both ESP and PC at the same time and ESP would respond but now ESP's TX would be connected to ATmega's RX which is now shorted with USB --> RS232 IC's TX so PC can't receive that packet. However, when ATmega328 responds with OK, the signal now goes from ATmega328 TX to USB --> RS232 IC's RX (as always) and you might see the response in serial terminal.

So, you can't get the ESP to respond directly to PC and to ATmega328 without interchanging the TX/RX wires. Furthermore, as you may know RS232 is designed for communication between two devices, not three - and this is the case where three devices (USB --> RS232 IC, ATmega328 and ESP8266) are connected to the same TX/RX pins at the same time in a rather unusual way. Because, devices are usually connected TX to RX and RX to TX. However, when using the Arduino's onboard USB --> RS232 converter (by removing the microcontroller or holding it under reset) then you have to connect TX to TX and RX to RX. That is because there is one more TX/RX pair in between PC and the RX/TX pins on the board. The output of the USB --> RS232 converter (TX) sends the data to RX pin on ATmega328 (and RX pin on the board) but if you want to send the signal further (to some other device), then the pin marked with RX is going to act as TX.

To summarize:

  1. The schematics does not correspond to what you have written. Such a connection would not allow to send the AT commands from the PC to ESP and to receive response, meaning you connected the TX/RX the other way round.
  2. You can not have both at the same time. You have to decide whether you want to send AT commands from the PC or from microcontroller and then connect the wires accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.