Espruino LM35 temperature sensor example

46

In this example we will connect an LM35 temperature sensor to our Espruino

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1/4°C at room temperature and ±3/4°C over a full -55 to +150°C  temperature range

Here is a picture of the pins, its important to get these correct or you can damage the sensor

lm35-temperature-sensor-pinout

I purchased a small module, which looks like this. This was clearly labelled and helps avoid any mistakes with wiring, I also prefer using cables to modules rather than breadboards

lm35-module

Schematics and Parts

You will need

Espruino
LM35 sensor or module
Hook up wire (dupont cables)

Very simple to connect Vcc is 3.3v, Gnd is any Gnd and out goes to Espruino A1, you can see this below

espruino-and-lm35_bb

Code

 

function getTemp() {
  var val = analogRead(A1); // read voltage
  var millivolts = val * 3300;
  var celsius = millivolts/10;
  return celsius; // and return the temperature
}
 
function checkTemp() {
 var temp = getTemp();
 console.log("Temperature: " + temp + " C");
}
setInterval(checkTemp, 1000);

Results

Here are the results via the console window of the Espruino Web IDE

Temperature: 17.64431219958 C
Temperature: 17.72487983520 C
Temperature: 18.20828564888 C
Temperature: 20.22247653925 C
Temperature: 21.59212634470 C
Temperature: 22.55893797207 C
Temperature: 23.28404669260 C
Temperature: 24.08972304875 C
Temperature: 24.41199359121 C
Temperature: 24.73426413366 C

Links

LM35 datasheet
5PCS LM35D Temperature Sensor TO92 Packing

Share