Advertisement
pleasedontcode

"Arduino Alarm" rev_01

Jan 3rd, 2024
73
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: "Arduino Alarm"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-03 08:28:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turn on buzzer when distance sensor detects an */
  21.     /* object nearby */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Ultrasonic.h>
  27. #include <ezBuzzer.h>
  28.  
  29. /****** SYSTEM REQUIREMENTS *****/
  30. /****** SYSTEM REQUIREMENT 1 *****/
  31.   /* Turn on buzzer when distance sensor detects an */
  32.   /* object nearby */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t distance_sensor_HC_SR04_Echo_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t distance_sensor_HC_SR04_Trigger_PIN_D2 = 2;
  44. const uint8_t buzzer_PassiveBuzzer_Signal_PIN_D4 = 4;
  45.  
  46. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  47. Ultrasonic ultrasonic(distance_sensor_HC_SR04_Trigger_PIN_D2, distance_sensor_HC_SR04_Echo_PIN_D3);
  48. ezBuzzer buzzer(buzzer_PassiveBuzzer_Signal_PIN_D4);
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.   pinMode(distance_sensor_HC_SR04_Echo_PIN_D3, INPUT);
  54.   pinMode(distance_sensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
  55.   pinMode(buzzer_PassiveBuzzer_Signal_PIN_D4, OUTPUT);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.  
  62.   // Read distance from ultrasonic sensor
  63.   unsigned int distance = ultrasonic.read();
  64.  
  65.   // Check if object is nearby
  66.   if (distance < 20) { // Adjust the threshold distance as per your requirement
  67.     // Turn on the buzzer
  68.     buzzer.beep(200); // Adjust the beep time duration as per your requirement
  69.   }
  70.  
  71.   // Add any other code for your system requirements here
  72.  
  73.   delay(100); // Adjust the delay time as per your requirement
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement