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: Line-Following Robot
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-12-03 03:24:49
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* line followin robot with 2 ir sensor */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Ultrasonic.h>
- #include <Arduino.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t obstacle_detection_sensor_HC-SR04_Echo_PIN_D13 = 13;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t obstacle_detection_sensor_HC-SR04_Trigger_PIN_D4 = 4;
- // Create Ultrasonic object
- Ultrasonic ultrasonicTrigger(obstacle_detection_sensor_HC-SR04_Trigger_PIN_D4, obstacle_detection_sensor_HC-SR04_Echo_PIN_D13);
- // IR sensors for line follow
- const uint8_t IR_left_SENSOR_PIN = 14;
- const uint8_t IR_right_SENSOR_PIN = 15;
- void setup(void) {
- pinMode(IR_left_SENSOR_PIN, INPUT);
- pinMode(IR_right_SENSOR_PIN, INPUT);
- Serial.begin(9600);
- }
- void loop(void) {
- int IR_left_state = digitalRead(IR_left_SENSOR_PIN);
- int IR_right_state = digitalRead(IR_right_SENSOR_PIN);
- int distanceCM = ultrasonicTrigger.read();
- int distanceIN = ultrasonicTrigger.read(INC);
- // Determine movement based on IR sensors
- if (IR_left_state == LOW && IR_right_state == LOW) {
- // Both sensors on line, go forward
- Serial.println("Moving forward");
- } else if (IR_left_state == LOW && IR_right_state == HIGH) {
- // Turn right
- Serial.println("Turning right");
- } else if (IR_left_state == HIGH && IR_right_state == LOW) {
- // Turn left
- Serial.println("Turning left");
- } else {
- // No line detected, stop or search
- Serial.println("Searching for line");
- }
- // Print ultrasonic distances
- Serial.print("Distance CM: ");
- Serial.println(distanceCM);
- Serial.print("Distance IN: ");
- Serial.println(distanceIN);
- delay(100);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment