Course · Robotics and AI
From zero to your first robot.
Start with the big picture, then build one small project at a time: a motor, a sensor, a line follower, a robot car, a robot arm, a simulator and finally a robot that learns. No robotics background needed.
Course home
Robotics and AI
From zero to your first robot.
A hands-on robotics course for engineering students who are new to robots. Start with the big picture, then build one small project at a time: motors, sensors, actuators, electronics, control, robot cars and arms, ROS 2 and robots that learn. Every module has a plain explanation, a demo to try on the page, real code and a quick check.
Use the course contents menu or the timeline above to move between modules. Your progress is saved on this device.
The path
Part 1 · The big picture
Part 2 · Build the basics
Part 3 · Modern robotics
Today's toolbox
The platforms robotics runs on
You do not need all of these on day one. The course starts with the beginner tools and works its way up.
Module 01 of 10
What is a robot?
A robot is a machine that senses the world, decides what to do, and moves. Everything else in robotics is detail on those three steps.
Robots come in many shapes, but every one of them runs the same loop, many times a second:
- Sense. Measure the world and itself: distance, light, camera images, wheel turns, tilt.
- Think. Turn those numbers into a decision. It can be one
ifstatement or a neural network. - Act. Drive motors, wheels, grippers or propellers, and the robot moves.
Then the world has changed, so the loop starts again. In this course you build each part of that loop yourself, one small project at a time.
In our robots
Our quadruped runs this loop 50 times a second: 12 joint sensors and a tilt sensor in, a neural network in the middle, 12 motors out. It is the same loop as a two-wheel robot car, just with more of everything.
Try it
Follow one loop
Tap a stage to see what does that job in a simple robot car and in a walking robot.
Kinds of robots
Your project
Find the loop
You need: nothing, just your eyes
- Pick three machines around you: a lift, a washing machine, a traffic signal.
- For each, write what it senses, what it decides and how it acts.
- Which one is closest to a robot? Why?
Quick check
A robot runs its loop 50 times a second. How long is one loop?
1 second ÷ 50 = 0.02 s = 20 ms. Sensing, thinking and acting must all fit in that time.
// Every robot program has the same shape: sense, think, act, repeat
void loop() {
// SENSE: read the world
int distance = readDistanceCm(); // ultrasonic sensor
// THINK: decide
bool blocked = distance < 20; // wall closer than 20 cm?
// ACT: move the motors
if (blocked) {
stopMotors();
} else {
driveForward(150); // speed 0-255
}
delay(20); // run 50 times a second
}Module 02 of 10
Motors and drivers
Motors make robots move. A microcontroller cannot power a motor directly, so a driver sits in between, and a gearbox trades speed for strength.
Three motors cover most student robots:
- DC motor: spins when powered; more voltage, more speed. Good for wheels.
- Servo: a motor with its own sensor and controller; you ask for an angle and it goes there. Good for arms.
- Stepper: moves in exact small steps. Good for 3D printers and plotters.
A driver (such as the L298N) lets a small signal switch a big current. Speed is set with PWM: switching the power on and off very fast, so the motor sees the average.
joint speed = motor speed ÷ gear ratio
In our robots
Our quadruped's joints use a brushless motor and a gearbox. The motor gives 8 to 10 N m at its peak and spins at up to about 400 rad/s; simulations told us the knee needs about 27 N m to walk and over 100 N m to run. The slider uses these numbers.
Try it
Pick a gear ratio
Move the slider. Which jobs can the knee of our quadruped do?

