Imagine a shopping cart that can move on its own — following a path, avoiding obstacles, and reaching you when needed. In this project, we’ll build a Smart Shopping Cart Robot using Arduino UNO, IR sensors, and ultrasonic sensors. This robot combines line-following and obstacle avoidance to move safely and intelligently, just like a real self-driving cart in a smart store.
This project is simple, low-cost, and an excellent choice for beginners and final-year students who want to explore Arduino robotics and sensor-based automation.
The smart shopping cart robot works using two main modules:
Line Following System:
Two IR sensors detect the black line on a white surface. When the left or right sensor detects the line, the robot adjusts its direction to stay centered.
Obstacle Avoidance System:
Two ultrasonic sensors in the front continuously measure the distance from obstacles. If any object is detected within 20 cm, the robot stops, moves backward, and then turns to avoid the obstacle before continuing forward.
The motors are driven by an L298N motor driver, and both IR and ultrasonic sensors are powered by the Arduino board.
Arduino UNO
L298N Motor Driver
2x DC Gear Motors
2x IR Line Sensors
2x Ultrasonic Sensors (HC-SR04)
Robot chassis, jumper wires, 9–12V battery
Left IR → D2
Right IR → D3
Left Ultrasonic (Trig D4, Echo D5)
Right Ultrasonic (Trig D6, Echo D7)
L298N IN1→D8, IN2→D9, ENA→D10
L298N IN3→D11, IN4→D12, ENB→D13
// Smart Shopping Cart Robot – Line Follower + Obstacle Avoidance
// Created by Incredible Technology
#define LINE_LEFT 2
#define LINE_RIGHT 3
#define USL_TRIG 4
#define USL_ECHO 5
#define USR_TRIG 6
#define USR_ECHO 7
#define LM_EN 10
#define LM_IN1 8
#define LM_IN2 9
#define RM_EN 13
#define RM_IN1 11
#define RM_IN2 12
const int OBSTACLE_DISTANCE = 20; // cm
const int SPEED_FWD = 150; // Normal motor speed
const int SPEED_TURN = 160;
const int SPEED_BACK = 150;
void setup() {
pinMode(LINE_LEFT, INPUT);
pinMode(LINE_RIGHT, INPUT);
pinMode(USL_TRIG, OUTPUT);
pinMode(USL_ECHO, INPUT);
pinMode(USR_TRIG, OUTPUT);
pinMode(USR_ECHO, INPUT);
pinMode(LM_EN, OUTPUT);
pinMode(LM_IN1, OUTPUT);
pinMode(LM_IN2, OUTPUT);
pinMode(RM_EN, OUTPUT);
pinMode(RM_IN1, OUTPUT);
pinMode(RM_IN2, OUTPUT);
Serial.begin(9600);
}
long distance(int trig, int echo) {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long duration = pulseIn(echo, HIGH, 30000);
return duration * 0.034 / 2;
}
void moveForward() {
digitalWrite(LM_IN1, HIGH);
digitalWrite(LM_IN2, LOW);
digitalWrite(RM_IN1, HIGH);
digitalWrite(RM_IN2, LOW);
analogWrite(LM_EN, SPEED_FWD);
analogWrite(RM_EN, SPEED_FWD);
}
void moveBackward() {
digitalWrite(LM_IN1, LOW);
digitalWrite(LM_IN2, HIGH);
digitalWrite(RM_IN1, LOW);
digitalWrite(RM_IN2, HIGH);
analogWrite(LM_EN, SPEED_BACK);
analogWrite(RM_EN, SPEED_BACK);
}
void turnLeft() {
digitalWrite(LM_IN1, LOW);
digitalWrite(LM_IN2, HIGH);
digitalWrite(RM_IN1, HIGH);
digitalWrite(RM_IN2, LOW);
analogWrite(LM_EN, SPEED_TURN);
analogWrite(RM_EN, SPEED_TURN);
}
void turnRight() {
digitalWrite(LM_IN1, HIGH);
digitalWrite(LM_IN2, LOW);
digitalWrite(RM_IN1, LOW);
digitalWrite(RM_IN2, HIGH);
analogWrite(LM_EN, SPEED_TURN);
analogWrite(RM_EN, SPEED_TURN);
}
void stopMotors() {
digitalWrite(LM_IN1, LOW);
digitalWrite(LM_IN2, LOW);
digitalWrite(RM_IN1, LOW);
digitalWrite(RM_IN2, LOW);
}
void loop() {
int left = digitalRead(LINE_LEFT);
int right = digitalRead(LINE_RIGHT);
long distL = distance(USL_TRIG, USL_ECHO);
long distR = distance(USR_TRIG, USR_ECHO);
if (distL < OBSTACLE_DISTANCE || distR < OBSTACLE_DISTANCE) {
stopMotors();
moveBackward();
delay(600);
stopMotors();
delay(200);
if (distL < distR) turnRight();
else turnLeft();
delay(600);
stopMotors();
delay(200);
}
else {
if (left == HIGH && right == HIGH) moveForward();
else if (left == LOW && right == HIGH) turnLeft();
else if (left == HIGH && right == LOW) turnRight();
else stopMotors();
}
}
The Arduino program reads line sensor values to control direction and checks ultrasonic sensors for obstacle detection. When both sensors detect a clear path, the motors move forward. If an obstacle is found, it reverses, turns, and continues following the line. The motor speed is set at a moderate value (150) for smooth, realistic motion.
Smart store or mall automation
Autonomous delivery cart
Educational robotics project
Basic self-driving vehicle prototype
This Smart Shopping Cart Robot is a great beginner project that blends line-following and obstacle detection to create a real-world automation example. With a few modifications — like adding Bluetooth or RFID — you can upgrade it into a fully interactive smart cart. It’s affordable, fun to build, and perfect for Arduino learners!
Arduino, Line Follower, Obstacle Avoidance, Robotics, DIY, Smart Cart, HC-SR04, L298N, IR Sensor, Autonomous Robot
0 Comments