• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

How to create a short ON/OFF momentary switch with a Relay?

Q&A Forum › Category: ESP8266 › How to create a short ON/OFF momentary switch with a Relay?
0 Vote Up Vote Down
Gustavo Ruiz Bonino asked 4 years ago

I’m using a Wemos D1 R2 and a 5V Relay. I want to make it go ON and OFF separated by a 500 delay, I saw that this was referet to as a momentary switch.

I’ve modified the webserver sample in the Build Web Server with ESP32 and ESP8266 (great book!) so I can press a button and open the relay and then another button to close it.
I would like it to make it in one procedure, but it doesnt work.
I just want to make a “blink”, open the relay and then 500ms later close triggering this using one single button creating the momentary switch effect (click-click)

This code is not working, it get stucked and it doesnt even click once.

void R1ON_OFF()
digitalWrite(relay1, LOW);
delay(500);
digitalWrite(relay1, HIGH);
}

I have to make two separate functions to make it work, hence I had to use two button, one for ON and another for OFF.

void R1ON(){
digitalWrite(relay1, LOW);
}

void R1ON(){
digitalWrite(relay1, LOW);
}

Is there any limitation on the Wemos D1 R2 or the Relay?

Thanks for your help!

 

Question Tags: relay; momentary switch; Wemos; ESP8266
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Here are two tutorials that might help with your project:

  • https://randomnerdtutorials.com/esp32-esp8266-web-server-outputs-momentary-switch/
  • https://randomnerdtutorials.com/esp32-esp8266-web-server-timer-pulse/

Let me know if you are able to mix it up with your project. Don’t hesitate to ask more questions.
Regards,
Sara
 

0 Vote Up Vote Down
Gustavo Ruiz Bonino answered 4 years ago

Sara, that was fast! I’ll try both methods and let it know here just in case somebody have this very same problem 🙂

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
Then, let me know.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.