Advertisement
pleasedontcode

"Proximity Detection" rev_01

Apr 25th, 2025
301
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: "Proximity Detection"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-25 23:29:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilizes an HC-SR04 ultrasonic sensor to sense */
  21.     /* pedestrian proximity, generating a signal for */
  22.     /* system activation. Aims for precise detection and */
  23.     /* reliable performance in smart traffic management */
  24.     /* systems. the traffic light will turn red */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <Ultrasonic.h> //https://github.com/ErickSimoes/Ultrasonic
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs();
  36. void checkProximity();
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t pedestriansensor_HC-SR04_Echo_PIN_D3      = 3;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t pedestriansensor_HC-SR04_Trigger_PIN_D2       = 2;
  43. const uint8_t myLED_LED_PIN_D4      = 4;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool    pedestriansensor_HC-SR04_Trigger_PIN_D2_rawData     = 0;
  48. bool    myLED_LED_PIN_D4_rawData        = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float   pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData     = 0.0;
  53. float   myLED_LED_PIN_D4_phyData        = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. // Create an instance of the Ultrasonic class
  57. Ultrasonic ultrasonic(pedestriansensor_HC-SR04_Trigger_PIN_D2, pedestriansensor_HC-SR04_Echo_PIN_D3);
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.  
  63.     pinMode(pedestriansensor_HC-SR04_Echo_PIN_D3, INPUT);
  64.     pinMode(pedestriansensor_HC-SR04_Trigger_PIN_D2, OUTPUT);
  65.     pinMode(myLED_LED_PIN_D4, OUTPUT);
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // put your main code here, to run repeatedly:
  71.     checkProximity(); // Check for pedestrian proximity
  72.     updateOutputs(); // Refresh output data
  73. }
  74.  
  75. void checkProximity()
  76. {
  77.     // Read distance from the ultrasonic sensor
  78.     pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData = ultrasonic.read();
  79.  
  80.     // Check if the distance is below a certain threshold (e.g., 50 cm)
  81.     if (pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData < 50) {
  82.         myLED_LED_PIN_D4_rawData = HIGH; // Turn on the LED (traffic light turns red)
  83.     } else {
  84.         myLED_LED_PIN_D4_rawData = LOW; // Turn off the LED
  85.     }
  86. }
  87.  
  88. void updateOutputs()
  89. {
  90.     digitalWrite(pedestriansensor_HC-SR04_Trigger_PIN_D2, pedestriansensor_HC-SR04_Trigger_PIN_D2_rawData);
  91.     digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData);
  92. }
  93.  
  94. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement