Top 5 Arduino Robot Projects for Beginners (With Code & Circuit)



Top 5 Arduino Robot Projects for Beginners (With Code & Circuit)

Robotics is the gateway that gets most people hooked on electronics. These 5 projects start with the classic line-follower and progress to a Bluetooth-controlled car and voice-controlled robot — each one building skills that carry into the next. All use the L298N motor driver and common components available on every electronics site.

Project 1 — Line Follower Robot

Project Description

The classic beginner robot — it follows a black line on a white surface using two IR reflectance sensors. When both sensors are on white it goes straight; when the left sensor hits black it turns left; when the right sensor hits black it turns right. Simple, fast, and satisfying to watch. Great for school competitions.

Components: Arduino Uno, L298N motor driver module, 2 × DC gear motors with wheels, 2 × IR reflectance sensors (TCRT5000), chassis, 9V battery, breadboard, jumper wires.

Circuit Description

ComponentConnectionArduino Pin
Left IR sensorOUTPin 2
Right IR sensorOUTPin 3
L298N IN1Left motor forwardPin 8
L298N IN2Left motor backwardPin 9
L298N IN3Right motor forwardPin 10
L298N IN4Right motor backwardPin 11
L298N ENA/ENBSpeed (PWM)Pins 5, 6

Code

#define LEFT_IR  2
#define RIGHT_IR 3
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
#define ENA 5
#define ENB 6

#define SPEED 160

void forward()    { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void turnLeft()   { digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void turnRight()  { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); }
void stopMotors() { digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);digitalWrite(IN3,LOW); digitalWrite(IN4,LOW); }

void setup() {
  pinMode(LEFT_IR, INPUT); pinMode(RIGHT_IR, INPUT);
  for (int p : {IN1,IN2,IN3,IN4}) pinMode(p, OUTPUT);
  analogWrite(ENA, SPEED); analogWrite(ENB, SPEED);
}

void loop() {
  bool L = digitalRead(LEFT_IR) == LOW;  // LOW = black line detected
  bool R = digitalRead(RIGHT_IR) == LOW;

  if (!L && !R)  forward();     // both on white: go straight
  else if (L && !R) turnLeft(); // left on black: turn left
  else if (!L && R) turnRight();// right on black: turn right
  else stopMotors();             // both on black: stop (junction)
}

Conclusion

Line following teaches sensor-driven feedback control — the foundational concept of all robotics. Next step: add a third central sensor for more accurate line tracking, or add a PID controller for smoother cornering.

Project 2 — Obstacle Avoiding Robot

Project Description

An ultrasonic sensor (HC-SR04) mounted on a servo sweeps left and right to detect obstacles. When something is closer than 20cm, the robot stops, looks left and right, then turns towards the clearest path. Mount it on any 2-wheel chassis with the same L298N driver.

Components: Arduino Uno, L298N, 2 × DC motors, HC-SR04 ultrasonic sensor, SG90 servo, chassis, 9V battery.

Circuit Description

HC-SR04Arduino Pin
TRIGPin A0
ECHOPin A1
Servo signalPin 12
Motor pinsSame as Project 1

Code

#include <Servo.h>
#define TRIG A0
#define ECHO A1
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
#define ENA 5
#define ENB 6
#define SERVO_PIN 12

Servo scanServo;
#define SPEED 160
#define STOP_DIST 20

long getDistance() {
  digitalWrite(TRIG, LOW); delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  return pulseIn(ECHO, HIGH) / 58;
}

void forward()   { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void backward()  { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void turnLeft()  { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void turnRight() { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void stop_()     { digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW); }

void setup() {
  Serial.begin(9600);
  pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
  for (int p : {IN1,IN2,IN3,IN4}) pinMode(p, OUTPUT);
  analogWrite(ENA, SPEED); analogWrite(ENB, SPEED);
  scanServo.attach(SERVO_PIN);
  scanServo.write(90); delay(500);
}

void loop() {
  long dist = getDistance();
  Serial.println("Distance: " + String(dist) + " cm");

  if (dist > STOP_DIST) { forward(); return; }

  stop_(); delay(300);
  backward(); delay(400);
  stop_(); delay(200);

  // Scan left
  scanServo.write(0); delay(700);
  long leftDist = getDistance();
  // Scan right
  scanServo.write(180); delay(700);
  long rightDist = getDistance();
  scanServo.write(90); delay(300);

  if (leftDist > rightDist) { turnLeft(); delay(400); }
  else { turnRight(); delay(400); }
  stop_();
}

Conclusion

Obstacle avoidance teaches environment mapping and decision trees — the same logic used in Roombas and warehouse robots. Next step: mount a 360° lidar or multiple ultrasonic sensors to eliminate blind spots.

Project 3 — 3-DOF Robotic Arm

Project Description

Three servo motors form a shoulder, elbow, and wrist joint. Three potentiometers on a handheld controller let you manually position each joint in real time. Moving the pots moves the arm — direct, intuitive, and teaches inverse kinematics concepts in a hands-on way.

Components: Arduino Uno, 3 × SG90 or MG996R servos, 3 × 10kΩ potentiometers, 5V 2A power supply for servos (do not power servos from the Arduino 5V pin), breadboard, jumper wires.

Circuit Description

JointServo Signal PinPot Pin
ShoulderPin 9A0
ElbowPin 10A1
WristPin 11A2

Power all servo VCC wires from the external 5V supply. Connect servo GND and Arduino GND together.

Code

#include <Servo.h>

Servo shoulder, elbow, wrist;
int sPos = 90, ePos = 90, wPos = 90;

void setup() {
  shoulder.attach(9);
  elbow.attach(10);
  wrist.attach(11);
  shoulder.write(sPos); elbow.write(ePos); wrist.write(wPos);
  Serial.begin(9600);
  Serial.println("Robotic Arm Ready");
}

void smoothMove(Servo &s, int &current, int target) {
  // Move servo 1 degree at a time to avoid jerky motion
  while (current != target) {
    current += (target > current) ? 1 : -1;
    s.write(current);
    delay(10);
  }
}

void loop() {
  int rawShoulder = analogRead(A0);
  int rawElbow    = analogRead(A1);
  int rawWrist    = analogRead(A2);

  int targetS = map(rawShoulder, 0, 4095, 0, 180);
  int targetE = map(rawElbow,    0, 4095, 0, 180);
  int targetW = map(rawWrist,    0, 4095, 0, 180);

  smoothMove(shoulder, sPos, targetS);
  smoothMove(elbow,    ePos, targetE);
  smoothMove(wrist,    wPos, targetW);

  Serial.printf("S:%d E:%d W:%d\n", sPos, ePos, wPos);
  delay(20);
}

Conclusion

Robotic arms teach servo control, mechanical linkage, and the basics of kinematic chains. Next step: record a sequence of pot positions to memory and play it back automatically — that's how industrial robot arms are taught their repetitive tasks.

Project 4 — Bluetooth Remote Control Car

Project Description

Control a 2-wheel robot car from your phone using a free Bluetooth controller app (like "Arduino Bluetooth Controller"). The HC-05 module receives commands ('F', 'B', 'L', 'R', 'S') and the Arduino drives the motors accordingly. Range is about 10 metres — plenty for indoor use.

Components: Arduino Uno, HC-05 Bluetooth module, L298N motor driver, 2 × DC gear motors, chassis, 9V battery.

Circuit Description

HC-05Arduino
TXPin 0 (RX)
RXPin 1 (TX) via 1kΩ + 2kΩ divider
VCC5V
GNDGND

The HC-05 RX pin is 3.3V tolerant — use a 1kΩ/2kΩ voltage divider from Arduino TX to bring it from 5V to ~3.3V. Motor wiring is the same as Projects 1 and 2.

Code

#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
#define ENA 5
#define ENB 6
#define SPEED 200

void fwd()   { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void bwd()   { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void left()  { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void right() { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void stop_() { digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW); }

void setup() {
  Serial.begin(9600); // HC-05 default baud
  for (int p : {IN1,IN2,IN3,IN4}) pinMode(p, OUTPUT);
  analogWrite(ENA, SPEED); analogWrite(ENB, SPEED);
}

void loop() {
  if (!Serial.available()) return;
  char cmd = Serial.read();
  switch (cmd) {
    case 'F': fwd();   break;
    case 'B': bwd();   break;
    case 'L': left();  break;
    case 'R': right(); break;
    default:  stop_(); break;
  }
}

Conclusion

Bluetooth serial control is the gateway to wireless robotics. Next step: upgrade to ESP32 Bluetooth Classic (same HC-05 protocol but no separate module), or switch to BLE for lower power and longer range.

Project 5 — Voice-Controlled Robot

Project Description

Control the robot with spoken commands using a smartphone's Google voice recognition and a Bluetooth connection. Say "forward", "backward", "left", "right", or "stop" into the Arduino Bluetooth Controller app — the recognised text is sent to the Arduino which drives the motors. No internet needed; recognition runs entirely on the phone.

Components: Arduino Uno (or ESP32 with built-in BT), HC-05 Bluetooth module, L298N, 2 × DC motors, chassis, 9V battery.

Circuit Description

Identical to Project 4. The only difference is in the code — string commands instead of single characters.

Code

#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
#define ENA 5
#define ENB 6

void fwd()   { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void bwd()   { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void left()  { digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW); }
void right() { digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH); }
void stop_() { for(int p:{IN1,IN2,IN3,IN4}) digitalWrite(p,LOW); }

void setup() {
  Serial.begin(9600);
  for (int p : {IN1,IN2,IN3,IN4,ENA,ENB}) pinMode(p, OUTPUT);
  analogWrite(ENA, 200); analogWrite(ENB, 200);
}

String cmd = "";
void loop() {
  while (Serial.available()) {
    char c = Serial.read();
    if (c == '\n') {
      cmd.trim(); cmd.toLowerCase();
      Serial.println("CMD: " + cmd);
      if      (cmd == "forward")  fwd();
      else if (cmd == "backward") bwd();
      else if (cmd == "left")     left();
      else if (cmd == "right")    right();
      else if (cmd == "stop")     stop_();
      cmd = "";
    } else { cmd += c; }
  }
}

Conclusion

Combining voice recognition, wireless communication, and motor control in one project is impressive at any level. Next step: add a distance sensor so the robot automatically stops if it's about to hit something, regardless of voice commands — a safety override that mimics real autonomous vehicle systems.


More ESP32 & Arduino Project Guides

Post a Comment

0 Comments