9.8.1 The Project Cycle
- Idea and requirements. What must it do? List inputs and outputs.
- Block diagram. Input → Arduino → Output; add power.
- Component selection and budget.
- Circuit design. Draw the schematic; check current and voltage limits of every pin.
- Pin assignment table. Write it down to avoid conflicts.
- Flowchart or pseudocode.
- Build in stages. Test each module separately, then combine.
- Test and debug. Use the Serial Monitor.
- Documentation. Circuit diagram, code, photographs, user instructions.
- Demonstration and reflection.
9.8.2 Worked Example: Obstacle-Avoiding Robot Car
This project combines the ultrasonic sensor (Practical 4), the servo (Practical 3) and the L298N with two motors (Practical 6).
Requirements. The car drives forward. When an obstacle is closer than 20 cm it stops, reverses briefly, looks left and right with the servo-mounted sensor, then turns toward the side with more free space.
Block diagram.
Pin assignment.
| Device | Pin |
|---|---|
| L298N ENA / IN1 / IN2 | 5 / 7 / 8 |
| L298N ENB / IN3 / IN4 | 6 / 4 / 12 |
| Servo signal | 9 |
| HC-SR04 Trig / Echo | 10 / 11 |
Flowchart in words.
1START: centre the servo
➜2Measure distance
➜3Distance > 20 cm?
➜4Yes: drive forward, then measure again
➜5No: stop, reverse 0.3 s
➜6Look left and right, measure both
➜7Centre servo, turn toward the larger distance for 0.4 s
➜8Continue the loop
Program.
Arduino C/C++
#include <Servo.h>
const int ENA = 5, IN1 = 7, IN2 = 8;
const int ENB = 6, IN3 = 4, IN4 = 12;
const int trigPin = 10, echoPin = 11;
const int servoPin = 9;
const int carSpeed = 170;
const float stopDistance = 20.0;
Servo head;
float getDistance() {
digitalWrite(trigPin, LOW); delayMicroseconds(2);
digitalWrite(trigPin, HIGH); delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long d = pulseIn(echoPin, HIGH, 30000);
if (d == 0) return 400; // treat no echo as far away
return d * 0.0343 / 2.0;
}
void drive(bool leftFwd, bool rightFwd) {
digitalWrite(IN1, leftFwd ? HIGH : LOW);
digitalWrite(IN2, leftFwd ? LOW : HIGH);
digitalWrite(IN3, rightFwd ? HIGH : LOW);
digitalWrite(IN4, rightFwd ? LOW : HIGH);
analogWrite(ENA, carSpeed);
analogWrite(ENB, carSpeed);
}
void stopMotors() {
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
analogWrite(ENA, 0); analogWrite(ENB, 0);
}
void setup() {
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);
head.attach(servoPin);
head.write(90); // look straight ahead
delay(500);
}
void loop() {
if (getDistance() > stopDistance) {
drive(true, true); // path clear: forward
} else {
stopMotors();
delay(200);
drive(false, false); // reverse a little
delay(300);
stopMotors();
head.write(30); delay(500);
float rightDist = getDistance();
head.write(150); delay(700);
float leftDist = getDistance();
head.write(90); delay(400);
if (leftDist > rightDist) drive(false, true); // turn left
else drive(true, false); // turn right
delay(400);
stopMotors();
}
}Testing tips. Test the motor directions with the wheels off the ground first. Lift the sensor above the motors to avoid vibration noise. Tune stopDistance, turning time and speed on the real floor.
9.8.3 More Mini-Project Ideas
| Project | Main parts | Key skill |
|---|---|---|
| Automatic street light | LDR, LED | Analog input, threshold |
| Smart dustbin lid | HC-SR04, servo | Sensor triggers actuator |
| Parking distance alarm | HC-SR04, buzzer, 3 LEDs | Distance zones |
| Temperature-controlled fan | LM35, transistor, small DC motor | Analog sensor, transistor driver |
| Bluetooth switch board | HC-05, relay module (low-voltage lamp) | Wireless control |
| Traffic light controller | 3 LEDs, push button for pedestrians | State machine, millis() |
| Digital door counter | 2 IR sensors, LCD | Logic and counting |
| Plant watering reminder | Soil moisture sensor, buzzer | Analog sensing |
9.8.4 Project Marking Guide (100 marks)
| Criterion | Marks |
|---|---|
| Requirements and planning (block diagram, pin table) | 15 |
| Circuit construction and neatness | 20 |
| Program quality (structure, comments, functions) | 20 |
| Functionality and testing | 25 |
| Documentation and report | 10 |
| Demonstration and viva | 10 |
9.8.5 Review Questions
- List the steps of the project cycle.
- Why create a pin assignment table before wiring?
- In the obstacle-avoiding car, why does
getDistance()return 400 when no echo is received? - What would you change so that the car also follows Bluetooth commands?
Show answers
- Idea, block diagram, components, circuit design, pin table, flowchart, staged build, testing, documentation, demonstration.
- To avoid two devices using the same pin and to make wiring and debugging easier.
- No echo usually means the way ahead is open or the object is too far, so the car should treat it as a large free distance rather than as an obstacle.
- Add the HC-05 on SoftwareSerial pins (for example A0 and A1, which are free in this pin map) and add a mode selector so Bluetooth commands override the automatic behaviour.