Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Proximity Detection"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-04-25 23:29:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Utilizes an HC-SR04 ultrasonic sensor to sense */
- /* pedestrian proximity, generating a signal for */
- /* system activation. Aims for precise detection and */
- /* reliable performance in smart traffic management */
- /* systems. the traffic light will turn red */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Ultrasonic.h> //https://github.com/ErickSimoes/Ultrasonic
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void checkProximity();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t pedestriansensor_HC-SR04_Echo_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t pedestriansensor_HC-SR04_Trigger_PIN_D2 = 2;
- const uint8_t myLED_LED_PIN_D4 = 4;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool pedestriansensor_HC-SR04_Trigger_PIN_D2_rawData = 0;
- bool myLED_LED_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData = 0.0;
- float myLED_LED_PIN_D4_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the Ultrasonic class
- Ultrasonic ultrasonic(pedestriansensor_HC-SR04_Trigger_PIN_D2, pedestriansensor_HC-SR04_Echo_PIN_D3);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(pedestriansensor_HC-SR04_Echo_PIN_D3, INPUT);
- pinMode(pedestriansensor_HC-SR04_Trigger_PIN_D2, OUTPUT);
- pinMode(myLED_LED_PIN_D4, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- checkProximity(); // Check for pedestrian proximity
- updateOutputs(); // Refresh output data
- }
- void checkProximity()
- {
- // Read distance from the ultrasonic sensor
- pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData = ultrasonic.read();
- // Check if the distance is below a certain threshold (e.g., 50 cm)
- if (pedestriansensor_HC-SR04_Trigger_PIN_D2_phyData < 50) {
- myLED_LED_PIN_D4_rawData = HIGH; // Turn on the LED (traffic light turns red)
- } else {
- myLED_LED_PIN_D4_rawData = LOW; // Turn off the LED
- }
- }
- void updateOutputs()
- {
- digitalWrite(pedestriansensor_HC-SR04_Trigger_PIN_D2, pedestriansensor_HC-SR04_Trigger_PIN_D2_rawData);
- digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement