Advertisement
pleasedontcode

"Relay Control" rev_01

Mar 9th, 2025
113
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 Control"
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2025-03-09 16:45:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* "Generate a clear and labeled circuit diagram for */
  21.     /* an Arduino-based misting system using a 2N2222 */
  22.     /* transistor, a relay module, and a 12V water pump. */
  23.     /* :    Arduino RF Nano V3.0    D11 → Base of 2N2222 */
  24.     /* transistor (with a 1kΩ resistor i */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <Relay.h>  //https://github.com/rafaelnsantos/Relay
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t myRelay_RelayModule_Signal_PIN_D2     = 2; // Relay module signal pin
  38. const uint8_t transistorBasePin = 11; // Pin connected to the base of the 2N2222 transistor
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool    myRelay_RelayModule_Signal_PIN_D2_rawData       = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float   myRelay_RelayModule_Signal_PIN_D2_phyData       = 0.0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. // Create an instance of the Relay class
  50. Relay myRelay(myRelay_RelayModule_Signal_PIN_D2, 10); // Example period of 10 seconds
  51.  
  52. void setup(void)
  53. {
  54.     // put your setup code here, to run once:
  55.     pinMode(myRelay_RelayModule_Signal_PIN_D2, OUTPUT);
  56.     pinMode(transistorBasePin, OUTPUT); // Set the transistor base pin as output
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // put your main code here, to run repeatedly:
  62.     updateOutputs(); // Refresh output data
  63.     myRelay.loop(); // Call the relay loop to manage its state
  64. }
  65.  
  66. void updateOutputs()
  67. {
  68.     digitalWrite(myRelay_RelayModule_Signal_PIN_D2, myRelay_RelayModule_Signal_PIN_D2_rawData);
  69.     digitalWrite(transistorBasePin, myRelay_RelayModule_Signal_PIN_D2_rawData); // Control the transistor
  70. }
  71.  
  72. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement