Temperature Sensor
What is a Temperature Sensor?
A temperature sensor converts heat into an electrical signal or digital value. DS18B20 and LM35 modules are common in Arduino weather stations, incubators, battery packs, thermal alarms, and IoT logging projects.
The DS18B20 is digital, supports long cable runs, and can share one data wire across multiple sensors. The LM35 is analog and simple: its output voltage rises linearly with temperature.
Key Features
Direct Temperature Reading
Measures ambient, surface, liquid, or enclosure temperature depending on package style.
Digital or Analog Options
DS18B20 uses OneWire digital data; LM35 outputs 10mV per degree Celsius.
Waterproof Probe Option
Sealed DS18B20 probes are popular for aquariums, soil temperature, and outdoor projects.
Long Cable Friendly
Digital probes can work over longer wires when pull-up resistance and cable quality are chosen well.
Easy Calibration Check
Ice water and room-temperature references help verify sensor offset.
Useful Everywhere
Used in HVAC, battery safety, fermentation, weather logging, and electronics thermal testing.
Pin Configuration
VCC
Power input. DS18B20 commonly supports 3.0-5.5V; LM35 modules are often powered from 5V.
DATA / OUT
Digital OneWire data for DS18B20 or analog voltage output for LM35. Connect to a suitable GPIO or ADC pin.
GND
Ground reference shared with the microcontroller.
How It Works
The Science Behind It
An LM35 uses semiconductor junction behavior to produce a voltage proportional to Celsius temperature. The microcontroller ADC converts that voltage into a temperature estimate.
A DS18B20 contains sensing, conversion, and digital interface circuitry in one package. Each device has a unique address, so several sensors can share a single data pin.
Common Conversions:
LM35 temperature C = Vout(mV) / 10
ADC voltage = reading x Vref / ADC_max
DS18B20 value = digital reading from OneWire library
For ESP32 analog measurements, account for ADC nonlinearity and keep the sensor output within the 3.3V ADC range.
Wiring Tips & Best Practices
Use a Pull-up Resistor
DS18B20 data usually needs a 4.7k pull-up resistor from DATA to VCC.
Manage Cable Length
For long DS18B20 cables, use twisted pair, good grounding, and slower sampling.
Check Calibration
Compare against ice water, room temperature, or a trusted thermometer before relying on absolute values.
Separate Heat Sources
Keep the sensor away from regulators, microcontrollers, and power resistors unless measuring board heat.
Seal Outdoor Connections
Waterproof probe tips are sealed, but connectors still need heat-shrink or enclosure protection.
Sample Slowly
Temperature changes slowly. One reading per second is enough for most beginner projects.