Free Tutorials

Arduino & Robotics Tutorials

Learn by building. Follow simple, step-by-step tutorials and bring your ideas to life.

9 Projects
3 Difficulty Levels
100% Free to Learn
💡

How to use these tutorials

Choose a project below to open its complete tutorial. Each project includes the required components, wiring, Arduino code, step-by-step instructions, testing, and troubleshooting.

All Projects

🚦
⭐ Beginner Arduino

Arduino Traffic Light

Build a working traffic light system and learn how Arduino controls multiple digital outputs with timing.

📡
⭐⭐ Easy Arduino

Arduino Ultrasonic Distance Meter

Measure distance with an HC-SR04 ultrasonic sensor and display the result on an LCD.

🔐
⭐⭐ Easy Arduino

Arduino Keypad Door Lock

Build a password-controlled lock using a 4×4 keypad and SG90 servo motor.

🤖
⭐⭐⭐ Intermediate Robotics

Arduino Obstacle Avoiding Robot

Build a robot that detects obstacles using an ultrasonic sensor and controls its motors through an L298 driver.

📱
⭐⭐⭐ Intermediate Robotics

Bluetooth Controlled Car

Control a 4-wheel robot car from a phone using the HC-05 Bluetooth module.

🌱
⭐⭐ Easy Arduino

Automatic Plant Watering System

Use a capacitive soil moisture sensor to detect dry soil and automatically activate a small water pump.

🗑️
⭐⭐ Easy Arduino

Arduino Automatic Dustbin

Build a touchless dustbin that opens its lid when your hand approaches.

🎮
⭐⭐ Easy Arduino

Joystick Controlled Servo

Control the position of an SG90 servo motor using the X-axis of an Arduino joystick module.

💡
⭐⭐ Easy Automation

Motion Activated Light

Use a PIR motion sensor and relay module to automatically switch a low-voltage load on when movement is detected.

📋

Every tutorial follows the same structure

Project Overview → What You'll Need → What You'll Learn → How It Works → Wiring → Arduino Code → Step-by-Step Instructions → Testing → Troubleshooting → Components Used

Ready to start building?

Get the individual components you need for your next project from Robo.pk.

🚦

Arduino Traffic Light

⭐ Beginner Arduino

Project Overview

In this project, you'll build a simple traffic light using an Arduino and a traffic light module. The Arduino will turn the red, yellow and green LEDs on and off in sequence.

What You'll Need

  • Arduino UNO R3
  • 5V LED Traffic Light Module
  • 400-hole breadboard
  • Jumper wires

How It Works

Each LED on the traffic light module is connected to a digital output. Arduino activates one light at a time using digitalWrite() and waits between each change using delay().

Wiring

Traffic Light Arduino
Red D8
Yellow D9
Green D10
GND GND

Arduino Code

const int RED = 8; const int YELLOW = 9; const int GREEN = 10; void setup() { pinMode(RED, OUTPUT); pinMode(YELLOW, OUTPUT); pinMode(GREEN, OUTPUT); } void loop() { digitalWrite(RED, HIGH); delay(5000); digitalWrite(RED, LOW); digitalWrite(GREEN, HIGH); delay(5000); digitalWrite(GREEN, LOW); digitalWrite(YELLOW, HIGH); delay(2000); digitalWrite(YELLOW, LOW); }

Step-by-Step

  1. Connect the traffic light module to the Arduino.
  2. Connect the module ground to Arduino GND.
  3. Upload the code.
  4. The red light should turn on first.
  5. The green light will then turn on.
  6. Finally, the yellow light will turn on before the cycle repeats.

Testing

If the lights change in the correct sequence, your project is working. You can experiment with the delay times to create a faster or slower traffic-light cycle.

Troubleshooting

  • Check that GND is connected correctly.
  • Make sure the LED control wires are connected to the correct pins.
  • Verify that the code uploaded successfully.
↑ Back to all tutorials
📡

Arduino Ultrasonic Distance Meter

⭐⭐ Easy Arduino

Project Overview

Build a simple distance meter using an HC-SR04 ultrasonic sensor. The measured distance will be displayed on an I2C LCD.

What You'll Need

  • Arduino UNO R3
  • HC-SR04 Ultrasonic Sensor
  • 16×2 LCD with I2C
  • 400-hole breadboard
  • Jumper wires

How It Works

The HC-SR04 sends an ultrasonic pulse and measures how long it takes for the echo to return. Arduino converts this time into distance.

Wiring

HC-SR04 Arduino
VCC 5V
GND GND
TRIG D9
ECHO D10

LCD I2C Arduino UNO
VCC 5V
GND GND
SDA A4
SCL A5

Arduino Code

#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); const int trigPin = 9; const int echoPin = 10; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Distance Meter"); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); float distance = duration * 0.0343 / 2; lcd.setCursor(0, 1); lcd.print("Distance: "); lcd.setCursor(10, 1); lcd.print(distance, 1); lcd.print("cm"); delay(500); }

Step-by-Step

  1. Connect the HC-SR04 to the Arduino.
  2. Connect the LCD through its I2C pins.
  3. Install the LiquidCrystal_I2C library.
  4. Upload the code.
  5. Place an object in front of the ultrasonic sensor.
  6. The LCD should display the approximate distance.

Troubleshooting

  • If the LCD is blank, adjust the small contrast potentiometer on the I2C module.
  • If the LCD doesn't respond, check the I2C address. Some modules use 0x3F instead of 0x27.
  • Check TRIG and ECHO connections carefully.
↑ Back to all tutorials
🔐

Arduino Keypad Door Lock

⭐⭐ Easy Arduino

Project Overview

Build a simple electronic lock using a 4×4 matrix keypad and an SG90 servo motor. The servo unlocks when the correct password is entered.

What You'll Need

  • Arduino UNO R3
  • 4×4 Matrix Keypad
  • SG90 Servo Motor
  • Jumper wires

Wiring

Component Arduino
Keypad Row 1–4 D2–D5
Keypad Column 1–4 D6–D9
Servo Signal D10
Servo VCC 5V
Servo GND GND

Arduino Code

#include <Keypad.h> #include <Servo.h> const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {2, 3, 4, 5}; byte colPins[COLS] = {6, 7, 8, 9}; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); Servo lockServo; String password = "1234"; String entered = ""; void setup() { lockServo.attach(10); lockServo.write(0); } void loop() { char key = keypad.getKey(); if (key) { if (key == '#') { if (entered == password) { lockServo.write(90); delay(3000); lockServo.write(0); } entered = ""; } else if (key == '*') { entered = ""; } else { entered += key; } } }

Step-by-Step

  1. Connect the keypad rows and columns.
  2. Connect the SG90 servo signal wire to D10.
  3. Install the Keypad library.
  4. Upload the code.
  5. Enter 1234 followed by #.
  6. The servo should move to the unlocked position.

Testing

Try entering an incorrect password. The servo should remain locked. Then enter 1234 followed by # and check that the servo moves.

Troubleshooting

  • Check the keypad row and column order.
  • Make sure the servo has a common ground with Arduino.
  • Check that the Keypad library is installed.
↑ Back to all tutorials
🤖

Arduino Obstacle Avoiding Robot

⭐⭐⭐ Intermediate Robotics

Project Overview

Build a robot that drives forward and automatically changes direction when it detects an obstacle in front of it.

What You'll Need

  • Arduino UNO R3
  • HC-SR04 Ultrasonic Sensor
  • L298 Motor Driver
  • 4-Wheel Robot Car Chassis

How It Works

The ultrasonic sensor continuously measures the distance in front of the robot. When the robot gets too close to an obstacle, Arduino tells the motor driver to change the robot's movement.

Basic Wiring

Component Arduino
HC-SR04 TRIG D2
HC-SR04 ECHO D3
L298 IN1 D5
L298 IN2 D6
L298 IN3 D9
L298 IN4 D10
Keep the ENA and ENB enable jumpers installed on the L298 module so both motor channels are enabled. If your module does not have jumpers installed, make sure ENA and ENB are correctly enabled according to the module's pinout. Motor power should come from an appropriate external motor power source. Do not try to power the robot motors directly from an Arduino GPIO pin.

Arduino Code

const int trigPin = 2; const int echoPin = 3; const int IN1 = 5; const int IN2 = 6; const int IN3 = 9; const int IN4 = 10; long getDistance() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); return duration * 0.0343 / 2; } void forward() { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); } void stopRobot() { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); } void turnRight() { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); } void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); } void loop() { long distance = getDistance(); if (distance > 20 || distance == 0) { forward(); } else { stopRobot(); delay(200); turnRight(); delay(500); } }

Step-by-Step

  1. Assemble the 4-wheel chassis.
  2. Connect the motors to the L298 driver.
  3. Connect the L298 control pins to Arduino.
  4. Mount the HC-SR04 at the front of the robot.
  5. Upload the code.
  6. Place the robot on the floor.
  7. Place an object in front of it and watch the robot turn away.

Troubleshooting

  • If the robot moves backward, swap the motor polarity.
  • If only one side moves, check the motor-driver connections.
  • If the robot doesn't detect obstacles, check TRIG and ECHO.
  • Make sure the motor supply is adequate.
↑ Back to all tutorials
📱

Bluetooth Controlled Car

⭐⭐⭐ Intermediate Robotics

Project Overview

Control a 4-wheel robot car wirelessly from a smartphone using an HC-05 Bluetooth module.

What You'll Need

Bluetooth Wiring

  • HC-05 VCC → Arduino 5V
  • HC-05 GND → Arduino GND
  • HC-05 TXD → Arduino D10
  • Arduino D11 → HC-05 RXD through a voltage divider

The HC-05 communicates with the Arduino using serial communication. In this setup, D10 is used as the Arduino's SoftwareSerial RX pin and D11 as the SoftwareSerial TX pin. Because the HC-05 RX pin is a 3.3V logic input, use a voltage divider between Arduino D11 and HC-05 RXD.

How It Works

The phone sends simple commands over Bluetooth. Arduino receives the characters and uses them to control the L298 motor driver.

Example Commands

  • F = Forward
  • B = Backward
  • L = Left
  • R = Right
  • S = Stop

Arduino Code

#include <SoftwareSerial.h> SoftwareSerial bluetooth(10, 11); const int IN1 = 5; const int IN2 = 6; const int IN3 = 9; const int IN4 = 12; void stopCar() { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); } 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 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 setup() { bluetooth.begin(9600); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); stopCar(); } void loop() { if (bluetooth.available()) { char command = bluetooth.read(); if (command == 'F') forward(); if (command == 'B') backward(); if (command == 'L') left(); if (command == 'R') right(); if (command == 'S') stopCar(); } }

Step-by-Step

  1. Build the 4-wheel chassis.
  2. Connect the motors to the L298 driver.
  3. Connect the L298 control pins to Arduino.
  4. Connect the HC-05 module to Arduino as follows:
    • HC-05 TX → Arduino D10 (SoftwareSerial RX)
    • HC-05 RX → Arduino D11 (SoftwareSerial TX) through an appropriate voltage divider or level-shifting arrangement
    • HC-05 VCC → appropriate supply for your HC-05 module
    • HC-05 GND → Arduino GND
  5. Pair your phone with the HC-05.
  6. Use a Bluetooth terminal/controller app to send commands.
  7. Test forward, backward, left, right and stop.
Bluetooth module wiring and power should be checked carefully before powering the circuit. The HC-05 is a serial Bluetooth module and communicates with Arduino through UART. Because the HC-05 RX input is typically not 5V tolerant, use an appropriate voltage divider or level-shifting arrangement between Arduino D11 and HC-05 RX.
↑ Back to all tutorials
🌱

Automatic Plant Watering System

⭐⭐ Easy Arduino

Project Overview

Build a simple automatic plant watering system. Arduino checks the soil moisture and activates a small water pump when the soil becomes dry.

What You'll Need

  • Arduino UNO R3
  • Capacitive Soil Moisture Sensor
  • 1 Channel Relay
  • Mini Submersible Water Pump

How It Works

The moisture sensor provides Arduino with a reading related to soil moisture. When the reading indicates dry soil, Arduino activates the relay, which switches the pump on.

Wiring

Soil Sensor Arduino
VCC 5V
GND GND
AOUT A0

Relay Arduino
VCC 5V
GND GND
IN D7

For the pump circuit, connect the external pump power supply positive terminal to the relay COM terminal. Connect the relay NO terminal to the pump positive terminal. Connect the pump negative terminal directly to the external power supply negative terminal. Use an external supply suitable for your pump's voltage and current.

The water pump should use a suitable external power supply. Do not power the pump directly from an Arduino GPIO pin.

Arduino Code

const int moisturePin = A0; const int relayPin = 7; const int dryThreshold = 650; void setup() { Serial.begin(9600); pinMode(relayPin, OUTPUT); digitalWrite(relayPin, HIGH); } void loop() { int moisture = analogRead(moisturePin); Serial.println(moisture); if (moisture > dryThreshold) { digitalWrite(relayPin, LOW); } else { digitalWrite(relayPin, HIGH); } delay(1000); }

Step-by-Step

  1. Connect the capacitive moisture sensor to A0.
  2. Connect the relay input to D7.
  3. Connect the pump through the relay's switching terminals as described above.
  4. Connect the pump to a suitable external power supply.
  5. Upload the code.
  6. Open Serial Monitor and observe the moisture readings.
  7. Adjust the dry threshold according to your soil and sensor.

Troubleshooting

  • Use Serial Monitor to see your sensor's actual readings.
  • The threshold in the example may need adjustment.
  • If the relay behaves backwards, check whether your module is active LOW.
  • Make sure the pump has its own suitable power source.
