LM35 เป็นเซนเซอร์อุณหภูมิที่ให้ค่าเอาต์พุตแบบ Analog ออกมาเป็น 0-1.4V แปรผันตามอุณหภูมิ ดังนั้นเราสามารถใช้ขา A0 อ่านค่าแบบ Analog เข้ามาได้
//initializes/defines the output pin of the LM35 temperature sensor
int outputpin = 0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
}
//main loop
void loop()
{
int rawvoltage = analogRead(outputpin);
float millivolts = (rawvoltage / 1024.0) * 3300;
float celsius = millivolts / 10;
Serial.print(celsius);
Serial.print(" degrees Celsius, ");
Serial.print((celsius * 9) / 5 + 32);
Serial.println(" degrees Fahrenheit");
delay(1000);
}
เมื่ออัพโหลดโคดแล้ว เปิดดูที่ Serial Monitor จะเห็นค่าอุณหภูมิและความชื้นที่อ่านได้