Introduction: ESP01/01S RELAY MODULE TUTORIAL
Description
This WiFi relay based on AI-Thinker ESP-01/ 01S WiFi module, we use the GPIO0 of ESP-01/ 01S to control the relay by low level. It’s easy to DIY your smart switch to any device by your phone anywhere with this smart relay.
Specifications
- Working voltage: DC 5V-12V
- Working current: ≥250mA
- Communication: ESP01 or ESP 01S
- WiFi module Transmission distance: the maximum transmission distance is 400m (open environment, mobile phone equipped with WiFi module)
- Load: 10A/ 250VAC, 10A/ 30VDC, 10A/ 30VDC, 10A/ 28VDC
- Size: 37 x 25mm
Step 1: Material Preparation
In this tutorial, we only used the following materials:
- USB to UART FTDI Converter
- ESP8266 WiFi Serial Transceiver Module
and last but not least, ESP01/01S Relay Module.
We connect ESP8266 WiFi Serial Transceiver Module to ESP01/01S Relay Module so that we can control the relay via WiFi. To program ESP8266, FTDI Converter is required to be connected with ESP8266.
Step 2: Hardware Installation
As for the connection between ESP8266 and FTDI Converter, it is shown as diagram above or listed as below:
- RX -> TX
- TX -> RX
- VCC -> VCC
- CH_EN -> VCC
- GPIO-0 -> GND
- GND -> GND
The pins for ESP8266 is also labeled as diagram 2.
After done uploading the code to ESP8266, simply connect it to ESP01/01S Relay Module.
Step 3: Uploading the Code
For coding part, change the SSID and PASSWORD to your WiFi SSID and Password respectively. In the code, it is mentioned that serial begin is 115200, so make sure that the serial monitor is 115200 otherwise it will not display anything. We set the URL to https://192.168.0.178/ and it will be used later on.
Attachments
Step 4: Results
When we access the URL, it will show as diagram 1 above. Make sure that you have been activated the ESP8266 along with ESP01/01S Relay Module with a range of 5V to 12V so that you can access the URL. The results for the module is shown as diagram 2 which LED lighted up indicated that the relay is ON.
Once we pressed the OFF in URL, the relay will be turned OFF simultaneously and vice versa for ON option.
8 People Made This Project!
- dougrice made it!
- dazzor made it!
- garnerchris32 made it!
- Omickie made it!
See 4 More
88 Comments
Question 4 weeks ago on Step 3
how I connect to my WIFI, and I can't connect with the address given
I don't have the USB to UART FTDI Converter
4 months ago
please add firebase cloud control
5 months ago
Hello,
Unable to send *.ino program with Arduino IDE to ESP01 via UART FTDI Converter
Error message
"esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header"
ThankYOU
Question 10 months ago on Introduction
Hello, how can I convert this source code from client to access point?
2 years ago
Did anyone faced any problem...such as relay getting on/off continuously as soon as the relay board is powered on. I am facing this irritating problem, any help?
Reply 11 months ago
I use timer (ne555) to power up 4 relay module after 7sec after power on esp8266
Reply 2 years ago
i assume you're using v4 module. just add a 470uf/16v elec. capacitor direcly on optocoupler pin 1 (+) and 2 (-)
Reply 2 years ago
I got the HW-655 with the ESP8266 and when I power it up (before even programming the ESP8266) I got the relay on the HW-655 operating and releasing about every second, haven't worked out why yet, if anyone knows why, I'd love to hear, cheers
1 year ago
If having problems uploading the code try this. It worked for me... Anyhow webserver "drops" all the time. It works for about 5 minutes then it freezes... Any idea what to do???
2 years ago
mine not working
the error message is below
Arduino: 1.8.12 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Serial, None, Only Sketch, 115200"
Executable segment sizes:
IROM : 246344 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 28148 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1260 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 1264 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 25208 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 277016 bytes (28%) of program storage space. Maximum is 958448 bytes.
Global variables use 27732 bytes (33%) of dynamic memory, leaving 54188 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port COM4
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
File "C:\Users\Dr. Chandan Parashar\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1/tools/upload.py", line 65, in <module>
esptool.main(cmdline)
File "C:/Users/Dr. Chandan Parashar/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/esptool\esptool.py", line 2890, in main
esp.connect(args.before)
File "C:/Users/Dr. Chandan Parashar/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/esptool\esptool.py", line 483, in connect
raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
can you tell what is the mistake I am committing
Reply 1 year ago
This happens when your ESP01 is not in program mode, you need to connect GPIO0 to ground -> and then reconnect your ESP
Reply 2 years ago
I have/had the same problem, spent a couple of days trying, put a 10uF accross the 3.3v, seemed to make it better, then I found that is I momentarily disconnected the GPIO0 when it go to this bit "Connecting........_____", it continued on loading the data all OK, why I don't know...If I find out more, I will report.
Reply 2 years ago
Are you sure you have the correct port and have your Tx and Rx the right way round? It looks like the ESP isn't responding at all.
I've had one occasionally sit looking at me which recovered after pulling the USB and re-plugging.
2 years ago
Well, after spending an inordinate time trying to solve the problem of the ESP webserver becoming unresponsive (but with the device still responding to a ping) including adding a watchdog and sending a heartbeat from the IoT controller I gave up and moved over to ESPAsyncWebServer which you can get here:-
https://github.com/me-no-dev/ESPAsyncWebServer/
Rui Santos has an excellent working example here:-
https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/ESP8266/ESP8266_Relay_Module_Web_Server.ino
You'll need to change NUM_RELAYS and the GPIO assigned to your relays but after that it just works and has not locked up in a couple of days (touch wood).
All good fun :)
Reply 1 year ago
I too encountered this issue and managed to solve it.
SOLUTION:
Add:
client.stop();
to the end of the loop cycle and
client.setTimeout(10);
to the top of the loop cycle.
This will disconnect the clients and prevent the hang/freeze. Be aware that with these modifications, the server will accept the command (ON or OFF) and instantly disconnect you.
This is an ideal scenario if you have a third party app controlling the relay since its the fastest way to activate the relay and free the webserver.
Reply 2 years ago
I experienced the same issues with the server becoming unresponsive -
tried implementing no sleep options etc but nothing seemed to work. Your
suggestion of ESPAsyncWebServer worked for me. For those looking to get
this working with the same system as described in this article, it will
take a bit of effort as you'll need to install about three libraries
and as mentioned by @crossy7980 you'll need to update the code to suit -
but after that it's smooth sailing with the USB programmer and ESP101S.
1 year ago
It works, just that my Network changed the IP address, so I had to search on my router for the new IP address.
2 years ago on Step 4
I've noticed that the relay engages momentarily when first powered on. I moved the write to before the pinmode to see if it helped but it didn't. Depending on the application, this could be problematic.
2 years ago on Step 4
Thank you for the Instructable that was clear and informative but I'm baffled by something.
This didn't work for me. The sketch works fine when the ESP-01 is connected to a UART to USB adapter but when it's connected to the relay module, nothing happens and I think I know why.
All the reports I have read suggest that these modules have two faults that prevents them booting, which is why I'm baffled. I don't understand how this worked for anyone. The two issues are that the CH_PD pin is not pulled high and GPIO0, which needs to be pulled high at boot time is actually pulled to ground via a 10k resistor. The descriptions I've seen elsewhere suggest that this can only work if the CH_PD pin is permanently connected to Vcc and either that the 10k resistor pulling GPIO0 is removed or another is added to connect GPIO0 to Vcc. I'm going to try this today. If it works (as has been widely reported elsewhere), I'll report back.
[Edit]
I have now tried this and it worked.
I had to remove the 10k resistor marked as R2 on my board (which looks absolutely identical to yours) and connect CH_PD to Vcc to get the ESP-01 module to boot. Once I'd done that, everything worked exactly as you'd expect. Until I did this, it didn't even boot. This is a fundamental design flaw with this board. The fix is very easy if you have the tools to desolder tiny SMD components. I suppose you could just break the resistor with wire cutters if you cannot desolder the resistor.
Reply 2 years ago
Looks like it's depending on the manufacturer.
Most of my devices work out of the box while plugged into USB with an USB->Serial converter. However, the chips I got with the relay boards refused to connect.
After -fix- wiring the CH_EN to VCC it works perfectly adn flashed latest Tasmota (8.x)
Suggest to solder a 4k7 resistor between VCC and CH_EN.
Thx for the hint.