Connecting a temperature [sensor](https://www.ampheo.com/c/sensors) to an [Arduino](https://www.ampheo.com/c/development-board-arduino) is a great beginner-friendly project. Here's a simple step-by-step guide using the most common sensor types:  **Option 1: LM35 (Analog Temperature Sensor)** **What You Need:** * [Arduino Uno](https://www.ampheo.com/product/a000046-25542493) (or compatible) * [LM35](https://www.ampheo.com/search/LM35) temperature sensor * Breadboard + jumper wires **Wiring:**  **Arduino Code:** ``` cpp const int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int rawValue = analogRead(sensorPin); float voltage = rawValue * (5.0 / 1023.0); float temperatureC = voltage * 100.0; // 10 mV per °C Serial.print("Temperature: "); Serial.print(temperatureC); Serial.println(" °C"); delay(1000); } ``` **Option 2: DS18B20 (Digital 1-Wire Sensor)** **What You Need:** * Arduino * [DS18B20](https://www.ampheo.com/product/ds18b20-26808200) sensor * 4.7kΩ resistor (pull-up) * Jumper wires **Wiring:**  **Libraries Required:** * OneWire * DallasTemperature Install them via: Sketch > Include Library > Manage Libraries... **Arduino Code:** ``` cpp #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup() { Serial.begin(9600); sensors.begin(); } void loop() { sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" °C"); delay(1000); } ``` **Other Temperature Sensors** 
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.