Your project
Spin a motor, sweep a servo
You need: Arduino Uno, L298N driver, DC motor, SG90 servo, battery pack (or Wokwi online)
- Wire the motor through the driver and the servo straight to pin 9.
- Upload the program and watch the motor speed up, then the servo sweep.
- Change the PWM steps: what is the slowest speed at which your motor still turns?
Quick check
You change a gearbox from 10:1 to 20:1. What happens to the output?
Torque goes up by the ratio and speed goes down by the same ratio. Power (torque × speed) stays about the same.
// Speed of a DC motor through a driver (L298N), and a servo angle
#include <Servo.h>
const int ENA = 5, IN1 = 7, IN2 = 8; // driver pins
Servo arm;
void setup() {
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
arm.attach(9); // servo signal on pin 9
}
void loop() {
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); // direction: forward
for (int speed = 0; speed <= 255; speed += 5) {
analogWrite(ENA, speed); // PWM: 0 = stopped, 255 = full speed
delay(40);
}
for (int angle = 0; angle <= 180; angle += 10) {
arm.write(angle); // a servo goes to the angle you ask for
delay(80);
}
}Module 03 of 10
Sensors
Without sensors a robot is blind. Students start with two: an ultrasonic sensor for distance and an encoder to count how far a wheel or joint has turned.
An ultrasonic sensor sends a click of sound and times the echo. Sound travels 343 m/s, and the time covers the trip there and back:
An encoder is a slotted disc on a shaft. A light shines through the slots, so the sensor sees pulses as it turns. Two sensors, A and B, a quarter slot apart, also give the direction: whichever changes first.
Other common sensors: IR line sensors, IMUs for tilt, cameras, and LiDAR for 3D maps.
In our robots
Our robot joints use an inductive encoder: copper coils on a circuit board sense a metal target turning above them. No light and no magnets, so dust and oil do not upset it. The counting idea is the same as the slotted disc.
Try it
Spin the encoder
Turn the disc either way. Watch pulses A and B, and how the count follows.

Your project
A car that stops before a wall
You need: Your motor setup, HC-SR04 ultrasonic sensor
- Print the distance on the Serial Monitor and check it with a ruler.
- Add the motor: drive forward, stop when the distance is under 20 cm.
- Make it smarter: slow down as it gets closer instead of stopping suddenly.
Quick check
An encoder disc has 100 slots. How many counts is one full turn?
Each slot gives 4 edges between A and B, so 100 × 4 = 400 counts per turn.
// Measure distance with an HC-SR04 ultrasonic sensor
const int TRIG = 9, ECHO = 10;
void setup() {
pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
Serial.begin(9600);
}
float readDistanceCm() {
digitalWrite(TRIG, HIGH); delayMicroseconds(10); digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH); // time for the echo to come back
return us * 0.0343 / 2; // sound: 343 m/s, there and back
}
void loop() {
Serial.println(readDistanceCm());
delay(100);
}Module 04 of 10
Actuators
An actuator is everything a robot joint needs in one box: a motor to make force, a gearbox to multiply it, a sensor to measure the angle and a driver to control it.
A hobby servo is the smallest actuator: a tiny motor, a plastic gearbox, a potentiometer and a control chip. Industrial arms and legged robots use the same idea, much bigger and stronger. The parts, from top to bottom:
- Driver board: the electronics that run the control loop.
- Encoder: measures the angle, so the driver knows where the joint is.
- Motor: a stator of copper coils and a rotor of magnets that spins.
- Reducer: the gearbox. Planetary gears are compact; cycloidal discs are very strong for their size; harmonic (strain-wave) gears have no play, which arms like.
Legged robots choose a low ratio, about 6 to 15:1. The joint stays backdrivable: push the leg and it gives a little, which soaks up the shock of every landing instead of breaking the gears.
In our robots
Every joint of our quadruped is an actuator our team designs in-house: motor, reducer, encoder and driver board in one compact unit. The concept picture below shows the same building blocks.
Try it
Take the actuator apart
Drag the slider to pull the parts apart. Tap a part to see what it does.