↑ Back to all tutorials
🗑️

Arduino Automatic Dustbin

⭐⭐ Easy Arduino

Project Overview

Build a touchless dustbin that automatically opens when an object approaches the ultrasonic sensor.

What You'll Need

  • Arduino UNO R3
  • HC-SR04 Ultrasonic Sensor
  • SG90 Servo Motor

How It Works

The HC-SR04 measures the distance to your hand. If your hand comes within a set distance, Arduino rotates the servo to open the lid.

Wiring

Component Arduino
HC-SR04 TRIG D7
HC-SR04 ECHO D8
Servo Signal D9
VCC 5V
GND GND

Arduino Code

#include <Servo.h> Servo lidServo; const int trigPin = 7; const int echoPin = 8; const int servoPin = 9; long getDistance() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); return duration * 0.0343 / 2; } void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); lidServo.attach(servoPin); lidServo.write(0); } void loop() { long distance = getDistance(); if (distance > 0 && distance < 20) { lidServo.write(90); delay(3000); lidServo.write(0); } delay(200); }

Step-by-Step

  1. Mount the servo so it can move the lid.
  2. Mount the ultrasonic sensor near the top/front of the bin.
  3. Connect the sensor and servo to Arduino.
  4. Upload the code.
  5. Move your hand within approximately 20 cm of the sensor.
  6. The lid should open and then close automatically.

Troubleshooting

  • Adjust the 20 cm detection distance in the code.
  • Make sure the servo has a common ground with Arduino.
  • If the lid moves in the wrong direction, change the servo angles.
↑ Back to all tutorials
🎮

Joystick Controlled Servo

⭐⭐ Easy Arduino

Project Overview

Learn how analog input works by using an Arduino joystick to control the angle of an SG90 servo motor.

What You'll Need

  • Arduino UNO R3
  • PS2 Joystick Module
  • SG90 Servo Motor

How It Works

The joystick's X-axis produces an analog value between approximately 0 and 1023. Arduino maps this value to a servo angle between 0 and 180°.

Wiring

Joystick Arduino
VCC 5V
GND GND
VRx A0

Servo Arduino
Signal D9
VCC 5V
GND GND

Arduino Code

#include <Servo.h> Servo myServo; const int joystickX = A0; const int servoPin = 9; void setup() { myServo.attach(servoPin); } void loop() { int joystickValue = analogRead(joystickX); int angle = map( joystickValue, 0, 1023, 0, 180 ); myServo.write(angle); delay(10); }

Step-by-Step

  1. Connect the joystick's VRx output to A0.
  2. Connect the servo signal to D9.
  3. Connect the grounds together.
  4. Upload the code.
  5. Move the joystick left and right.
  6. The servo should follow the joystick position.

What You'll Learn

  • Analog inputs
  • Analog-to-digital conversion
  • Mapping values
  • Servo control
↑ Back to all tutorials
💡

Motion Activated Light

⭐⭐ Easy Automation

Project Overview

Build a simple motion-triggered automation system using a PIR sensor and a relay. When movement is detected, Arduino activates the relay.

What You'll Need

  • Arduino UNO R3
  • HC-SR501 PIR Motion Sensor
  • 1 Channel Relay
  • A suitable low-voltage load for testing
For a beginner project, test this with a low-voltage DC load. Do not connect household mains electricity unless you know how to work safely with mains wiring and the required electrical protection.

How It Works

The PIR sensor outputs a HIGH signal when it detects movement. Arduino reads that signal and switches the relay accordingly.

Wiring

PIR Sensor Arduino
VCC 5V
GND GND
OUT D2

Relay Arduino
VCC 5V
GND GND
IN D7

Arduino Code

const int pirPin = 2; const int relayPin = 7; void setup() { pinMode(pirPin, INPUT); pinMode(relayPin, OUTPUT); digitalWrite(relayPin, HIGH); } void loop() { int motion = digitalRead(pirPin); if (motion == HIGH) { digitalWrite(relayPin, LOW); } else { digitalWrite(relayPin, HIGH); } }

Step-by-Step

  1. Connect the PIR sensor to Arduino.
  2. Connect the relay input to D7.
  3. Connect a suitable low-voltage load to the relay.
  4. Upload the code.
  5. Allow the PIR sensor a short time to initialize.
  6. Move in front of the sensor.
  7. The relay should activate.

Troubleshooting

  • PIR sensors can take several seconds to stabilize after power-up.
  • Adjust the PIR sensitivity and delay controls if needed.
  • If the relay works backwards, your relay module may use active-LOW logic.
↑ Back to all tutorials