Embed presentation
Download to read offline




















#Arduino UNO code # Summary of the Code: This Arduino code is for a **line-following robot** that can follow complex paths, make decisions, and avoid obstacles using various sensors. Here's a breakdown of the key features and functionality: #### 1. **Hardware Components**: - **5 Line Sensors**: Detect the path (leftmost, left, center, right, rightmost). - **2 DC Motors**: Control the robot’s movement (forward, backward, left turn, right turn). - **Ultrasonic Sensor**: Used for obstacle detection (measures distance). #### 2. **Sensor Logic**: - The robot uses the **5 line sensors** to determine its position on the track. Based on which sensors detect the line, it decides whether to go straight, turn left, or turn right. - If the robot loses the line (both sides off the track), it searches for the line again by moving forward and checking the sensors. #### 3. **Path Decision**: - The robot continuously reads the sensor values and uses simple logic to decide its next action: - **Centered on the line**: Move forward. - **Left off the line**: Turn right. - **Right off the line**: Turn left. - **Both sides off the track**: Search for the line. #### 4. **Obstacle Avoidance**: - The robot uses an **ultrasonic sensor** to detect obstacles in front of it. If an obstacle is detected within a certain distance (e.g., 20 cm), the robot stops, moves backward, and turns to avoid it. #### 5. **Movement Functions**: - The robot has several movement functions: - **Forward**: Move straight. - **Backward**: Move in reverse. - **Left/Right Turn**: Make sharp turns. - **Stop**: Stop the motors. #### 6. **Timing**: - The main loop runs continuously, checking sensor values and making decisions at regular intervals (every 50ms). #### 7. **PID Control** (Optional, not fully implemented): - The code includes placeholders for a **PID control** system, which can be used to make smoother and more accurate corrections while following the line. ### Key Functionalities: - **Line Following**: The robot follows the track based on sensor inputs. - **Decision-Making**: The robot chooses the correct path based on sensor readings. - **Obstacle Avoidance**: The robot detects and avoids obstacles using an ultrasonic sensor. - **Error Recovery**: The robot can recover if it goes off the track by searching for the line. This code provides a robust foundation for a line-following robot capable of handling complex tracks and obstacles, with the potential for further improvements like advanced PID control and better obstacle avoidance. Building a line-following robot based on the Arduino code requires assembling the hardware components, wiring them together, and ensuring that the robot can follow a track while avoiding obstacles. Below are the steps to build the robot: --- ### **Components Needed:** 1. **Arduino Board** (e.g., Arduino Uno) 2. **2 DC Motors** with motor drivers (e.g., L298N or L293D) 3. **5 IR



















