If you are ready to learn, let’s begin this exciting discussion. Hopefully, this tutorial will help you learn effectively and boost your motivation to explore Arduino projects.
Introduction to the LM35 Sensor
The LM35 is a temperature sensor capable of detecting ambient temperature in its surrounding environment.
In this Arduino project, we will measure the ambient temperature using the LM35 sensor.
Required Components
Prepare the following components:
- 1× Arduino board
- 1× Breadboard
- 1× LM35 temperature sensor
- 2× Green LEDs
- 2× Yellow LEDs
- 2× Red LEDs
- 6× 220-ohm resistors
- 11× Jumper wires
Connect the components as shown in the diagram below.
Wiring Notes:
- Connect the GND and 5V pins from the Arduino to the breadboard.
- Connect the left pin of the LM35 to 5V, the right pin to GND, and the middle pin to A0 on the Arduino.
Connect:
Green LEDs to digital pins 2 and 3- Yellow LEDs to digital pins 4 and 5
- Red LEDs to digital pins 6 and 7
- Connect each LED’s negative (cathode) pin to GND through a 220-ohm resistor.
LM35 Temperature Sensor Code
byte lm35 = A0;
int value;
void setup() {
Serial.begin(9600);
}
void loop() {
value = analogRead(lm35);
value = value * 0.488;
Serial.println(value);
delay(500);
}
Code Explanation
Serial.begin(9600);
analogRead(lm35);
value = value * 0.488;
Serial.println(value);
Creating a Temperature Indicator Using LEDs
You can open the Serial Monitor by pressing CTRL + SHIFT + M.
Note:
A value such as 27 indicates the temperature in degrees Celsius. Try touching the LM35 sensor—its value will increase because it detects heat from your body.
Adding LED Logic
if statements) as shown below:Complete Arduino Sketch
Additional Notes
The temperature values used in the code should be adjusted based on your local environment, as ambient temperatures may vary.
-
if (valueLM35 == 28)
Executes the code block when the temperature equals 28°C. -
else if
Executes when the previous condition is not met. -
else
Executes when none of the conditions are true.
Creative Challenge
There are still three unused LEDs in the circuit.
Try creating a program with the following logic:
-
If
LM35 == 28, all green LEDs turn ON -
If
LM35 == 29, all yellow LEDs turn ON -
If
LM35 == 30, all red LEDs turn ON

Posting Komentar untuk "Arduino Temperature Sensor Project Using LM35"