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: **Obstacle Detection**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-20 13:49:48
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* when Ir sensor will detect any obstracle then led */
- /* will blink for 5 seasond */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t IRsensorInfraredsensor_LED_PIN_D2 = 2;
- const uint8_t LED1 = 13; // Added LED pins
- const uint8_t LED2 = 12;
- const uint8_t LED3 = 11;
- const uint8_t IR1 = 2; // Note: This conflicts with IRsensorInfraredsensor_LED_PIN_D2
- const uint8_t IR2 = 3;
- const uint8_t IR3 = 4;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool IRsensorInfraredsensor_LED_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float IRsensorInfraredsensor_LED_PIN_D2_phyData = 0.0;
- // Variables for obstacle detection
- int val1 = 0;
- int val2 = 0;
- int val3 = 0;
- unsigned long previousMillis = 0; // to track the time for LED blinking
- const long interval = 500; // interval for blinking (500ms)
- const long delayTime = 5000; // Delay for 5 seconds (5000ms)
- bool obstacleDetected = false; // Flag for obstacle detection
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(IRsensorInfraredsensor_LED_PIN_D2, OUTPUT);
- pinMode(IR1, INPUT); // Setup for IR sensors
- pinMode(IR2, INPUT);
- pinMode(IR3, INPUT);
- pinMode(LED1, OUTPUT); // Setup for LEDs
- pinMode(LED2, OUTPUT);
- pinMode(LED3, OUTPUT);
- Serial.begin(9600); // Initialize serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Read IR sensor values
- val1 = digitalRead(IR1);
- val2 = digitalRead(IR2);
- val3 = digitalRead(IR3);
- // Check for obstacle detection
- if (val1 == 0 || val2 == 0 || val3 == 0) {
- obstacleDetected = true; // Set flag if any IR sensor detects an obstacle
- previousMillis = millis(); // Reset the timer for blinking
- }
- // Blink LEDs for 5 seconds if an obstacle is detected
- if (obstacleDetected) {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis < delayTime) {
- // Blink LED1
- if ((currentMillis / interval) % 2 == 0) {
- digitalWrite(LED1, HIGH);
- digitalWrite(LED2, HIGH);
- digitalWrite(LED3, HIGH);
- } else {
- digitalWrite(LED1, LOW);
- digitalWrite(LED2, LOW);
- digitalWrite(LED3, LOW);
- }
- } else {
- // Reset the flag after 5 seconds
- obstacleDetected = false;
- digitalWrite(LED1, LOW);
- digitalWrite(LED2, LOW);
- digitalWrite(LED3, LOW);
- }
- } else {
- // Turn off LEDs if no obstacle is detected
- digitalWrite(LED1, LOW);
- digitalWrite(LED2, LOW);
- digitalWrite(LED3, LOW);
- }
- delay(10); // Small delay for stability
- }
- void updateOutputs()
- {
- digitalWrite(IRsensorInfraredsensor_LED_PIN_D2, IRsensorInfraredsensor_LED_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement