Advertisement
pleasedontcode

"Blynk Relay" rev_01

Jun 29th, 2024
573
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: "Blynk Relay"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-29 17:42:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system should control a relay module connected */
  21.     /* to digital pin D2 using the Relay library. The */
  22.     /* relay on off same as switch on off at blynk */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Create a system to manage a relay module on */
  25.     /* digital pin D2 with the Relay library. The relay */
  26.     /* should respond to a Blynk app switch, ensuring */
  27.     /* synchronized on/off states for efficient remote */
  28.     /* control. */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Relay.h>  //https://github.com/rafaelnsantos/Relay
  33. #include <BlynkSimpleStream.h>  // Blynk library for serial communication
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38. void updateOutputs(void);
  39. BLYNK_WRITE(V1); // Blynk function to handle virtual pin V1 writes
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t relay_RelayModule_Signal_PIN_D2 = 2;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool relay_RelayModule_Signal_PIN_D2_rawData = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. /***** used to store data after characteristic curve transformation *****/
  50. float relay_RelayModule_Signal_PIN_D2_phyData = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. Relay light(relay_RelayModule_Signal_PIN_D2, true); // Initialize relay on pin 2, Normally Open
  54.  
  55. /****** BLYNK AUTH TOKEN *****/
  56. char auth[] = "YourAuthToken"; // Replace with your Blynk Auth Token
  57.  
  58. void setup(void)
  59. {
  60.     // put your setup code here, to run once:
  61.     Serial.begin(9600); // Initialize serial communication
  62.     Blynk.begin(Serial, auth); // Initialize Blynk with serial communication
  63.     light.begin(); // Initialize the pin
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // put your main code here, to run repeatedly:
  69.     Blynk.run(); // Run Blynk
  70.     updateOutputs(); // Refresh output data
  71. }
  72.  
  73. void updateOutputs()
  74. {
  75.     // Example of using the Relay library functions
  76.     relay_RelayModule_Signal_PIN_D2_rawData = light.getState(); // Get relay state
  77. }
  78.  
  79. // Blynk function to handle virtual pin V1 writes
  80. BLYNK_WRITE(V1)
  81. {
  82.     int pinValue = param.asInt(); // Get the value from the Blynk app
  83.     if (pinValue == 1) {
  84.         light.turnOn(); // Turn relay on
  85.     } else {
  86.         light.turnOff(); // Turn relay off
  87.     }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement