Write the following code in Cloud9 and save it as tmp36.js
. Run the program and check the printed temperature. Then touch the plastic body of the sensor for a few seconds (avoid touching metal pins). You should see an increase in temperature. The code for tmp36.js
is as follows:
var b = require('bonescript'); var loopTimer = setInterval(readVoltageLoop, loopTime); var loopTime = 2000; var TMP36 = 'P9_40'; function readVoltageLoop() { b.analogRead(TMP36, printTemperature); } function printTemperature(pinObj) { var volt = pinObj.value * 1.8; var temperature = (100 * volt) - 50; console.log("Voltage at input pin = " + volt.toPrecision(3) + " Temperature in Celsius =" + temperature.toPrecision(3) ); }