ESP32/ESP8266 Relay Module - Control AC Appliances (Web Server)

Sdílet
Vložit
  • čas přidán 17. 12. 2019
  • ESP32 Project (schematics + source code) ► RandomNerdTutorials.com/esp32...
    ESP8266 Project (schematics + source code) ► RandomNerdTutorials.com/esp82...
    Using a relay with the ESP32 is a great way to control AC household appliances remotely. This tutorial explains how to control a relay module with the ESP32. We'll take a look at how a relay module works, how to connect the relay to the ESP32 and build a web server to control a relay remotely (or as many relays as you want).
    SAFETY WARNING: in this example, we’re dealing with mains voltage. Misuse can result in serious injuries. If you’re not familiar with mains voltage ask someone who is to help you out. While programming the ESP or wiring your circuit make sure everything is disconnected from mains voltage.
    Like my page on Facebook:
    / randomnerdtutorials
    Follow me on twitter:
    / ruisantosdotme
    Subscribe for more projects like this!
    bit.ly/subscribeRNT
  • Věda a technologie

Komentáře • 152

  • @RuiSantosdotme
    @RuiSantosdotme  Před 4 lety +13

    You can find on my blog the full step-by-step instructions for each ESP board.
    ESP32 Project (schematics + source code) ► RandomNerdTutorials.com/esp32-relay-module-ac-web-server/
    ESP8266 Project (schematics + source code) ► RandomNerdTutorials.com/esp8266-relay-module-ac-web-server/

    • @ingenierocristian
      @ingenierocristian Před 4 lety

      Rui Santos Hi, I bought your ESP32 course, it turns out that I need to send digital values from 16 GPIOS, and send them to a platform called Ubidots, but I still don’t know how can I doit, can you please help me about?

    • @RuiSantosdotme
      @RuiSantosdotme  Před 4 lety

      @@ingenierocristian hello, unfortunately I've never used that platform before. Have you tried their sample projects from the library? Thanks!

    • @ingenierocristian
      @ingenierocristian Před 4 lety

      @@RuiSantosdotme Ubidots is quite similar to the project you made in the Module 7 of your course, except this platform integrate its broker, it uses the MQTT protocol

    • @RuiSantosdotme
      @RuiSantosdotme  Před 4 lety

      @@ingenierocristian I think they have a library with a bunch of examples that show how to use the platform. Did you try their library examples? You can also use any MQTT example (instead of using an IP address, you use their domain name, then check which topics you need to subscribe to)

  • @MrSpock-sm3dd
    @MrSpock-sm3dd Před 3 lety +9

    This is the third project I'm trying. Yours was the only one who works. Thank you a lot my friend, hugs from Brazil

    • @RuiSantosdotme
      @RuiSantosdotme  Před 3 lety +2

      Thank you for your kind words, I'm glad it was helpful. Greetings from Portugal, Rui

  • @jtrain1653
    @jtrain1653 Před rokem +1

    Thank you so much for sharing this wonderful video!It means alot to show and educate people who are trying to do gadgets like these.

  • @Banjoba
    @Banjoba Před 4 lety +1

    Clear and concise. Great video. Thanks.

  • @edsonferraz1
    @edsonferraz1 Před 5 měsíci

    Congratulations Rui!! Great solution, thanks so much.

  • @ldt_
    @ldt_ Před 4 lety +1

    This is great... you are great... where the hell was this video 8 months ago when I needed you? lol. Good work!

    • @RuiSantosdotme
      @RuiSantosdotme  Před 4 lety

      Thanks!

    • @ldt_
      @ldt_ Před 4 lety

      @@RuiSantosdotme Hey, so going through your posted project, do you have any recommendations for setting this up and accessing the ESP without port forwarding on the firewall? Something like a websocket server/client with an Android app?
      Thanks

  • @pelouis9413
    @pelouis9413 Před 3 lety

    Thank you my friend by your project ,Im come from Vietnam.

  • @edsonferraz1
    @edsonferraz1 Před 5 měsíci

    Congratulation Rui!! Great solution. Thanks so much.

  • @CreativeDesk
    @CreativeDesk Před 4 lety +1

    Your video is always so clear and also your website .all the necessary things are present in website
    Keep posting ...

  • @WPGinfo
    @WPGinfo Před 3 lety

    Thank you. This was very useful!

  • @muneebbutt7101
    @muneebbutt7101 Před 2 měsíci

    i have watched a lot of videos about home automation using esp 8266 but nothing worked . but to my surprise, this time it worked . means a lot bro

  • @kaiomatico
    @kaiomatico Před 4 lety

    Wow now that is really awesome and clean code! Thank you so much:)

  • @rishujain21
    @rishujain21 Před 4 lety +2

    Hi Rui, Thank you for this fantastic video.
    Is there a limit to the number of Channels which can be controlled using a single 8266 NodeMCU component?

  • @sameneko8979
    @sameneko8979 Před 4 lety

    Thank you for the video sir.

  • @3DprintRC
    @3DprintRC Před 7 měsíci

    simple and usefully video.thanks.

  • @dons3357
    @dons3357 Před 4 lety

    Thank you. Helpful as always.

  • @bishop34644
    @bishop34644 Před 4 lety

    Great job if I wanted to only be able to have one really on at a time example if I have four relays and I turn on number one then I turn on number two in the code how would I have it so when you switch relays it auto shuts off pervious one

  • @andys6
    @andys6 Před rokem

    This is great! thank you

  • @Leo-db6mi
    @Leo-db6mi Před 6 měsíci

    really good stuff keep it up

  • @carloselmano6725
    @carloselmano6725 Před 3 lety

    Olá Rui. Parabéns pelo video e pelo canal. Gostava de saber se é possivel fazer o seguinte:
    ter o som ambiente por zonas com botão no Home assistant... será que é possível com esp 8266 ou wemos Com relé E adicionar o sistema ao HA com botões?
    Tipo - ligo o sistema de som e as colunas estão todas ligadas
    - se ligar o botão 1 toca na sala
    - se ligar o botão 2 toca no WC
    se ligar os 2 tocam em ambos os espaços.
    Obrigado

  • @jag_3d
    @jag_3d Před 3 lety +5

    Hey great video! I got a question, do I have to find a 3.3v relay for using in with my ESP32? or what is the model youre using in this video? Thanks, I apreciate your work!

  • @Kunal_Joshi
    @Kunal_Joshi Před 3 lety

    Hi Rui, is there a way to do the same using softAP.

  • @societateanationala6207

    Took me 10 mins ... Thx

  • @christiangenebrozo2126

    Hi good video, could you tell me how did you do the app to your celphone, thanks a lot

  • @kamalambrator4332
    @kamalambrator4332 Před 4 lety

    nice presentation! thank you

  • @sukasa9374
    @sukasa9374 Před 4 lety +1

    I see this tutorial only control 5 chanel ? Can this device use 8 chanel ?

  • @sandorfarkas7193
    @sandorfarkas7193 Před 3 lety

    Hello. do you have any idea how it can work with xlights with an esp32 16 channel relay?

  • @gurumurthykola8520
    @gurumurthykola8520 Před 4 lety

    Hi Rui, The tutorial is nice. i have tried using the information provided in your tutorial. Able to control the relays only when my ESP8266 and Laptop (where i am opening the web page to control the relays) are connected to same network. If both are connected to same Wifi network, the ip address is not opening. What might be the issue? Do you have any inputs?

  • @mr3748
    @mr3748 Před 3 lety +1

    Good day Mr Santos, thank you for your videos, Ive learned a lot from all of them. I was wondering if you could help me regarding relays...
    So I have a simple webserver where I can turn a relay on/off and I have three LDR sensors as inputs for the three status LED of the water pump I want to control. Ive used the meta-refresh to refresh my web server every 30s, BUT once the server refreshes, my relay quickly turn off and back on again during the reset. Is this one of issues related with using meta-refresh or does this sound like bad coding?
    EDIT: I fixed it within an hour of typing this message, Ive connected the relay to GPIO2 but I was so focused on my coding and other stuff that Ive failed to remember that the buildin LED is also controlled from GPIO2. Luckily this is an easy fix.
    Ive used the buildin LED to give me wifi status updates as well as data coming from the client, that is why my relay went mad.
    Ill leave this comment to help others.

  • @BootlegEL
    @BootlegEL Před 6 měsíci

    Thanx this was helpful

  • @2ds.service200
    @2ds.service200 Před rokem

    A good work. Really i like

  • @user-dl3hj3cw9o
    @user-dl3hj3cw9o Před 4 lety

    Отличный проект. Можно ли добавить простой таймер, например после движения ползунком влючается реле, а через 5 сек. отключается и ползунок возвращается в состояние выкл.

  • @nursyazwani8846
    @nursyazwani8846 Před 3 lety

    hi, may i know what database u are using for this project?

  • @RoMecha_lb
    @RoMecha_lb Před 3 lety

    Great tutorial dear

  • @RajatGupta_Pune
    @RajatGupta_Pune Před 4 lety

    @rui Santos : can you help me with code in your Relay code, to have the Internal LED of ESP8266 Blinking while the WIFI is being Connected, and stays ON once connected to wifi, Unable to be sure if it was connected or not if not connected to computer.

  • @exmexh4713
    @exmexh4713 Před 4 lety

    Hello. Can I control 24V relay with 3.3V(12mA) output GPIO? So using ohms law i need 2k ohms to get 24V. Will this work?

  • @danielwarnock4157
    @danielwarnock4157 Před rokem

    I followed your tutorial and built a similar project Thank You it was a fun build! is there a way to name the relays independently in the web server? I have them performing specific functions and I'd rather them have a name other than Relay #1 - GPIO 16 etc... I'd really appreciate your help

  • @walterr8115
    @walterr8115 Před 3 měsíci

    Thank you😃, i was wondering why it doesn't work, then i realize the jumper caps were removed!

  • @blukobalto
    @blukobalto Před 3 lety

    I have an esp and i want to monitor the lights of an electromechanical pump's control box. The lights are 24v ac i need to read their status on or off with the esp is it possible to read the relays status with this module?

  • @treeyuono9372
    @treeyuono9372 Před 4 lety

    Thank u....Rui...

  • @danisxatzi6282
    @danisxatzi6282 Před 3 lety

    Hello!!
    What if i want when i sent the command to close the relay, it will close in one or 2 sec it self?
    Thanks!!

  • @cizainnocent8392
    @cizainnocent8392 Před 2 lety +1

    Very nice video. It worked perfectly when I repeated it. Could do you please improve it by making it accessible from anywhere over the internet? thx

  • @mojtaba3296
    @mojtaba3296 Před 2 lety

    fantastic!!

  • @sonupradeep1996
    @sonupradeep1996 Před 3 lety

    how to acces the node mcu from external network...do we have to perform things like port forwarding to acces the same throuh the internet

  • @Eduardo-ro4bv
    @Eduardo-ro4bv Před 2 lety

    Thanks for your video dude. I have a question? If I need a relay that can handle a 48VDC out with 6A. Can i connect to 2 relay that give 30VDC and 10A each to control only this 1 equipment?

  • @mekszii
    @mekszii Před rokem

    Hello! if I want to supplement it with a LoRa module due to the longer range, what should i do?

  • @abur9976
    @abur9976 Před 2 lety

    una pregunta, estoy estoy trabajando en un proyecto para automatizar el reguio de un cultivo por bonbas de agua, el control de la automatización se hara mediante una aplicacion wed, tengo un modulo esp8266 y un rele de dos canales, la pregunta es a pesar que el rele dice que solo soporta 10-15A Y 125 VAC - 250VAC, no hay problema si lo utilizo para una bomba de agua de 110 vcc?

  • @bossdonalan6840
    @bossdonalan6840 Před 4 lety

    Good explanation

  • @raffaelebarlotti9017
    @raffaelebarlotti9017 Před rokem

    Hi, great project! I need to use all 8 channels with ESP8266 could you tell me which pins to connect the remaining 3 channels to? Thank you.

  • @Luismaia00
    @Luismaia00 Před 2 lety

    Very nice , let´s say as is 5 relay, each controled by each button now how to add a button to turn off/on all at the same time,the idea is that leaving house and turn OFF all ligths or getting home turn on ligths ON, is it possible ?

  • @hussienmohamed2589
    @hussienmohamed2589 Před 3 lety

    Could I use the same project to control more than one home light bulb?
    Or I need to buy 8 channel relay module to control all the ceiling light bulbs in my room?
    "I mean the main voltage home light bulbs not the external light bulbs".
    Thank you.

  • @gurunanjaiahkembhavimath8728

    Good video

  • @ingenierocristian
    @ingenierocristian Před 3 lety

    Hi, I need to make an I2C communication between an Esp 32 and Esp8266, where can I find info about?

  • @DeepRoy4600
    @DeepRoy4600 Před 3 lety

    Vou testar isso assim que tiver tempo. Serias capaz de me tirar umas dúvidas?

  • @Circuitsplanet
    @Circuitsplanet Před 2 lety

    Excellent

  • @naufal9104
    @naufal9104 Před 4 lety

    rui, how to post data without refreshing the page?

  • @christiangenebrozo2126

    Good video, i have a problem my relé module needs 5v and the esp8266 just send 3.3v and it doesn't work please help, thanks a lot

  • @chubbyvery1339
    @chubbyvery1339 Před 3 měsíci

    Hi,
    Followed your video and it works. The problem I encounter is that when I open my motor, I need to close it before I can open other device. I believe they should work simultaenously. Whats wrong with my circuit?

  • @NEWBI3GAM1NG
    @NEWBI3GAM1NG Před 4 lety

    nice video.. but anyway i have a little question about how to change the credentials without hard coding again.. thanks in advance..

  • @Dancopymus
    @Dancopymus Před 3 lety

    Hi Rui, Greetings from Brazil! I have two questions:
    1) I have a Module with 8x Relays, but it works with 12V, so how should I connect it to ESP32/ESP8266? I know I must use External Power, but how do I make the connections?
    2) And that JDVcc jumper I don't understand what it's for. Thanks

  • @quickfixengineeringltd8035

    I have a hosted domain. How do I make this project controlled over WiFi not with a local network

  • @hummingbird2520
    @hummingbird2520 Před 3 lety

    Can we Controll led output of 1 volt

  • @sanmeetsingh8219
    @sanmeetsingh8219 Před 2 lety

    hi
    i like your video , but i have question that,
    i am using esp 32 for my rgb lights {wled} and i also want that esp board to turn off things that i link in this video,
    so plzz tell me can i makeor run 2 commands always on a single esp board
    u can also make video on that

  • @GurinderSingh
    @GurinderSingh Před 2 lety

    Is internet connection or wi fi
    compulsory with this module can I use this module for switch on off with mobile directly

  • @evilmode100
    @evilmode100 Před 2 lety

    Hi how to name each gpio? as Relay #4 renamed to garage?

  • @vishwambharjoshi4317
    @vishwambharjoshi4317 Před 3 lety

    Hay we are using it by Wifi, but can we use it by Manually + Bluetooth enabled........if Yes, then what will be the circuit diagram and codes?

  • @MFORMAAZ
    @MFORMAAZ Před 4 lety

    Can I control 1 phase AC motor

  • @dkeinys
    @dkeinys Před 3 lety

    Hi Can you please create version of this script that allows to control relays based on Temp & Humidity??

  • @bhaskerreddy9054
    @bhaskerreddy9054 Před 4 lety

    Is this can be controlled from anywhere in the world

  • @guilhermepaixao1102
    @guilhermepaixao1102 Před 4 lety

    Exelente.obrigado pour partilhar.Bom ano!

  • @eldaelda4991
    @eldaelda4991 Před 3 lety

    How reverse the output,
    Relay 16 channel have positif input.

  • @enriquebartolini6161
    @enriquebartolini6161 Před 2 lety

    Do you need an ip pubblic? Thanks

  • @Dean.Michael.Winchester

    What if I want to control the relays using blynk?

  • @valdirturquettes8715
    @valdirturquettes8715 Před 4 lety +1

    Olá ! Amigo
    Seus videos são bons
    Faca em português , que vc vai ter muitos seguidores no aqui no Brasil
    ATt

  • @vojtasmolik3547
    @vojtasmolik3547 Před 4 lety

    Hi Rui don't you want to make weather station based on your ESP-32 weather shield with another wirelessly connected another shield that one will be inside and one outside that will be shown on display and on internet and maybe solar powered i think that would be awesome sorry for my poor english keep what are you doing and happy holidays!

  • @elektron2kim666
    @elektron2kim666 Před měsícem

    I need to do this at some point. My solar setup (tiny 12 volt batteries) must be off at night (draining from the controller, mostly) and my sister got some ideas where she lives.

  • @NEWBI3GAM1NG
    @NEWBI3GAM1NG Před 3 lety

    hi sir is it a local server only? thanks in advance

  • @shandradm911
    @shandradm911 Před 2 lety

    how to make if turn off relay 1 turn on relay 2?

  • @technotricks7627
    @technotricks7627 Před rokem

    Sir i need, auto on relay when connected to wifi can u help me? M a beginner

  • @titsik
    @titsik Před 4 lety

    you are genios

  • @CharDhue
    @CharDhue Před 3 lety

    I use this relay module but the relay won't change even thou the led change with 3.3v from nodemcu

  • @enriqueolmeda1
    @enriqueolmeda1 Před 3 lety

    Hi Rui, ESPAsyncWebServer is not available... What can I do? Could it be that it does not exist anymore?

  • @NuMwhan-bg4fq
    @NuMwhan-bg4fq Před rokem

    when connecting my 4 channel module to the gnd and 5V pins of my esp32wroom32u wifi disconnects and can't access webpage (I made my own)
    What could be the issue? the module is taking too much energy?

  • @Circuitsplanet
    @Circuitsplanet Před 2 lety

    Is there anyway to control it through internet is????? Plzzzz

  • @user-xe5fg8yy3l
    @user-xe5fg8yy3l Před 5 měsíci

    i know it is long time this video was relased but i tried it and is wdt reseting can somebodz help me????

  • @AshiqurRahman
    @AshiqurRahman Před 3 lety

    I have NODE MCU esp 32 wroom devkitv1 .
    It has no 5v output. (Only one 3.3v output)
    if I connect relay module eith external 5v power source and connect only the data pin with ESP 32 board, will my relay work? Will the ESP32 burn?
    I understand that the above question can be answered if I knew
    1. Relay connected with just an external power source (no pins even data is connected with esp 32 board). What is the voltage reading of data pin of relay?
    [ I believe it should be 0, since this is just a triggerer]
    2. Now I have connected relay module's data pin with ESP32's any data pin and relay's power is again given from external source. Will the ESP32 be able to trigger relay now?
    Please answer I am having hard times.

    • @patrickmclaughlin6013
      @patrickmclaughlin6013 Před 3 lety

      I think you can use an external power supply for the relays and just use the esp8266 to trigger them
      see 2:34 for the jumper but that could be specific to the relay board you have, the one I have does not have the external power supply jumper

  • @danielapetroaie8217
    @danielapetroaie8217 Před rokem

    when i run the code i don't get any error but nothing shows up on the serial port i pressed the rst button
    why?

  • @user-dm8sm3gw5o
    @user-dm8sm3gw5o Před 4 lety +2

    Hello and thanks for this beautiful video. Can you tell me how to connect to this Esp32 from WEB and not only from same network??

    • @yoursinger4014
      @yoursinger4014 Před 3 lety

      You can use Firebase or any sort of database. Connect it to your Esp32 , make an android or IOS app.. and you are done! There are plenty of videos on how to connect Esp32 with Firebase. Hope it helps!

  • @elpetitcafe5385
    @elpetitcafe5385 Před 4 lety +3

    Hi Rui,
    I though you need 5v to move the coil of the relay, are the 3v of a nodemcu enough to control relay? Or do you use an extra power source to make it work?

    • @adrianshawuk
      @adrianshawuk Před 4 lety +2

      Elpetit Cafe I had to buy 3v relays as my esp32 couldn't supply enough to use the 5v one I was using with my Arduino that ran on 5v

  • @technophile01
    @technophile01 Před 3 lety

    Hi. Can we access to esp8266 from anywhere ? Thanks.

  • @christianrojano6470
    @christianrojano6470 Před 4 lety +1

    Good Day Sir!, In my current project I am combining your codes for the dht22 and relay. I encountered a problem and it says "relayState is not declared in this scope"...can I ask sir why is that?

    • @prakharverma2286
      @prakharverma2286 Před 2 lety

      put this at the starting of the code:
      String relayState(int i);

  • @jumbo999614
    @jumbo999614 Před rokem

    Is this tutorial for RELAY with active LOW? Mine is active low.
    Can you also explain the code?
    the lines with code:
    request->send_P(200, "text/html", index_html, processor);
    The function: String processor(const String& var) { .....}
    I thought you have to pass argument into processor function on "request->send...."

  • @0124akash
    @0124akash Před rokem

    This project based on local area network or global ?

  • @h.p.8379
    @h.p.8379 Před 4 lety

    Thanks for the video. I see use 2 skits for ESP8266 and ESP32. Couldn't you combine both sketches and just use the sketch for both ESP (8266 and 32)?
    You would then only have one sketch, which then works for both ESPs.

    • @RuiSantosdotme
      @RuiSantosdotme  Před 4 lety

      The examples demonstrated in this video work for both boards, if you notice I use a condition to include the proper WiFi library if you're using the ESP32 or ESP8266 (time of video 4:42 and lines 7-12 ). I hope that helps!

  • @Santiter
    @Santiter Před 4 lety +1

    Hi ! First of all thank you very much for all your tutorial and content ! Thanks a lot !!
    I have a question:
    I'm starting to program an ESP32, and what I want to do is to use data that I wan’t to input through an internal html site, exactly as you do in one of your tutorials using the ESPAsyncWebServer Library, and at the same time I need to be able to auto connect the device without hardcoding the Password and Name of the net, so I can do it more “plug and play”
    Where should I start studying? Is there a way of combining both libraries, or some of those features are also possible to make in both libraries?
    Thanks a lot !!

    • @saeedbaloch2
      @saeedbaloch2 Před 3 lety

      that's exactly what I am looking for too, I hope he replies back to this.

  • @mikepatton9684
    @mikepatton9684 Před 2 lety

    and webserver with espalexa?

  • @hanslubbe9702
    @hanslubbe9702 Před rokem

    Hi Rui,
    Just came across this video, i must say very well done, nice clean code and awesome explanation !!
    i do have a question though, i would like to name the relays, i don't want to see the "Relay#1 - GPIO 14" text, can you please update the esp8266 sketch?

    • @hanslubbe9702
      @hanslubbe9702 Před rokem

      Hey Rui, don't worry, i got it working the way i want to :)
      Still, thank you for your great video, it helped me a lot!!

  • @magicianofelectronics951

    Compiling error for ESP8266, Wemos D1 R1 mini, Thank you

  • @FlorinIonitaAdrian
    @FlorinIonitaAdrian Před 3 lety

    Hello! i have a question. if you close the webpage, and you open it again, does it still show the relay state? if the device is on or of?

  • @AshiqurRahman
    @AshiqurRahman Před 3 lety +1

    Is the relay module 3.3v or 5 v