Concept illustration
One joint, cut open.
- Cover with fins carries heat away
- Driver board runs the control loop
- Encoder on the shaft measures the angle
- Stator: copper coils on an iron core
- Rotor magnets, red and blue poles, spin inside the stator
- Planetary gearbox multiplies the torque
- Output flange: the leg or arm bolts on here
A simplified concept, not a real product drawing. Read it from top to bottom.
Your project
Open a servo and count its gears
You need: An SG90 servo, a small screwdriver, a notebook
- Open the case and find the motor, the gears, the potentiometer and the control board.
- Count the teeth on each gear, put your numbers in the program and work out the real ratio.
- Close it again and test it. Does it still go to the angle you ask for?
Quick check
Why do legged robots use a low gear ratio in their joints?
A low ratio keeps the joint backdrivable. When a foot lands hard, the motor is pushed back a little instead of the gear teeth taking the whole shock.
# A hobby servo gear train: four stages (example tooth counts)
stages = [(10, 32), (10, 35), (10, 32), (10, 28)] # (small gear, big gear) teeth
ratio = 1
for small, big in stages:
ratio *= big / small # each stage multiplies the ratio
motor_rpm, motor_torque = 12000, 0.0025 # tiny DC motor: fast, weak (N m)
print(f"Ratio about {ratio:.0f}:1")
print(f"Output: {motor_rpm / ratio:.0f} rpm, {motor_torque * ratio * 0.7:.2f} N m")
# Ratio about 100:1 -> 120 rpm and about 0.18 N m: slow, but strongModule 05 of 10
Robot electronics
A robot is a small network of computers. Each board does one job, they talk over buses, and a battery with a BMS powers them all safely.
Embedded hardware is everywhere in a robot. A main computer (a Raspberry Pi or Jetson) runs the planning and AI. Microcontrollers (Arduino, ESP32, STM32) sit next to the hardware: one in every motor driver, one reading the sensors, one in the battery.
They talk over communication buses. Short and simple inside a board, long and robust across the robot:
- UART: two wires, one device to one device. Serial Monitor, GPS, debug.
- I2C: two wires shared by many small sensors, each with an address.
- SPI: four wires, very fast, short distance: encoders, IMUs, displays.
- CAN: two twisted wires shared by many boards, built for noisy machines and cars.
- EtherCAT: industrial Ethernet that updates every joint in a fraction of a millisecond.
The battery pack is many lithium cells. In series the voltages add, in parallel the capacities add. A BMS (battery management system) watches every cell: it stops charging or discharging before a cell is over-charged, over-drained, too hot or overloaded, and balances the cells so they stay equal.
run time ≈ battery energy (Wh) ÷ robot power (W)
In our robots
Our Pilot motor drivers talk EtherCAT and CAN, so a few cables daisy-chain all 12 joints of the quadruped. Our Sentinel BMS manages a 14-cell pack: 14 × 3.6 V is about 50 V.
Try it
Follow the wires
Tap a connection to see which bus it uses and why.

