pleasedontcode

Relay Monitor rev_09

Aug 4th, 2025
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Relay Monitor
  13.     - Source Code compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-08-04 21:56:00
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Toggle relay 1 and its associated LED every 3 */
  21.     /* seconds using the connected relay (pin D0) and LED */
  22.     /* component (pin LED_D0) on the Arduino Opta WiFi */
  23.     /* board. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - add information on serial
  30. ********* User code review feedback **********/
  31.  
  32. /* START CODE */
  33. /****** DEFINITION OF LIBRARIES *****/
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. const int relayPin = D0;      // Pin connected to relay 1
  40. const int ledPin = LED_D0;    // Pin connected to LED associated with relay 1
  41.  
  42. void setup(void)
  43. {
  44.   // Initialize serial communication at 9600 baud rate
  45.   Serial.begin(9600);
  46.   Serial.println("System initialized. Starting relay toggle loop.");
  47.  
  48.   // Initialize relay and LED pins as outputs
  49.   pinMode(relayPin, OUTPUT);
  50.   pinMode(ledPin, OUTPUT);
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   static bool relayState = LOW; // Keep track of relay and LED state
  56.  
  57.   // Toggle relay and LED state
  58.   relayState = !relayState;
  59.   digitalWrite(relayPin, relayState);
  60.   digitalWrite(ledPin, relayState);
  61.  
  62.   // Send status message over serial
  63.   if (relayState)
  64.   {
  65.     Serial.println("Relay and LED turned ON");
  66.   }
  67.   else
  68.   {
  69.     Serial.println("Relay and LED turned OFF");
  70.   }
  71.  
  72.   delay(3000); // Wait for 3 seconds
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment