Arduino Uno and esp8266 module communication

Hello people!

I am new here. I have quite a lot of experience with electronics and coding, BUT not much with digital electronics and Arduino.

I am trying to make a simple thermostat for my heating system, but I want to make both the relay and temperature sensor wireless. For this I bought some esp8266 WiFi modules, and I don't really understand how are they supposed to work. I have yet to successfully connect to them, but even if I did, I'd have no idea what to do next and Google doesn't help.

What I imagine I will do is put one esp8266 on the Arduino, one on the sensor and one on the relay, and have them talk to each other, writing code on the Arduino to fetch data from the modules via WiFi.

What I don't understand is this... do I need connection to my router, or can they communicate between themselves independently? Another complete blackout for me is how I would actually send data using the esp8266 modules... I don't even know where to start and what to do and I can't find much info on Google.

I don't need the basics, the thermostat is already running and tested in wired configuration with code already modified and played with... I know the basics, I have no idea how to integrate the esp8266 modules...

Can this even be done or do I need another Arduino on the sensor/relay side as well?

I moved your topic to an appropriate forum category @techalyzer .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Sorry, new here and the New Topic button was greyed out saying I can't make a new topic, when I tried to post in categories...

You must have selected one of the categories that are configured to not allow the creation of topics. If you encounter that, it means you didn't select an appropriate category and you just need to look more closely at the list of available categories to find an appropriate one.

Esp8266 development board is like arduino board with wifi. You can program it on arduino ide.
So you don't need arduino to be connected to esp, you just use esp.
Internet is full of Esp8266 tutorials.

1 Like

You can do it all with an esp8266. What do you mean with the sensor wireless? do you want the sensor someplace other than the control relay? If so you would need two esp8266s.

There are many interconnect possibilities. If you want to network it you can connect to your home network as a station. Another possibility is an access point, in which case it looks like its own network you have to sign on to.

If you set it up as a web server you can interface through any web browser. This is how I use wireless. If you go this route you will need to learn some HTML. It is a lot to learn the basics, but after that you can chose how complicated you want to get.

There are other possibilities such as ESP-NOW for communicating devices.

I made my own PHP application, no problems on the coding side :slight_smile: It's the first time in my life when I write software for hardware, though :upside_down_face:

So if I put a Wifi module on the temperature sensor and one on the arduino, I can connect them? Do I need to somehow program the ESP8266 first?

Sorry for insisting, I know I can find stuff on Google, but it's the same place where a guy said that ESP8266 doesn't turn on at 3.3V and it needs 5V... so I fried my first WiFi module... a lot of false information as well.

Yes.
Have you installed the board package/core for the modules you have purchased?

I assume you are talking about an UNO class Arduino. If so skip the Arduino - do it all on the esp8266. The esp8266 has a better processor and more memory than the Arduino UNO. You need to download the board files for the esp8266 and then you can use the Arduino IDE to program it. Depending on the peripherals you may need some 5V to 3.3V level shifters - but this is a well understood area.

With the board files you will get a bunch of sample programs to get you started on the WiFi features. There are also a lot (of varying quality :slightly_smiling_face:) examples on the internet.

1 Like

That's true if you supply power to onboard voltage regulator.
Most esp8266 dev boards have 5V to 3.3V regulator and they can be powered at 5V, often from USB.
Maybe you should post what board you are dealing with...

I attached my board picture, the smaller black one.

@ oldcurmudgeon

I know, I've been doing this this entire evening to no avail. I must have tried 5 or 6 different wirings, leds, buttons, no leds, no buttons, arduino in reset, arduino without reset, nothing, nothing, nothing.

But, let's put things in order so I make sure that I'm not barking at the wrong tree. As I said, I know next to nothing about this thing and I just started with Arduino. Say I want to make an Arduino read a wireless temperature sensor and a wireless relay. It is important not to have any wired connection to these. Is this the way to go? Is the ESP8266 a good choice, or do I need to look at something else?

I bought such a relay:
2024-10-01 00_00_43-Kit releu cu ESP8266, ESP-01S 5V - eMAG.ro - Brave

Do I have to take out the ESP module out of it to program it with something, or does it work as it is out of the box?

And if I have to talk to the ESP8266, how on Earth do I do it? I have tried all the variants online, and none of them work.

Connections are 3v3 to 3v3 on Arduino, RX to RX and TX to TX on Arduino (already tried to reverse them each time, TX to RX and RX to TX), RST both in air, permanently to ground or pushing a button to ground while programming (again, conflicting information online), IO0 and IO2 either in air, to ground, IO0 to an LED and IO2 in air, EN to 3v3, GND to GND...

