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: Relay Monitor
- - Source Code compiled for: Arduino Opta WiFi
- - Source Code created on: 2025-08-04 21:56:00
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Toggle relay 1 and its associated LED every 3 */
- /* seconds using the connected relay (pin D0) and LED */
- /* component (pin LED_D0) on the Arduino Opta WiFi */
- /* board. */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - add information on serial
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- const int relayPin = D0; // Pin connected to relay 1
- const int ledPin = LED_D0; // Pin connected to LED associated with relay 1
- void setup(void)
- {
- // Initialize serial communication at 9600 baud rate
- Serial.begin(9600);
- Serial.println("System initialized. Starting relay toggle loop.");
- // Initialize relay and LED pins as outputs
- pinMode(relayPin, OUTPUT);
- pinMode(ledPin, OUTPUT);
- }
- void loop(void)
- {
- static bool relayState = LOW; // Keep track of relay and LED state
- // Toggle relay and LED state
- relayState = !relayState;
- digitalWrite(relayPin, relayState);
- digitalWrite(ledPin, relayState);
- // Send status message over serial
- if (relayState)
- {
- Serial.println("Relay and LED turned ON");
- }
- else
- {
- Serial.println("Relay and LED turned OFF");
- }
- delay(3000); // Wait for 3 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment