CPE309/309L: MICROPROCESSORS
LABORATORY ACTIVITY NO. 7
S.Y. 2025 – 2026, 2nd Semester
Student Name and Signatures: Score:
_______________________________/________
_______________________________/________
_______________________________/________
Course, Year, and Section: Group No.: Date:
Activity No. 7: Automatic Cooling & Overheat Warning System
Overview:
This project simulates a smart thermal control system using the LM35 temperature sensor.
When the temperature exceeds a safe limit, a DC fan is activated. If the temperature becomes
dangerously high, a red LED and buzzer provide an alert. This final activity brings together
analog sensing, digital control, and hardware integration.
Practice A: Read Temperature and Control DC Fan
Objective:
Use the LM35 sensor to measure temperature and turn on a cooling fan when it rises above
30°C.
Pin Connections:
LM35 OUT → GPIO34
Transistor base → GPIO13 (via 1kΩ resistor)
Transistor collector → Motor negative
Motor positive → 6V power
Diode across motor terminals
Code:
const int tempPin = 34;
const int fanPin = 13;
void setup() {
Serial.begin(115200);
pinMode(fanPin, OUTPUT);
}
void loop() {
int raw = analogRead(tempPin);
float voltage = (raw / 4095.0) * 3.3;
float tempC = voltage * 100.0;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.println(" °C");
if (tempC > 30) {
analogWrite(fanPin, 200); // run fan at 80% speed
} else {
analogWrite(fanPin, 0);
}
delay(1000);
}
Practice B: Overheat Alert with LED & Buzzer
Objective:
Trigger a red LED and buzzer when temperature reaches 40°C or higher.
Pin Connections:
LM35 OUT → GPIO34
Red LED → GPIO25 (via 220Ω resistor)
Buzzer → GPIO26
Code:
const int tempPin = 34;
const int ledPin = 25;
const int buzzerPin = 26;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
int raw = analogRead(tempPin);
float voltage = (raw / 4095.0) * 3.3;
float tempC = voltage * 100.0;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.println(" °C");
if (tempC >= 40) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}
delay(1000);
}
Activity Proper: Smart Cooling & Alert System
Objective:
Integrate both a fan-based cooling response and an emergency alert (LED + buzzer) to
simulate an automatic thermal control system.
Pin Connections Summary:
LM35 OUT → GPIO34
Transistor base → GPIO13
Motor → External 6V via transistor
Red LED → GPIO25
Buzzer → GPIO26
Final Code:
const int tempPin = 34;
const int fanPin = 13;
const int ledPin = 25;
const int buzzerPin = 26;
void setup() {
Serial.begin(115200);
pinMode(fanPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
int raw = analogRead(tempPin);
float voltage = (raw / 4095.0) * 3.3;
float tempC = voltage * 100.0;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.println(" °C");
// Cooling Fan Logic
if (tempC > 30) {
analogWrite(fanPin, 200);
} else {
analogWrite(fanPin, 0);
}
// Overheat Alert Logic
if (tempC >= 40) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}
delay(1000);
}
Materials Activity Proper Only):
1x ESP32 Dev Board
1x LM35 Temperature Sensor
1x 6V DC Motor
1x NPN Transistor (TIP120 or 2N2222)
1x 1kΩ Resistor
1x Flyback Diode (1N4007)
1x Red LED
1x 220Ω Resistor
1x Buzzer
Jumper wires
Breadboard
External 6V power supply
Schematic:
Because some components are
not available in Wokwi, we have
attached pictures of those
components here.