Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 <Arduino.h>
- #include <EasyButton.h>
- /****** 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");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement