0% found this document useful (0 votes)
10 views9 pages

Complete Embedded Systems Lab Report With Formulas

The document outlines four B.Tech minor lab experiments focused on embedded systems using ESP32. Experiments include designing an automatic street light, interfacing IR sensors with a DC motor, measuring distance with an ultrasonic sensor, and creating a line follower robot with obstacle detection. Each experiment includes components, theory, design, algorithm, code, and results demonstrating successful implementations.

Uploaded by

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

Complete Embedded Systems Lab Report With Formulas

The document outlines four B.Tech minor lab experiments focused on embedded systems using ESP32. Experiments include designing an automatic street light, interfacing IR sensors with a DC motor, measuring distance with an ultrasonic sensor, and creating a line follower robot with obstacle detection. Each experiment includes components, theory, design, algorithm, code, and results demonstrating successful implementations.

Uploaded by

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

B.

Tech Minor Lab Experiments – Embedded Systems

Experiment 1: Automatic Street Light Using LDR and Relay Module

Aim
To design and implement an automatic street light control system using ESP32, LDR-based
voltage divider and relay module.

Components Required
• ESP32 Development Board

• LDR (Light Dependent Resistor)

• 1 kΩ Resistor

• Relay Module (Active LOW)

• Breadboard

• Jumper Wires

• USB Cable

Theory (with formulas)


Light Dependent Resistor (LDR): An LDR's resistance (R_LDR) decreases as incident light
increases.

Voltage divider (LDR + R_fixed):

V_out = V_cc × (R_fixed) / (R_LDR + R_fixed)

Where V_out is the voltage measured by the ESP32 ADC pin.

ESP32 ADC (12-bit) maps analog voltage 0 – V_ref to digital 0 – 4095.

Therefore ADC_value ≈ round( (V_out / V_ref) × 4095 ).

Relay logic (for active-LOW relay): Relay pin LOW → Relay ON (light ON); Relay pin HIGH →
Relay OFF (light OFF).

Design
LDR + 1 kΩ resistor → ADC pin (e.g., GPIO34).

Relay IN pin → ESP32 output (e.g., GPIO4).

ESP32 compares averaged ADC value with a predefined threshold.


Algorithm
1. Read averaged ADC value from LDR voltage divider.

2. Compare ADC value with pre-set threshold (experimentally chosen).

3. If ADC <= threshold → it's dark → set relay LOW (ON).

4. If ADC > threshold → it's bright → set relay HIGH (OFF).

5. Repeat with a short delay to avoid flicker.

Code
const int LDR_PIN = 34;
const int RELAY_PIN = 4;

void setup() {
[Link](115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Relay OFF initially (active LOW)
analogReadResolution(12); // 12-bit ADC: 0 - 4095
}

int readAverageADC() {
long sum = 0;
const int SAMPLES = 6;
for (int i = 0; i < SAMPLES; ++i) {
sum += analogRead(LDR_PIN);
delay(60);
}
return sum / SAMPLES;
}

void setRelay(bool on) { // on=true -> light ON


digitalWrite(RELAY_PIN, on ? LOW : HIGH);
}

void loop() {
int val = readAverageADC();
[Link]("ADC = "); [Link](val);
const int Threshold = 100; // adjust experimentally
if (val <= Threshold) setRelay(true);
else setRelay(false);
delay(300);
}

Result
The automatic street light turned ON in dark conditions and OFF when ambient light
increased. Averaging ADC readings reduced flicker.
Experiment 2: Interfacing 2 IR Sensors and 1 DC Motor

Aim
To interface two IR sensors with ESP32 and control a DC motor (via L298N) so IR1 runs the
motor and IR2 stops it (IR2 has priority).

Components Required
• ESP32 Development Board

• 2 × IR Obstacle Sensors

• L298N Motor Driver

• DC Motor

• External Motor Power Supply

• Jumper Wires

• Breadboard

• USB Cable

Theory (with formulas)


IR obstacle sensors: Many modules output a digital signal. For this report we assume:

Output HIGH → object detected; Output LOW → no object (verify your module's datasheet).

Motor control through L298N: IN1/IN2 control motor direction. ENA enables outputs (tie
HIGH for always enabled or use PWM).

To run motor forward: IN1 = HIGH, IN2 = LOW. To stop (coast): IN1 = LOW, IN2 = LOW.

Design
IR1 → input to ESP32 (e.g., GPIO23).

IR2 → input to ESP32 (e.g., GPIO22).

L298N IN1/IN2 → ESP32 outputs to control motor.

Algorithm
1. Read IR2. If IR2 detects → stop motor immediately (highest priority).

2. Else read IR1. If IR1 detects → run motor forward.

3. Otherwise → stop motor.

Code
#define IR1_PIN 23
#define IR2_PIN 22
#define IN1_PIN 19
#define IN2_PIN 18

void setup() {
pinMode(IR1_PIN, INPUT);
pinMode(IR2_PIN, INPUT);
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, LOW);
}

void motorStop() {
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, LOW);
}

void motorRunForward() {
digitalWrite(IN1_PIN, HIGH);
digitalWrite(IN2_PIN, LOW);
}

void loop() {
bool ir2 = digitalRead(IR2_PIN) == HIGH;
bool ir1 = digitalRead(IR1_PIN) == HIGH;

if (ir2) motorStop();
else if (ir1) motorRunForward();
else motorStop();

delay(100);
}

Result
Motor runs when IR1 detects and stops when IR2 detects. IR2 correctly overrides IR1 as
priority.

Experiment 3: Distance Measurement Using ESP32, HC-SR04 Ultrasonic Sensor


and I2C LCD

Aim
To interface an HC-SR04 ultrasonic sensor with ESP32 and display the measured distance
on a 16×2 I2C LCD.

Components Required
• ESP32 Development Board

• HC-SR04 Ultrasonic Sensor

• 16×2 I2C LCD (PCF8574)

• Jumper Wires
• Breadboard

• USB Cable

Theory (with formulas)


HC-SR04 timing: To measure distance, TRIG pin is given a 10 µs pulse. ECHO returns a pulse
whose HIGH duration is the round-trip time (in microseconds).

Speed of sound ≈ 343 m/s = 0.0343 cm/µs (at ~20°C).

Distance (one-way) = (Echo duration in µs × speed of sound in cm/µs) / 2

Hence: Distance (cm) = (duration × 0.0343) / 2

Equivalent commonly used formula: Distance (cm) ≈ duration / 58 (because 1/0.01715 ≈


58).

Note: pulseIn() returns time in microseconds (µs). Always use a timeout to avoid blocking.

Design
TRIG → digital output; send 10 µs HIGH pulse.

ECHO → input; measure HIGH duration using pulseIn().

Convert duration to distance using formula and display on LCD.

Algorithm
1. Trigger pulse (10 µs).

2. Read duration = pulseIn(ECHO, HIGH, timeout).

3. Compute distance = (duration × 0.0343) / 2.

4. Display on 16×2 I2C LCD. Repeat.

Code
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>

#define TRIG_PIN 18
#define ECHO_PIN 25

LiquidCrystal_PCF8574 lcd(0x27);

void setup() {
[Link](115200);
[Link]();
[Link](16,2);
[Link](255);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
digitalWrite(TRIG_PIN, LOW);
delay(100);
}

long measureOnceCm(unsigned long timeout = 30000UL) {


digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
unsigned long duration = pulseIn(ECHO_PIN, HIGH, timeout);
if (duration == 0) return -1;
return (long)((duration * 0.0343) / 2.0);
}

void loop() {
long dist = measureOnceCm();
[Link](0,0);
[Link]("Distance: ");
[Link](0,1);
if (dist < 0) [Link]("Out of range ");
else {
[Link](dist);
[Link](" cm");
[Link](" ");
}
delay(300);
}

Result
Ultrasonic distance measured and displayed. Use averaging for more stable readings under
noisy conditions.

Experiment 4: Line Follower Robot including Obstacle Detection

Aim
Design and implement a line follower robot including obstacle detection to prevent
accidents.

Components Required
• ESP32 Development Board

• 2 × IR Line Sensors

• HC-SR04 Ultrasonic Sensor

• L298N Motor Driver

• 2 DC Motors

• Battery Pack
• Jumper Wires

• Breadboard

Theory (with formulas)


Line follower behaviour: IR reflectance sensors give digital outputs depending on surface
reflectivity (white vs black).

Common interpretation used here: Black line → sensor output LOW (less reflection); White
→ HIGH (more reflection).

Ultrasonic obstacle detection uses the same distance formula as Experiment 3.

Motor steering: Use an H-bridge driver (L298N) to control two motors. Combinations of IN
pins produce forward/turn/stop motions.

Design
IR sensors mounted near front wheelbase to detect line.

Ultrasonic mounted frontal to detect obstacles before collision.

Motor driver connected to two motors for steering.

Algorithm
1. Measure distance using ultrasonic sensor.

2. If distance > 0 and < threshold → stop motors.

3. Else read IR sensors and follow logic:

- (LOW, LOW) → forward

- (HIGH, LOW) → left

- (LOW, HIGH) → right

- (HIGH, HIGH) → stop

4. Repeat.

Code
int L1 = 18;
int L2 = 19;
int R1 = 16;
int R2 = 17;

int sL = 34;
int sR = 35;

int trig = 27;


int echo = 14;
int distStop = 15;

void setup() {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(sL, INPUT);
pinMode(sR, INPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
[Link](115200);
}

void fwd() {
digitalWrite(L1, HIGH); digitalWrite(L2, LOW);
digitalWrite(R1, HIGH); digitalWrite(R2, LOW);
}
void lft() {
digitalWrite(L1, LOW); digitalWrite(L2, LOW);
digitalWrite(R1, LOW); digitalWrite(R2, HIGH);
}
void rgt() {
digitalWrite(L1, LOW); digitalWrite(L2, HIGH);
digitalWrite(R1, LOW); digitalWrite(R2, LOW);
}
void stp() {
digitalWrite(L1, LOW); digitalWrite(L2, LOW);
digitalWrite(R1, LOW); digitalWrite(R2, LOW);
}

float getDist() {
digitalWrite(trig, LOW); delayMicroseconds(5);
digitalWrite(trig, HIGH); delayMicroseconds(10);
digitalWrite(trig, LOW);
long t = pulseIn(echo, HIGH, 30000);
float d = t * 0.034 / 2;
return d;
}

void loop() {
float d = getDist();
[Link]("Distance: "); [Link](d);
if (d > 0 && d < distStop) {
stp();
return;
}
int L = digitalRead(sL);
int R = digitalRead(sR);
if (L == LOW && R == LOW) fwd();
else if (L == HIGH && R == LOW) lft();
else if (L == LOW && R == HIGH) rgt();
else stp();
}
Result
The robot followed the line and stopped reliably for obstacles. Ensure sensor calibration for
consistent performance.

You might also like