{"id":42452,"date":"2018-01-01T00:00:00","date_gmt":"2017-12-31T23:00:00","guid":{"rendered":"https:\/\/botland.com.pl\/blog\/esp32-connecting-a-relay\/"},"modified":"2025-05-20T08:32:05","modified_gmt":"2025-05-20T06:32:05","slug":"esp32-connecting-a-relay","status":"publish","type":"post","link":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/","title":{"rendered":"ESP32 &#8211; connecting a relay"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading time:<\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">min.<\/span><\/span>\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"42452\" class=\"elementor elementor-42452 elementor-28573\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-2b47ef99 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2b47ef99\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6e3ecd50\" data-id=\"6e3ecd50\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d49b7f7 elementor-widget elementor-widget-text-editor\" data-id=\"d49b7f7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b6d134e elementor-widget elementor-widget-heading\" data-id=\"b6d134e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">What we need to complete the project<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-77d289b elementor-widget elementor-widget-text-editor\" data-id=\"77d289b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>For the lighting control project, we will need an ESP32 module, a relay module, and an LED or light bulb. We recommend<span style=\"font-weight: bold;\">\u00a0<a href=\"https:\/\/botland.store\/esp32-wifi-and-bt-modules\/19291-esp32-starter-kit-with-esp32-wifi-module-5903351242950.html\" data-wpel-link=\"internal\">ESP32 starter kit available at Botland onlne store<\/a><\/span>, as it contains all the necessary components for this and previous projects.<\/p><p>Alternatively, full list of needed products can be completed below:<\/p><ul style=\"font-size: 16px; background-color: #ffffff;\"><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"http:\/\/esp32%20wifi%20+%20bt%204.2%20-%20platform%20with%20module%20esp-wroom-32%20compatible%20with%20esp32-devkit\/\" data-wpel-link=\"external\" target=\"_blank\" rel=\"nofollow external noopener noreferrer\">ESP module<\/a><\/span><\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/relays\/1997-relay-module-1-channel-with-optoisolation--5904422302337.html\" data-wpel-link=\"internal\">Relay module<\/a><\/span><\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/leds\/1447-set-of-5mm-led-30pcs.html\" data-wpel-link=\"internal\">LED diode<\/a><\/span>\u00a0(or a light bulb)<\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/through-hole-resistors-tht\/4544-tht-cf-carbon-resistor-14w-330-30pcs.html\" data-wpel-link=\"internal\">Resistor<\/a><\/span>\u00a0<span style=\"font-weight: bold; font-size: 1rem;\"><a href=\"https:\/\/botland.store\/through-hole-resistors-tht\/4544-tht-cf-carbon-resistor-14w-330-30pcs.html\" data-wpel-link=\"internal\">330\u00a0<\/a><\/span><a style=\"background-color: #ffffff; font-size: 1rem; font-family: Roboto;\" href=\"https:\/\/botland.com.pl\/rezystory-przewlekane\/4544-rezystor-tht-cf-weglowy-1-4w-330-30szt.html\" target=\"_blank\" rel=\"noopener\" data-wpel-link=\"internal\">\u03a9<\/a><\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/tact-switch\/377-tact-switch-6x6mm-43mm-dip-5-pcs.html\" data-wpel-link=\"internal\">Tact Switch<\/a><\/span><\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/various-wires\/1022-connecting-cables-male-male-65pcs.html\" data-wpel-link=\"internal\">Male-male connecting cables<\/a>\u00a0<u>and<\/u>\u00a0<\/span><a style=\"font-weight: bold;\" href=\"https:\/\/botland.store\/82-various-wires?cable-standard=m-f\" data-wpel-link=\"internal\">female-male connecting cables<\/a><\/li><li style=\"font-size: 16px;\"><span style=\"font-weight: bold;\"><a href=\"https:\/\/botland.store\/476-usb-20-cables\" data-wpel-link=\"internal\">microUSB cable<\/a><\/span><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fcc84f1 elementor-widget elementor-widget-heading\" data-id=\"fcc84f1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Connecting components<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bf3c6f4 elementor-widget elementor-widget-text-editor\" data-id=\"bf3c6f4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The relay, like PIR motion sensor, cannot be plugged into the contact board. The module was connected to the ESP32 using connection wires. The relay coil is powered by 5 V, so the VCC pin was connected to the VIN pin of the ESP32. In order to run the relay coil from the ESP32 kit, a low state must be given to the IN pin, we will use pin 5 of the ESP32 module. Connect the device you want to power using the relay to the screw connectors, in our case it is an LED whose voltage is connected to the COM and NO pins. The coil of the relay will be switched on when the button connected to pin 15 of the ESP32 module is pressed. A detailed wiring diagram can be found below.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-92d3ba6 elementor-widget elementor-widget-image\" data-id=\"92d3ba6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/21.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"21\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6Nzc5OTksInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvMjEuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"473\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/21.jpg\" class=\"attachment-large size-large wp-image-77999\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/21.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/21-300x178.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/21-768x455.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-90cc364 elementor-widget elementor-widget-heading\" data-id=\"90cc364\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Program for ESP32<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-15c8bc4 elementor-widget elementor-widget-code-highlight\" data-id=\"15c8bc4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>\/\/ definiujemy piny, gdzie pod\u0142\u0105czyli\u015bmy przeka\u017anik oraz__przycisk\r\nint relay_pin = 5;\r\nint button_pin = 15;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  pinMode(relay_pin, OUTPUT);   \/\/ ustawiamy pin przeka\u017anika jako OUTPUT\r\n  pinMode(button_pin, INPUT_PULLUP);    \/\/ ustawiamy pin przycisku jako INPUT_PULLUP\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ definiujemy aby stan przycisku odczytywany by\u0142 cyforowo: wysoki \/ niski\r\n  int buttonState = digitalRead(button_pin);\r\n  \/\/ definiujemy zale\u017cno\u015b\u0107:\r\n  if (buttonState == LOW) { \/\/ je\u017celi przycisk przejdzie w stan niski\r\n    Serial.println(\"Przycisk zosta\u0142 wci\u015bni\u0119ty\");\r\n    digitalWrite(relay_pin, LOW);   \/\/ przeka\u017anik za\u0142\u0105czy si\u0119\r\n  }\r\n  else if (buttonState == HIGH) {\r\n    Serial.println(\"Przycisk zosta\u0142 puszczony\");\r\n    digitalWrite(relay_pin, HIGH);\r\n  }\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-0b3082e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0b3082e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-753aafd\" data-id=\"753aafd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-abf88d0 elementor-widget elementor-widget-image\" data-id=\"abf88d0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/34.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"34\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMDMsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvMzQuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/34.jpg\" class=\"attachment-large size-large wp-image-78003\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/34.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/34-300x225.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/34-768x576.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-e02299c\" data-id=\"e02299c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-aec2854 elementor-widget elementor-widget-image\" data-id=\"aec2854\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/43.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"43\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMDcsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvNDMuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/43.jpg\" class=\"attachment-large size-large wp-image-78007\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/43.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/43-300x225.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/43-768x576.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-c70f564 elementor-widget elementor-widget-spacer\" data-id=\"c70f564\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c886cb5 elementor-widget elementor-widget-heading\" data-id=\"c886cb5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Remote relay control<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3c95a42 elementor-widget elementor-widget-text-editor\" data-id=\"3c95a42\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can use the ESP32 web server to remotely control the lights using relays. With the following program, you can use any number of relays by changing the number given in the #define NUM_RELAYS line and specify the corresponding pins to which the relays are connected in int relayGPIOs[NUM_RELAYS] = { };.<\/p><p>After loading the program, the local IP address where the server was created will appear in the serial monitor.<\/p><section class=\"elementor-section elementor-top-section elementor-element elementor-element-b074aa5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" style=\"flex-basis: var(--flex-basis); flex-grow: var(--flex-grow); flex-shrink: var(--flex-shrink); order: var(--order); align-self: var(--align-self); --swiper-theme-color: #000; --swiper-navigation-size: 44px; --swiper-pagination-bullet-size: 6px; --swiper-pagination-bullet-horizontal-gap: 6px; --widgets-spacing: 20px 20px;\" data-id=\"b074aa5\" data-element_type=\"section\"><div class=\"elementor-container elementor-column-gap-default\"><div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5b802a2\" style=\"flex-basis: var(--flex-basis); flex-grow: var(--flex-grow); flex-shrink: var(--flex-shrink); order: var(--order); align-self: var(--align-self); --swiper-theme-color: #000; --swiper-navigation-size: 44px; --swiper-pagination-bullet-size: 6px; --swiper-pagination-bullet-horizontal-gap: 6px; --widgets-spacing: 20px 20px; width: 900px;\" data-id=\"5b802a2\" data-element_type=\"column\"><div class=\"elementor-widget-wrap elementor-element-populated\" style=\"width: 900px;\"><div class=\"elementor-element elementor-element-2347b79 elementor-widget elementor-widget-text-editor\" style=\"flex-basis: var(--flex-basis); flex-grow: var(--flex-grow); flex-shrink: var(--flex-shrink); order: var(--order); align-self: var(--align-self); flex-direction: var(--flex-direction); flex-wrap: var(--flex-wrap); justify-content: var(--justify-content); align-items: var(--align-items); align-content: var(--align-content); gap: var(--gap); --swiper-theme-color: #000; --swiper-navigation-size: 44px; --swiper-pagination-bullet-size: 6px; --swiper-pagination-bullet-horizontal-gap: 6px; --widgets-spacing: 20px 20px; font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight ); width: 880px;\" data-id=\"2347b79\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\"><div class=\"elementor-widget-container\" style=\"transition: background .3s,border .3s,border-radius .3s,box-shadow .3s,transform var(--e-transform-transition-duration,.4s);\"><pre><i>https:\/\/randomnerdtutorials.com\/esp32-esp8266-relay-web-server\/<\/i><\/pre><\/div><\/div><\/div><\/div><\/div><\/section>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-04713b9 elementor-widget elementor-widget-image\" data-id=\"04713b9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/56.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"56\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMTEsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvNTYuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"473\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/56.jpg\" class=\"attachment-large size-large wp-image-78011\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/56.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/56-300x178.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/56-768x455.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-53fa5d0 elementor-widget elementor-widget-code-highlight\" data-id=\"53fa5d0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>#include <WiFi.h>\r\n#include <AsyncTCP.h>\r\n#include <ESPAsyncWebServer.h>\r\n\r\n\/\/Ustaw warto\u015b\u0107 true, aby zdefiniowa\u0107 przeka\u017anik jako normalnie otwarty (NO)\r\n#define RELAY_NO    true\r\n\r\n\/\/Ustaw liczb\u0119 przeka\u017anik\u00f3w\r\n#define NUM_RELAYS  1\r\n\r\n\/\/Przyporz\u0105dkuj ka\u017cde GPIO do przeka\u017anika\r\nint relayGPIOs[NUM_RELAYS] = {5};\r\n\r\nconst char* ssid = \"Twoje_SSID\";\r\nconst char* password = \"Twoje_haslo\";\r\n\r\nconst char* PARAM_INPUT_1 = \"relay\";\r\nconst char* PARAM_INPUT_2 = \"state\";\r\n\r\n\/\/Tworzenie obiektu AsyncWebServer na porcie 80\r\nAsyncWebServer server(80);\r\n\r\nconst char index_html[] PROGMEM = R\"rawliteral(\r\n<!DOCTYPE HTML><html>\r\n<head>\r\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\r\n  <style>\r\n    html {font-family: Arial; display: inline-block; text-align: center;}\r\n    h2 {font-size: 3.0rem;}\r\n    p {font-size: 3.0rem;}\r\n    body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}\r\n    .switch {position: relative; display: inline-block; width: 120px; height: 68px}\r\n    .switch input {display: none}\r\n    .slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 34px}\r\n    .slider:before {position: absolute; content: \"\"; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 68px}\r\n    input:checked+.slider {background-color: #2196F3}\r\n    input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}\r\n  <\/style>\r\n<\/head>\r\n<body>\r\n  <h2><span id=\"Oswietlenie\">Oswietlenie<\/span><\/h2>\r\n  %BUTTONPLACEHOLDER%\r\n<script>function toggleCheckbox(element) {\r\n  var xhr = new XMLHttpRequest();\r\n  if(element.checked){ xhr.open(\"GET\", \"\/update?relay=\"+element.id+\"&state=1\", true); }\r\n  else { xhr.open(\"GET\", \"\/update?relay=\"+element.id+\"&state=0\", true); }\r\n  xhr.send();\r\n}<\/script>\r\n<script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement(\"span\"),this.deviceMode.id=\"elementor-device-mode-wpr\",this.deviceMode.setAttribute(\"class\",\"elementor-screen-only\"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,\":after\").content.replace(\/\"\/g,\"\");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(\".elementor-invisible[data-settings]\").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if(\"none\"===n)return void t.classList.remove(\"elementor-invisible\");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove(\"elementor-invisible\"),t.classList.add(\"animated\",n),this._removeAnimationSettings(t,e)},i);window.addEventListener(\"rocket-startLoading\",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t=\"mobile\"){const e=[\"\"];switch(t){case\"mobile\":e.unshift(\"_mobile\");case\"tablet\":e.unshift(\"_tablet\");case\"desktop\":e.unshift(\"_desktop\")}const i=[];return[\"animation\",\"_animation\"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener(\"DOMContentLoaded\",RocketElementorAnimation.run);<\/script><\/body>\r\n<\/html>\r\n)rawliteral\";\r\n\r\n\/\/Zast\u0119puje placeholder sekcj\u0105 przycisku na twojej stronie internetowej\r\nString processor(const String& var){\r\n  \/\/Serial.println(var);\r\n  if(var == \"BUTTONPLACEHOLDER\"){\r\n    String buttons =\"\";\r\n    for(int i=1; i<=NUM_RELAYS; i++){\r\n      String relayStateValue = relayState(i);\r\n      buttons+= \"<h4>Przekaznik #\" + String(i) + \" - GPIO \" + relayGPIOs[i-1] + \"<\/h4><label class=\\\"switch\\\"><input type=\\\"checkbox\\\" onchange=\\\"toggleCheckbox(this)\\\" id=\\\"\" + String(i) + \"\\\" \"+ relayStateValue +\"><span class=\\\"slider\\\"><\/span><\/label>\";\r\n    }\r\n    return buttons;\r\n  }\r\n  return String();\r\n}\r\n\r\nString relayState(int numRelay){\r\n  if(RELAY_NO){\r\n    if(digitalRead(relayGPIOs[numRelay-1])){\r\n      return \"\";\r\n    }\r\n    else {\r\n      return \"checked\";\r\n    }\r\n  }\r\n  else {\r\n    if(digitalRead(relayGPIOs[numRelay-1])){\r\n      return \"checked\";\r\n    }\r\n    else {\r\n      return \"\";\r\n    }\r\n  }\r\n  return \"\";\r\n}\r\n\r\nvoid setup(){\r\n  Serial.begin(115200);\r\n\r\n    \/\/ Ustaw wszystkie przeka\u017aniki na wy\u0142\u0105czenie przy starcie programu - je\u015bli ustawione na Normally Open (NO), przeka\u017anik jest wy\u0142\u0105czony, gdy ustawisz przeka\u017anik na HIGH\r\n  for(int i=1; i<=NUM_RELAYS; i++){\r\n    pinMode(relayGPIOs[i-1], OUTPUT);\r\n    if(RELAY_NO){\r\n      digitalWrite(relayGPIOs[i-1], HIGH);\r\n    }\r\n    else{\r\n      digitalWrite(relayGPIOs[i-1], LOW);\r\n    }\r\n  }\r\n\r\n  \/\/Po\u0142\u0105cz z WiFi\r\n  WiFi.begin(ssid, password);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(1000);\r\n    Serial.println(\"\u0141\u0105czenie z WiFi..\");\r\n  }\r\n\r\n  \/\/Wy\u015bwietl lokalne IP\r\n  Serial.println(WiFi.localIP());\r\n\r\n  \/\/ Route dla root \/ web page\r\n  server.on(\"\/\", HTTP_GET, [](AsyncWebServerRequest *request){\r\n    request->send_P(200, \"text\/html\", index_html, processor);\r\n  });\r\n\r\n  \/\/Wy\u015blij \u017c\u0105danie GET do <ESP_IP>\/update?relay=<inputMessage>&state=<inputMessage2>.\r\n  server.on(\"\/update\", HTTP_GET, [] (AsyncWebServerRequest *request) {\r\n    String inputMessage;\r\n    String inputParam;\r\n    String inputMessage2;\r\n    String inputParam2;\r\n    \/\/GET input1 value on <ESP_IP>\/update?relay=<inputMessage>\r\n    if (request->hasParam(PARAM_INPUT_1) & request->hasParam(PARAM_INPUT_2)) {\r\n      inputMessage = request->getParam(PARAM_INPUT_1)->value();\r\n      inputParam = PARAM_INPUT_1;\r\n      inputMessage2 = request->getParam(PARAM_INPUT_2)->value();\r\n      inputParam2 = PARAM_INPUT_2;\r\n      if(RELAY_NO){\r\n        Serial.print(\"NO \");\r\n        digitalWrite(relayGPIOs[inputMessage.toInt()-1], !inputMessage2.toInt());\r\n      }\r\n      else{\r\n        Serial.print(\"NC \");\r\n        digitalWrite(relayGPIOs[inputMessage.toInt()-1], inputMessage2.toInt());\r\n      }\r\n    }\r\n    else {\r\n      inputMessage = \"No message sent\";\r\n      inputParam = \"none\";\r\n    }\r\n    Serial.println(inputMessage + inputMessage2);\r\n    request->send(200, \"text\/plain\", \"OK\");\r\n  });\r\n  \/\/ Start server\r\n  server.begin();\r\n}\r\n\r\nvoid loop() {\r\n\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-c89f9e7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c89f9e7\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-17dc3c9\" data-id=\"17dc3c9\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3af89ff elementor-widget elementor-widget-image\" data-id=\"3af89ff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/77.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"77\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMTYsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvNzcuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"391\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/77.jpg\" class=\"attachment-large size-large wp-image-78016\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/77.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/77-300x146.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/77-768x375.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-3471509\" data-id=\"3471509\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9e62312 elementor-widget elementor-widget-image\" data-id=\"9e62312\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/88.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"88\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMjAsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvODguanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/88.jpg\" class=\"attachment-large size-large wp-image-78020\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/88.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/88-300x225.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/88-768x576.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-a3fe8c0 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a3fe8c0\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-578303d\" data-id=\"578303d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-80a0b3c elementor-widget elementor-widget-image\" data-id=\"80a0b3c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/99.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"99\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMjQsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvOTkuanBnIn0%3D\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"391\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/99.jpg\" class=\"attachment-large size-large wp-image-78024\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/99.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/99-300x146.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/99-768x375.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-e7b917c\" data-id=\"e7b917c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e3475ae elementor-widget elementor-widget-image\" data-id=\"e3475ae\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/111.jpg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"111\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NzgwMjgsInVybCI6Imh0dHBzOlwvXC9ib3RsYW5kLnN0b3JlXC9ibG9nXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE4XC8wMVwvMTExLmpwZyJ9\" data-wpel-link=\"internal\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/111.jpg\" class=\"attachment-large size-large wp-image-78028\" alt=\"\" srcset=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/111.jpg 1024w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/111-300x225.jpg 300w, https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/01\/111-768x576.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.<\/p>\n","protected":false},"author":5,"featured_media":62358,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,341,331],"tags":[],"class_list":["post-42452","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics","category-tips","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ESP32 - connecting a relay - Botland<\/title>\n<meta name=\"description\" content=\"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ESP32 - connecting a relay - Botland\" \/>\n<meta property=\"og:description\" content=\"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/\" \/>\n<meta property=\"og:site_name\" content=\"Botland\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/Botland\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-31T23:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-20T06:32:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1510\" \/>\n\t<meta property=\"og:image:height\" content=\"755\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Grzegorz Galuba\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Grzegorz Galuba\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/\"},\"author\":{\"name\":\"Grzegorz Galuba\",\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#\\\/schema\\\/person\\\/320f225a4bee757f7d030c49aea2a072\"},\"headline\":\"ESP32 &#8211; connecting a relay\",\"datePublished\":\"2017-12-31T23:00:00+00:00\",\"dateModified\":\"2025-05-20T06:32:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/\"},\"wordCount\":332,\"publisher\":{\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg\",\"articleSection\":[\"Electronics\",\"Tips\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/\",\"url\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/\",\"name\":\"ESP32 - connecting a relay - Botland\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg\",\"datePublished\":\"2017-12-31T23:00:00+00:00\",\"dateModified\":\"2025-05-20T06:32:05+00:00\",\"description\":\"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#primaryimage\",\"url\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg\",\"contentUrl\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg\",\"width\":1510,\"height\":755},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/esp32-connecting-a-relay\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Strona g\u0142\u00f3wna\",\"item\":\"https:\\\/\\\/botland.store\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ESP32 &#8211; connecting a relay\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/\",\"name\":\"Botland\",\"description\":\"Blog Raspberry Pi, Arduino, elektronika i robotyka - Botland\",\"publisher\":{\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#organization\",\"name\":\"Botland\",\"url\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/logo_kolor_WP_2-1.png\",\"contentUrl\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/logo_kolor_WP_2-1.png\",\"width\":250,\"height\":57,\"caption\":\"Botland\"},\"image\":{\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/facebook.com\\\/Botland\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/botland.com.pl\\\/blog\\\/#\\\/schema\\\/person\\\/320f225a4bee757f7d030c49aea2a072\",\"name\":\"Grzegorz Galuba\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/logo_kolor_WP_3-1-150x150.png\",\"url\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/logo_kolor_WP_3-1-150x150.png\",\"contentUrl\":\"https:\\\/\\\/botland.store\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/logo_kolor_WP_3-1-150x150.png\",\"caption\":\"Grzegorz Galuba\"},\"description\":\"GG nie ma czasu na gadu-gadu - jest zawsze na bie\u017c\u0105co z nowo\u015bciami z oferty, wybiera tylko najlepsze i dba, aby pojawia\u0142y si\u0119 na czas. Jego rozleg\u0142a wiedza o specyfikacjach technicznych produkt\u00f3w to nieocenione wsparcie dla ca\u0142ej ekipy. Do pracy przyje\u017cd\u017ca rowerem i ju\u017c najwy\u017csza pora, aby wszyscy zacz\u0119li bra\u0107 z niego przyk\u0142ad. Oaza spokoju.\",\"url\":\"https:\\\/\\\/botland.store\\\/blog\\\/author\\\/grzegorz\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ESP32 - connecting a relay - Botland","description":"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/","og_locale":"en_US","og_type":"article","og_title":"ESP32 - connecting a relay - Botland","og_description":"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.","og_url":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/","og_site_name":"Botland","article_publisher":"https:\/\/facebook.com\/Botland\/","article_published_time":"2017-12-31T23:00:00+00:00","article_modified_time":"2025-05-20T06:32:05+00:00","og_image":[{"width":1510,"height":755,"url":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg","type":"image\/jpeg"}],"author":"Grzegorz Galuba","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Grzegorz Galuba","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#article","isPartOf":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/"},"author":{"name":"Grzegorz Galuba","@id":"https:\/\/botland.com.pl\/blog\/#\/schema\/person\/320f225a4bee757f7d030c49aea2a072"},"headline":"ESP32 &#8211; connecting a relay","datePublished":"2017-12-31T23:00:00+00:00","dateModified":"2025-05-20T06:32:05+00:00","mainEntityOfPage":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/"},"wordCount":332,"publisher":{"@id":"https:\/\/botland.com.pl\/blog\/#organization"},"image":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#primaryimage"},"thumbnailUrl":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg","articleSection":["Electronics","Tips"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/","url":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/","name":"ESP32 - connecting a relay - Botland","isPartOf":{"@id":"https:\/\/botland.com.pl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#primaryimage"},"image":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#primaryimage"},"thumbnailUrl":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg","datePublished":"2017-12-31T23:00:00+00:00","dateModified":"2025-05-20T06:32:05+00:00","description":"In this article we will connect a relay to an ESP32 module and create a lighting control system using an LED. You can also use a standard 230V incandescent bulb, but be careful with this.","breadcrumb":{"@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#primaryimage","url":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg","contentUrl":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2023\/05\/new2023-zestaw-esp32_okladka-nr5-przekaznik-4.jpg","width":1510,"height":755},{"@type":"BreadcrumbList","@id":"https:\/\/botland.store\/blog\/esp32-connecting-a-relay\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Strona g\u0142\u00f3wna","item":"https:\/\/botland.store\/blog\/"},{"@type":"ListItem","position":2,"name":"ESP32 &#8211; connecting a relay"}]},{"@type":"WebSite","@id":"https:\/\/botland.com.pl\/blog\/#website","url":"https:\/\/botland.com.pl\/blog\/","name":"Botland","description":"Blog Raspberry Pi, Arduino, elektronika i robotyka - Botland","publisher":{"@id":"https:\/\/botland.com.pl\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/botland.com.pl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/botland.com.pl\/blog\/#organization","name":"Botland","url":"https:\/\/botland.com.pl\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/botland.com.pl\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/04\/logo_kolor_WP_2-1.png","contentUrl":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2018\/04\/logo_kolor_WP_2-1.png","width":250,"height":57,"caption":"Botland"},"image":{"@id":"https:\/\/botland.com.pl\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/Botland\/"]},{"@type":"Person","@id":"https:\/\/botland.com.pl\/blog\/#\/schema\/person\/320f225a4bee757f7d030c49aea2a072","name":"Grzegorz Galuba","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2019\/03\/logo_kolor_WP_3-1-150x150.png","url":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2019\/03\/logo_kolor_WP_3-1-150x150.png","contentUrl":"https:\/\/botland.store\/blog\/wp-content\/uploads\/2019\/03\/logo_kolor_WP_3-1-150x150.png","caption":"Grzegorz Galuba"},"description":"GG nie ma czasu na gadu-gadu - jest zawsze na bie\u017c\u0105co z nowo\u015bciami z oferty, wybiera tylko najlepsze i dba, aby pojawia\u0142y si\u0119 na czas. Jego rozleg\u0142a wiedza o specyfikacjach technicznych produkt\u00f3w to nieocenione wsparcie dla ca\u0142ej ekipy. Do pracy przyje\u017cd\u017ca rowerem i ju\u017c najwy\u017csza pora, aby wszyscy zacz\u0119li bra\u0107 z niego przyk\u0142ad. Oaza spokoju.","url":"https:\/\/botland.store\/blog\/author\/grzegorz\/"}]}},"_links":{"self":[{"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/posts\/42452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/comments?post=42452"}],"version-history":[{"count":0,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/posts\/42452\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/media\/62358"}],"wp:attachment":[{"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/media?parent=42452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/categories?post=42452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/botland.store\/blog\/wp-json\/wp\/v2\/tags?post=42452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}