Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: Button Relay - Source Code compiled for: Arduino Uno - Source Code created on: 2023-12-15 11:14:23 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Connect a Motor Using Relay & Control from Serial */ /* Input and Relay switching output will be 230V */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
/****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void toggleRelay(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t SREE_PushButton_PIN_D2 = 2; const uint8_t RELAY_PIN = 3; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Initialize the EasyButton object with the button pin EasyButton button(SREE_PushButton_PIN_D2); void setup(void) { // Initialize Serial for debugging purposes. Serial.begin(9600); // Initialize the relay pin pinMode(RELAY_PIN, OUTPUT); // Set the initial state of the relay to OFF digitalWrite(RELAY_PIN, HIGH); // Initialize the button object button.begin(); // Register the toggleRelay function to be called when the button is pressed button.onPressed(toggleRelay); } void loop(void) { // Read the button state button.read(); // Add your additional code here } void toggleRelay(void) { // Toggle the state of the relay digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN)); // Send the relay state information via Serial if(digitalRead(RELAY_PIN)){ Serial.println("Relay OFF"); } else { Serial.println("Relay ON"); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)