Building a Four-in-One Arduino Robot

This project demonstrates how to build a four-in-one multifunctional robot using an Arduino Uno. The robot is capable of operating in four different modes:

 

Line Following

Obstacle Avoidance

Combined Line Following and Obstacle Avoidance

Object Following

 

By integrating multiple sensors and an L298N motor driver module, this project is a great learning experience for robotics and automation enthusiasts.

 

 

 

Components and Supplies


 

Immagine

 

4WD Car Chassis Kit - BUY NOW

 


L298N Motor Driver Module - BUY NOW

 

 

Jumper-Wires - BUY NOW

 

 

 

7-12 V DC Battery (in our case lipo 2s battery)

 

 

 

1 Arduino Uno - Buy Now

 

 

 

1 Breadboard - Buy Now

 

 

1 Ultrasonic Sensor - Buy Now

 

 

 

1 Servo Motor (SG90) - BUY NOW

 

 

 

 

Step 1: Circuit Connections

 

Arduino to L298N Motor Driver

Motor A (Left Wheels) → L298N OUT1 & OUT2

Motor B (Right Wheels) → L298N OUT3 & OUT4

L298N IN1, IN2 → Arduino Digital Pins 5, 6

L298N IN3, IN4 → Arduino Digital Pins 9, 10

L298N VCC → 12V Battery

L298N GND → Common GND with Arduino

L298N 5V Output → Arduino 5V

 

IR Sensors to Arduino

Left IR Sensor → A0

Right IR Sensor → A1

Additional IR Sensors for obstacle detection → A2, A3

 

Ultrasonic Sensor to Arduino

Trig Pin → Digital Pin 7

Echo Pin → Digital Pin 8

 

Servo Motor to Arduino

Signal Pin → Digital Pin 3

VCC → 5V

GND → GND

 

 

Step 2: Upload the Code

Use the Arduino IDE to upload the code. Ensure you have installed the NewPing library for ultrasonic sensor functionality.

 

Key Code Features:

Mode Selection: Line Following, Obstacle Avoidance, Combined Mode, and Object Following.

Motor Control Functions: rotateMotor() handles speed and direction.

Sensor Calibration: Adjust IR sensor sensitivity.

Servo and Ultrasonic Integration: Moves sensor to detect objects dynamically.

 

 

Step 3: Testing and Calibration

Calibrate IR Sensors: Ensure they properly detect lines.

Adjust Motor Speed: Modify PWM values if needed.

Battery Considerations: Use a LiPo battery for stable operation.

Fine-tune Ultrasonic Sensor Positioning: Adjust servo angles for better detection.

 

CODE
#include <NewPing.h>
#define TRIG_PIN 7
#define ECHO_PIN 8
#define MAX_DISTANCE 200
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

#define IN1 5
#define IN2 6
#define IN3 9
#define IN4 10

void setup() {
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
}

void loop() {
    int distance = sonar.ping_cm();
    if (distance > 0 && distance < 20) {
        avoidObstacle();
    } else {
        followLine();
    }
}

void avoidObstacle() {
    // Logic for obstacle avoidance
}

void followLine() {
    // Logic for line following
}
}
License
All Rights
Reserved
licensBg
0