I try AT commands, I get nothing. It feels like I'm trying to program a brick...

Does the LED on the ESP have to be ON to show that it's ready to be programmed? Because it only turns on when I put both IO0 and IO2 to ground...?

Do I program it with RESET on Arduino wired to GND?

I feel that this is stupidly complicated for something with 8 pins :slight_smile: And yes, I installed the ESP8266 by ESP8266 community, even tried different versions... one of the tutorials said to load the basic blinky code, I tried, it times out on connect: A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header. I can see the Arduino TX-ing, but the ESP never gets anything.

Could I just have 2 dead modules from all the noob tinkering? But at least I know the first one is dead because it got so hot it burnt my finger when I overvolted it...

Any help would be greatly appreciated. :pleading_face:

From the photo I can expect that there is voltage regulator to power Esp-01 at 3.3V while supplying 5V to relay. This is nor really ideal device if you want to start with Esp MCUs.
You need additional usb- serial module for programming. Could you purchase some Nodemcu or D1 mini devboard to start with. For $2 it would be reasonable investment.

That's fair enough. I was just trying to get away with what I already have. Just to put things into perspective, I've been doing electronics since the age of 9, IT for about the last 20 years and I coded my own billing and company management web app... I kinda hoped I'd figure it out.

But this is what bothers me... why all the tutorials programming the ESP through Arduino? Surely there wouldn't be so many if it wouldn't work...

Of course I'll also get a Nodemcu or D1 mini devboard, but it bugs me that I failed to complete such a simple task shown in the tutorials. Could it be that I actually have two dead ESPs? I kinda want to buy another one and be careful with it just to make sure...

What do you recommend between Nodemcu and D1? I see that D1 is fully Arduino compatible, which honestly would help. I understand that I need another IDE for the Nodemcu?

Thanks!

I recommend Esp32 board, Esp Wroom32 to be precise.
It's $5 board with dual core, 3 serial ports, wifi, bluetooth, plenty of ADC pins, DAC etc.
If you really have to use Esp8266, I prefer Nodemcu.
They are all compatible with same Arduino ide.

If you want tutorials for those, or for your actual Esp-01, I recommend this site:

Yes, but isn't it a technical overkill for just a relay or a temperature sensor? I won't say that I won't use it if it's easier to use, but all those specs just to turn a relay on or off until the end of time seems such a waste :upside_down_face:

Yep.
But it's my preferred board for prototyping. Excellent for learning as well.
When you get used to esp boards, just use those Esp-01 modules for relays and temp sensors. But for learning purpose they are PITA, you need to have separate usb-serial converter and in addition to serial pins you only have Gpio0 and 2, both strapping pins.

ps. if you don't use them for wifi, they are overkill as well, so go with attiny85 for example :wink:

Got it. I'll get one. I've been struggling for 2 days just to connect the standalone module to the Arduino IDE and I'm done with it. If those work out of the box, I'm getting one, plus I don't have to worry about frying anything.

What I'm trying to do is split my thermostat into 3 parts: the main arduino box with the screen where I set and view temperature sits somewhere on my desk. The relay inside the heating unit to get rid of any external wiring. And the temperature sensor somewhere else on a wall. The main reason for this is that the temperature sensor needs to be in a place as little influenced by other factors. My current thermostat is above my wife's desk, and there's a huge difference in detected temperature when she works there, it goes up by as much as 2 degrees, from the laptop and breath. So the ideal place for the sensor is a place where I wouldn't be able to reach the controls easily, and I don't want any wires. So I need both the relay and the temperature sensor to send data wirelessly to the Arduino.

Plus, future online control integration would be nice, though not a priority right now...

So it's perfect case for your new Esp board as "main arduino box", one esp-01 for relay and other for temp sensor. To have that setup online is just few lines of code.

But... will my exact code for the thermostat run on the new ESP board? Or do I have to rebuild it? I have the code ready on the Arduino, for the wired version, it works, senses and displays temperature and humidity on a 16x2 display, you can set the desired temperature and it turns the heating system on or off. I tested it a couple of nights and it works just fine.

What I was thinking was to keep my Arduino UNO as it is, since it works, add WiFi capability to it, and then use the 2 ESP boards on the relay and the temperature sensor.

You obviously need to adjust your code in both scenarios since you bring wireless communication to the game. Your existent code will be compatible with esp as well.
I personally see more work on marrying Uno and Esp than using just Esp. Be aware that they have different operating voltage, so you also need level shifters between them.

After all, I don't know how important that display is going to be when you connect your setup to wifi. You could skip the whole "box" and do the whole setup with two ESPs, one running web-server with UI on your wifi.