0% found this document useful (0 votes)
4 views6 pages

Speed Radar System with Alerts Guide

This document outlines a laboratory activity for a microprocessors course, focusing on building a speed radar system using an ultrasonic sensor. The activity involves measuring speed, triggering a warning system with an LED and buzzer if the speed exceeds 30 cm/s, and includes pin connections and code examples. Materials needed for the project include an ESP32 Dev Board, ultrasonic sensor, LED, resistor, buzzer, jumper wires, and a breadboard.

Uploaded by

Raleigh Riego
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Speed Radar System with Alerts Guide

This document outlines a laboratory activity for a microprocessors course, focusing on building a speed radar system using an ultrasonic sensor. The activity involves measuring speed, triggering a warning system with an LED and buzzer if the speed exceeds 30 cm/s, and includes pin connections and code examples. Materials needed for the project include an ESP32 Dev Board, ultrasonic sensor, LED, resistor, buzzer, jumper wires, and a breadboard.

Uploaded by

Raleigh Riego
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CPE309/309L: MICROPROCESSORS

LABORATORY ACTIVITY NO. 6

S.Y. 2025 – 2026, 2nd Semester

Student Name and Signatures: Score:


_______________________________/________
_______________________________/________
_______________________________/________
Course, Year, and Section: Group No.: Date:

Activity No. 6: Speed Radar with LED Warning System


Overview:
This activity simulates a roadside speed radar system. An ultrasonic sensor tracks how
fast an object (like your hand or a toy car) passes by. If the calculated speed exceeds a
threshold, a red LED flashes rapidly and a buzzer sounds an alert. This teaches motion
sensing, timing, and conditional reactions in real-time.

Practice A: Measure Distance at Two Intervals to Calculate Speed


Objective: Use ultrasonic sensor to measure movement and estimate speed.
Pin Connections:
 Trig → GPIO5
 Echo → GPIO18
Code:
#define trigPin 5
#define echoPin 18

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2;
}

void setup() {
[Link](115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
long d1 = getDistance();
delay(100);
long d2 = getDistance();

float speed = abs(d2 - d1) / 0.1; // cm per second


[Link]("Speed: ");
[Link](speed);
[Link](" cm/s");

delay(500);
}

Practice B: Trigger LED and Buzzer if Speed is Too High


Objective: Add warning outputs when speed exceeds 30 cm/s.
Pin Connections:
 Red LED → GPIO32 (220Ω resistor)
 Buzzer → GPIO27
Code:
#define trigPin 5
#define echoPin 18
#define ledPin 32
#define buzzerPin 27

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
long d1 = getDistance();
delay(100);
long d2 = getDistance();
float speed = abs(d2 - d1) / 0.1;
if (speed > 30) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}

delay(500);
}

Activity Proper: Complete Speed Radar System with Visual and Audio
Alerts
Objective: Build a working speed radar using an ultrasonic sensor to track object movement
and trigger a warning system if motion exceeds 30 cm/s.
Pin Summary:
 Trig → GPIO5
 Echo → GPIO18
 Red LED → GPIO32
 Buzzer → GPIO27
Code:
#define trigPin 5
#define echoPin 18
#define ledPin 32
#define buzzerPin 27

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
long d1 = getDistance();
delay(100);
long d2 = getDistance();
float speed = abs(d2 - d1) / 0.1;

if (speed > 30) {


digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}

delay(500);
}
Materials List:
 1x ESP32 Dev Board
 1x HC-SR04 Ultrasonic Sensor
 1x Red LED
 1x 220Ω Resistor
 1x Buzzer
 Jumper wires
 Breadboard

Schematic:

You might also like