Temperature Sensor

Hello again, world!

Temperature is also important for my go-kart project (later I’ll write about the project itself). It’s pretty important to know how to change the fuel mixture to avoid doing a hole in the piston and screwing up the spark.

Considering that I bought a temperature sensor in DX and here it is:


I put my finger close to it, so you can see how small it is. It uses the LM35 sensor, and here you can find its data sheet.

It works more or less like a potentiometer. You put on it 5v (or 3.3v, but you should change the code), and the output is mV, so we need analog pin. This sensor has a precision of 10mV/C, so for each Celsius degree output increase/decrease 10mV. And for each mV… you can do the math, right? 🙂

Arduino ADC has a precision of 10 bits or 5v / 1024 or ~0.0049. If we read the pin, we’ll have the value in volts, to convert it to millivolts we must multiply by 1000 and how the sensor precision is 10mV/C we must divide by 10… in other words “pin * 0.0049 * 1000 / 100”. Or being less stupid “pin * 0.49” and to convert to Fahrenheit multiply by 1.8 and then sum 32.

The left pin has a “-” close to it, what makes me know it’s the ground pin, the right one has a S close to it and I guess it is the output pin (if someone knows what “S” means, please let me know). The pin in the middle could only be VCC. Well… Now it’s easy to wire it… Left pin to Arduino ground pin, middle pin to Arduino 5v pin and right pin to Arduino A0 pin.

I wrote a small code to read the temperature:

int analogPin = 0;
int readValue = 0;
float temperature = 0;

void setup() {

void loop() {
readValue = analogRead(analogPin);
temperature = (readValue * 0.49);
Serial.print(“Temperature: “);
Serial.print(” C “);
Serial.print((temperature * 1.8) + 32);
Serial.println(” F”);

The output is:

Output from Temperature sensor

The value grows when you put the finger in the sensor, as you may notice in the picture above.

Have fun!!

Leave a Reply