Advertisement
pleasedontcode

"Buzzer Relay" rev_01

Jun 14th, 2024
467
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: "Buzzer Relay"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-14 16:51:43
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This code will program an arduino nano to */
  21.     /* communicate and operate my cube hopper mk2 via */
  22.     /* rs232 so that when  an icp pa7 bill acceptor take */
  23.     /* a dollor it gives out 4 quarters  every time a */
  24.     /* dollar is accepted turn on buzzer for 500ms */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <ezBuzzer.h>  // https://github.com/ArduinoGetStarted/buzzer
  29. #include <Relay.h>     // https://github.com/rafaelnsantos/Relay
  30. #include <HardwareSerial.h> // For RS232 communication
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36. void checkBillAcceptor(void);
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t buzz1_PassiveBuzzer_Signal_PIN_D2 = 2;
  40. const uint8_t myRelayModule_RelayModule_Signal_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool buzz1_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  45. bool myRelayModule_RelayModule_Signal_PIN_D3_rawData = 0;
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float buzz1_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
  50. float myRelayModule_RelayModule_Signal_PIN_D3_phyData = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. ezBuzzer buzzer(buzz1_PassiveBuzzer_Signal_PIN_D2);  // Initialize ezBuzzer object with the pin
  54. Relay myRelay(myRelayModule_RelayModule_Signal_PIN_D3, true); // Initialize Relay object with the pin and Normally Open configuration
  55.  
  56. void setup(void) {
  57.   // put your setup code here, to run once:
  58.   Serial.begin(9600); // Initialize RS232 communication
  59.   pinMode(buzz1_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  60.   myRelay.begin(); // Initialize the relay pin
  61. }
  62.  
  63. void loop(void) {
  64.   // put your main code here, to run repeatedly:
  65.   buzzer.loop();  // Call the buzzer.loop() function in loop()
  66.   checkBillAcceptor(); // Check if a dollar is accepted
  67.   updateOutputs();  // Refresh output data
  68. }
  69.  
  70. void updateOutputs() {
  71.   digitalWrite(buzz1_PassiveBuzzer_Signal_PIN_D2, buzz1_PassiveBuzzer_Signal_PIN_D2_rawData);
  72.   if (myRelayModule_RelayModule_Signal_PIN_D3_rawData) {
  73.     myRelay.turnOn();  // Turn relay on
  74.   } else {
  75.     myRelay.turnOff(); // Turn relay off
  76.   }
  77. }
  78.  
  79. void checkBillAcceptor() {
  80.   if (Serial.available() > 0) {
  81.     int receivedByte = Serial.read();
  82.     // Assuming the bill acceptor sends a specific byte when a dollar is accepted
  83.     if (receivedByte == 'D') { // Replace 'D' with the actual byte sent by the bill acceptor
  84.       // Dollar accepted
  85.       buzzer.beep(500); // Turn on buzzer for 500ms
  86.       for (int i = 0; i < 4; i++) {
  87.         myRelay.turnOn();  // Turn relay on to dispense a quarter
  88.         delay(250);        // Adjust delay as needed for the dispensing mechanism
  89.         myRelay.turnOff(); // Turn relay off
  90.         delay(250);        // Adjust delay as needed for the dispensing mechanism
  91.       }
  92.     }
  93.   }
  94. }
  95.  
  96. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement