Arduino Uno R3 + ESP8266MOD

Hello,

I am trying to connect my ESP8266MOD to WiFi, but it doesn't work correctfully.
Serial Monitor gives me some random garbage characters.

I am using:
ESP8266MOD (ESP-12E)
Arduino Uno R3
Some wiring cables

Wiring:
ESP UNO
EN --> 3V
VCC --> 3V
GND --> GND
TX --> PORT 1
RX --> PORT 0

**Code: ** (SoftwareSerialExample)

#include <SoftwareSerial.h>

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

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Serial monitor:
Gives "Goodnight moon".
Nothing else.

If I write AT+CWLAP, or any AT-command, it gives a⸮ or A+⸮⸮A5⸮

I am using 9600 bauds and both nl & cr.

Thank you already for your help!

There are several problems:

Pins 0 and 1 on the Uno are used for Serial. These pins are connected to the USB to serial adapter chip on your Uno that communicates with your computer over the USB cable. You're trying to use the same pins to communicate between the Uno's microcontroller and the ESP8266 as well as to communicate between the Uno's microcontroller and the Serial Monitor. You can't do that. You would need to use different pins.

Pins 0 and 1 have hardware serial functionality so it would be very silly to do software serial on these pins.

If you want to communicate between the Uno's microcontroller and the ESP8266, you need to make the connections RX-TX, TX-RX. But your connections are RX-RX, TX-TX. The reason for this is that RX stands for "receive" and TX stands for "transmit".

There are two different ways to do what you're attempting (using the Uno as a USB to serial adapter to communicate with the ESP8266 from the Serial Monitor: You can connect the ESP8266 to any pins on the Uno other than 0 and 1 and run a SoftwareSerial passthrough sketch. Or you can upload a BareMinimum sketch to the Uno and connect the ESP8266 to the Uno with RX-RX, TX-TX connections to pins 0 and 1. After what I just told you about the meanings of RX and TX, this seems confusing. The reason this works is that in this usage you are not communicating between the Uno's primary microcontroller and the ESP8266 but rather communicating directly between the USB to TTL serial adapter chip on the Uno and the ESP8266 with the Uno's primary microcontroller doing nothing. In this case, the functions of the pins 0 and 1 on the Uno are reversed, since the USB to serial adapter is connected to the primary microcontroller RX-TX, TX-RX.

What you are doing now (as have so many before you) is a mishmash of the two approaches and will never work. Are you following a tutorial or something?

The AT firmware on the ESP8266 runs at 115200 baud by default. If you want to use it at 9600 baud (as your code indicates), you need to first connect to it at 115200 baud and send the appropriate AT command to change it to run at 9600. SoftwareSerial does not work reliably at 115200 baud.

Thank you for your reply.

I changed baud's from code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8, 9); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

and I also changed rx and tx cables to port 8 and 9.
Now serial monitor says only "Goodnight moon!" but it won't receive any commands.
Now it doesn't say even carbage.

And I tried to find some guides, but I didn't find any good guide for uno r3, I have 3v in my controller, so I don't need any batteries or something like that I think.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar, then you can just manually add the code tags:

[code]

[color=blue]// your code is here[/color]

[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.

SoundVolume:
I changed baud's from code:

...

  mySerial.begin(115200);

I guess you missed what I said before:

pert:
SoftwareSerial does not work reliably at 115200 baud.

SoundVolume:
and I also changed rx and tx cables to port 8 and 9.

Please describe the exact connections.

SoundVolume:
And I tried to find some guides, but I didn't find any good guide for uno r3

There are a huge number of them. Unfortunately not all of them are very good.

SoundVolume:
I have 3v in my controller, so I don't need any batteries or something like that I think.

By "controller", do you mean the Uno? You should be aware that the ESP8266 uses a lot of current while the WiFi radio is operating. The 3.3 V pin on your Uno may not be able to supply enough current. This is a frequent cause of unreliable operation of the ESP8266.

pert:
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar, then you can just manually add the code tags:

[code]

[color=blue]// your code is here[/color]

[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.
I guess you missed what I said before:Please describe the exact connections.
There are a huge number of them. Unfortunately not all of them are very good.
By "controller", do you mean the Uno? You should be aware that the ESP8266 uses a lot of current while the WiFi radio is operating. The 3.3 V pin on your Uno may not be able to supply enough current. This is a frequent cause of unreliable operation of the ESP8266.

ESP8266 UNO
TX port 8 (rx)
RX port 9 (tx)
GND GND
VCC 3V
EN 3v

ESP2866mod's blue light blinks, so I think it will get power.

I changed the code back

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8, 9); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

SoundVolume:
ESP8266 UNO
TX port 8 (rx)
RX port 9 (tx)

Looks good.

SoundVolume:
ESP2866mod's blue light blinks, so I think it will get power.

That only tells you it's being powered. It provides no guarantee it won't drop out during the the times of ESP8266's peak current draw. These peaks only happen when the radio is operating. So you might be getting your AT ... OK and think it's all good, but then once you get into the real project things start working unreliably. Well, for now I guess you need to just focus on getting that first OK.

SoundVolume:
I changed the code back

Alright, but don't forget what I said:

pert:
The AT firmware on the ESP8266 runs at 115200 baud by default. If you want to use it at 9600 baud (as your code indicates), you need to first connect to it at 115200 baud and send the appropriate AT command to change it to run at 9600.

But serial console says still only "Goodnight moon"
I can't see "Hello world"-message and it won't receive any at-commands.

So will I use command like "AT+UART=9600" to change baud rate correctfully?

Download the "ESP8266 AT Instruction Set" from this page:

You will see that there are two commands: AT+UART_CUR and AT+UART_DEF. The one tricky thing is that there are multiple versions of the AT firmware and the AT commands have changed over time. If your ESP8266 has an outdated or non-standard AT firmware, the information in that reference may not apply. You can check the version using AT+GMR.

But it doesn't still take any commands.
But I will check ESP8266 AT Instruction Set, thanks.