Your project
Read an IMU over I2C
You need: Arduino Uno, MPU-6050 module, four jumper wires
- Wire VCC, GND, SDA and SCL. Run an I2C scanner: does it find address 0x68?
- Upload the program and open the Serial Plotter. Tilt the board and watch the line move.
- Add a second sensor on the same two wires. How does I2C tell them apart?
Quick check
A robot has 12 motor drivers spread over its body. Which bus suits them best?
I2C and SPI are made for short distances on one board. CAN and EtherCAT run long cables between many boards and shrug off electrical noise from the motors.
// Read the tilt sensor (MPU-6050) over I2C, send it to the PC over UART
#include <Wire.h>
const int IMU = 0x68; // the sensor's I2C address
void setup() {
Wire.begin(); // I2C: two wires, SDA and SCL
Wire.beginTransmission(IMU);
Wire.write(0x6B); Wire.write(0); // wake the sensor up
Wire.endTransmission();
Serial.begin(115200); // UART to the PC
}
void loop() {
Wire.beginTransmission(IMU);
Wire.write(0x3B); // first acceleration register
Wire.endTransmission(false);
Wire.requestFrom(IMU, 6); // x, y, z: two bytes each
int ax = Wire.read() << 8 | Wire.read();
int ay = Wire.read() << 8 | Wire.read();
int az = Wire.read() << 8 | Wire.read();
float tilt = atan2(ax, az) * 57.3; // degrees
Serial.println(tilt); // open the Serial Plotter
delay(20);
}Module 06 of 10
Control with PID
Telling a motor to go somewhere is easy. Getting there quickly, without overshooting or shaking, is control. PID is the controller used almost everywhere.
A PID controller looks at the error (where you want to be minus where you are) and adds three parts:
- P, proportional: push harder the further off you are. Too much and it overshoots and wobbles.
- I, integral: push harder the longer you have been off. Removes the small error left by gravity or friction.
- D, derivative: push against fast movement, like a brake that stops the overshoot.
Tuning means choosing Kp, Ki and Kd by trying, watching and adjusting, exactly like the panel here. A line follower uses the same idea: the error is how far the line is from the centre of the robot.
In our robots
Our motor drivers run their position loop 4,000 times a second, with a current loop inside it running 40,000 times a second. Every joint of the quadruped is held this way.
Try it
Tune a joint
The joint must move from 0° to 90°. Change the gains and watch the curve.
Your project
A line-following robot
You need: Robot car chassis, two motors, driver, 3 or 5 IR line sensors
- Read the sensors and turn them into one number: where is the line?
- Start with P only. Increase Kp until it follows but wobbles.
- Add D to stop the wobble. Race a friend's robot around the same track.
Quick check
Gravity is on and Ki = 0: the arm stops a little short of 90°. Which term fixes that?
The integral keeps growing while any error is left, so it builds up exactly the extra push gravity needs.
// Line follower: PID on the line position from a sensor array
float kp = 12.0, ki = 15.0, kd = 0.9; // try the "Well tuned" preset above
float integral = 0, lastError = 0;
float pid(float error, float dt) {
integral += error * dt; // how long have we been off?
float rate = (error - lastError) / dt; // how fast is it changing?
lastError = error;
return kp * error + ki * integral + kd * rate;
}
void loop() {
float error = readLinePosition(); // -1 = line far left, +1 = far right
float turn = pid(error, 0.01);
setWheelSpeeds(150 + turn, 150 - turn); // steer back to the line
delay(10);
}Module 07 of 10
Mobile robots
Most robot cars steer like a tank: no steering wheel, just two wheels that can turn at different speeds. This is called differential drive.
Both wheels at the same speed: the robot goes straight. Right wheel faster: it curves left. Wheels in opposite directions: it spins on the spot. Two numbers control everything:
turn rate ω = (vright − vleft) ÷ wheel gap
Add up small steps of v and ω over time and the robot knows roughly where it is. This is called odometry. It drifts slowly, which is why real robots also use cameras or LiDAR to correct it.
In our robots
Warehouse robots, robot vacuum cleaners and most research robots like the TurtleBot use exactly this. Our quadruped walks instead of rolling, but its walking brain still takes the same two commands: forward speed and turn rate.
Try it
Drive the robot
Set the two wheel speeds and watch the path. Try to drive a circle and a square.
Your project
Drive your robot car on a path
You need: Your robot car from module 5, wheel encoders
- Count wheel turns with the encoders and convert them to distance.
- Program a square: drive 50 cm, turn 90°, four times.
- Measure how far from the start it ends. That error is odometry drift.
Quick check
Left wheel 0.2 m/s, right wheel −0.2 m/s. What does the robot do?
Forward speed is (0.2 − 0.2) ÷ 2 = 0, but the turn rate is large, so it turns without moving: a spin.
# Differential drive: two wheel speeds -> how the robot moves
from math import cos, sin
WHEEL_GAP = 0.15 # metres between the wheels
def step(x, y, heading, v_left, v_right, dt):
v = (v_left + v_right) / 2 # forward speed
w = (v_right - v_left) / WHEEL_GAP # turning rate (rad/s)
x += v * cos(heading) * dt
y += v * sin(heading) * dt
heading += w * dt
return x, y, heading
# equal speeds: straight line; opposite speeds: spin on the spotModule 08 of 10
Robot arms
Kinematics links joint angles to where the gripper is. Forward: angles to position. Inverse: position to angles, which is what you need to pick something up.
A simple arm is two links: upper arm and forearm. With a shoulder angle and an elbow angle, trigonometry gives the gripper position: that is forward kinematics.
To pick up an object we need the reverse: we know where it is and need the two angles. Shoulder, elbow and gripper make a triangle with three known sides, so the law of cosines gives the elbow angle:
where d is the distance from shoulder to gripper. If d is longer than L1 + L2, it is out of reach.
In our robots
A robot leg is a robot arm upside down. Our quadruped places each foot with exactly this maths, with a 26 cm thigh and a 24 cm shank instead of 12 cm and 10 cm links.
Try it
Move the gripper
Drag the gripper. The joint angles are solved live. Press Draw to trace a shape.
Your project
A two-servo arm that draws
You need: Two SG90 servos, card or 3D-printed links, a pen
- Build the arm with 12 cm and 10 cm links and measure the real lengths.
- Use the program to turn (x, y) points into two servo angles.
- Draw a square on paper. Why are the corners not perfect?
Quick check
Links of 12 cm and 10 cm. The target is 25 cm from the shoulder. What happens?
The longest the arm can be is 12 + 10 = 22 cm. 25 cm is out of reach, so there is no solution.
# Inverse kinematics of a two-link arm: where should the joints go?
from math import acos, atan2, sqrt, degrees
L1, L2 = 0.12, 0.10 # upper and lower link, metres
def arm_ik(x, y):
"""Gripper at (x, y) from the shoulder. Returns shoulder and elbow angles."""
d = sqrt(x*x + y*y) # shoulder to gripper
if d > L1 + L2:
raise ValueError("out of reach")
elbow = acos((L1*L1 + L2*L2 - d*d) / (2*L1*L2)) # law of cosines
shoulder = atan2(y, x) + acos((L1*L1 + d*d - L2*L2) / (2*L1*d))
return degrees(shoulder), degrees(elbow)
print(arm_ik(0.10, 0.12)) # 10 cm forward, 12 cm upModule 09 of 10
Simulation and ROS 2
Real robot software is many small programs working together, tested in a simulator long before it runs on hardware.
ROS 2, the Robot Operating System, is the standard way to build that software. Each job is a small program
called a node: one reads the camera, one finds obstacles, one drives the motors. Nodes talk by publishing
messages on named topics, such as /cmd_vel for speed commands.
Because nodes only see topics, the same driving code can run a simulated robot today and the real one tomorrow. That is why engineers use simulators like Gazebo and Webots: crash a thousand times for free, then build.
In our robots
We test our robots in simulation first, too. Our quadruped's legs were tried in a physics simulator at many lengths, from 22 to 36 cm per link, before we chose 26 and 24 cm: long enough for 18 cm stairs, light enough to swing fast.
Try it
Watch the messages
Tap a node to switch it off and see what stops working.
Your project
Drive a robot in a simulator
You need: A laptop with ROS 2 and Gazebo (we help you install it, or use our lab PCs)
- Start the TurtleBot simulation and drive it with the keyboard.
- Run the driver node above: the robot drives in a circle.
- Read the simulated laser scanner and stop before a wall: module 3 again, in ROS 2.
Quick check
In ROS 2, how does the camera node send images to the vision node?
Nodes never call each other. The camera publishes on a topic such as /image, and any node that needs images subscribes.
# A ROS 2 node that drives a robot forward while turning gently
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Twist
class Driver(Node):
def __init__(self):
super().__init__("driver")
self.pub = self.create_publisher(Twist, "/cmd_vel", 10)
self.create_timer(0.1, self.tick) # 10 times a second
def tick(self):
msg = Twist()
msg.linear.x = 0.2 # m/s forward
msg.angular.z = 0.3 # rad/s turn
self.pub.publish(msg) # any robot listening moves
rclpy.init()
rclpy.spin(Driver())Module 10 of 10
Robots that learn (AI)
Writing every rule by hand gets hard fast. Modern robots learn: from camera images, from people showing them, and by practising in simulation.
Computer vision lets a robot see: libraries like OpenCV find lines and colours, and neural networks like YOLO find objects. Learning from demonstration lets a person guide an arm a few times until it copies the task.
Reinforcement learning goes further. A small neural network, the policy, reads the sensors and drives the motors. A reward scores each moment, and millions of tries in a simulator later, the robot has learned a skill. The catch: robots learn exactly what you reward, not what you meant.
Try it
Design the reward
Switch reward terms on and off. These are results our team got in real training runs.
Your project
Train a policy in simulation
You need: A laptop; a free simulator (we provide a ready setup)
- Run a pre-trained walking robot and watch what it does.
- Change one reward weight, train again for 20 minutes, compare.
- Write down what changed. You are now doing robot learning research.
Quick check
A reward pays the robot every time a foot is in the air. What does it learn?
Hopping scores the most. Our first training runs did exactly this, with all four feet off the ground most of the time.
# Reinforcement learning: score what the robot just did
def reward(robot, command):
r = 0.0
r += 1.0 * match(robot.speed, command.speed) # go the speed we asked for
r -= 0.5 * all_feet_in_air(robot) # no hopping at low speed
r -= 0.01 * sum(robot.joint_torques ** 2) # don't waste energy
r -= 0.1 * robot.action_change # move smoothly
if robot.fell_over:
r -= 10.0 # falling is very bad
return r
# The simulator runs thousands of robots at once and repeats this millions
# of times. The policy (a small neural network) learns high-reward actions.Capstone
Your robot, start to finish.
Bring it all together: a robot car that follows a line, avoids obstacles and reports its position, then the same robot driven through ROS 2 in a simulator.
- Week 1The big picture: kinds of robots, the sense-think-act loop, the tools of modern robotics.
- Weeks 2-3Motors, drivers and sensors. Spin a motor, sweep a servo, measure distance.
- Week 4PID control. A line-following robot, tuned by hand.
- Week 5Mobile robots. Drive your car on a planned path with odometry.
- Week 6Robot arms. A two-servo arm that draws shapes.
- Weeks 7-8ROS 2 and simulation. The same robot, in software.
- Week 9AI: vision and a first reinforcement learning run.
- Week 10Capstone demo and certificate.
Next level · Advanced course
Legged robots, with our quadruped.
After this course: an advanced course built on a shareable model of the Retech quadruped. Gaits, leg control and training a walking policy. Here is a taste: how four legs share the work as the robot speeds up.
A gait is the pattern in which legs touch the ground. In a walk one leg lifts at a time; in a trot diagonal pairs move together; in a bound front and back pairs move together, with moments of flight. Animals and robots switch gaits by the Froude number:
Below about 0.5 they walk, up to about 2.5 they trot, above that they gallop or bound.
In our robots
With our hip height of 0.34 m, Froude 0.5 is about 1.3 m/s and 2.5 about 2.9 m/s. Our trained robot walks, trots and gallops close to these speeds, without being told to.
Try it
See the gait change
Set a speed. The footfall pattern and the feet, seen from above, follow it.
Course materials
Take the course home.
Anyone can read this course. Registered students also get the downloads below.
Lesson slides
All ten modules as slides, with the diagrams from this page.
For registered studentsLab notebook (PDF)
Step-by-step practicals with circuits, photos and checklists.
For registered studentsCode pack
Every program from the course, ready for Arduino, Python and ROS 2.
For registered studentsSimulator setup
A tested guide to install ROS 2, Gazebo and the learning simulator.
For registered studentsReady to build your first robot?
Online or at our lab in Chennai, with a certificate. We call you to fix the batch.