Measuring environmental temperature

Similar to the previous code block (but slightly more mathematically complicated), the temperature sensor returns an analog reading of the sensor.

If we look at the manufacturer's explanation (http://wiki.seeedstudio.com/Grove-Temperature_Sensor_V1.2/) on how to read the sensor, we will discover that the sensor's v1.2 is shipped with a thermistor with the value of 4,250 as well as a 100k resistor.

Consequently, the formula for calculating the temperature value using this sensor is as follows:

The following code will give the temperature based on the sensor readings every two seconds:

var mraa = require('mraa');
var pin3 = new mraa.Aio(3);
var RESISTOR = 100000;
var THERMISTOR = 4250;
var getTemperature = function() {
var sensorReading = pin3.read();
var R = 1023 / sensorReading - 1;
R = RESISTOR * R;
var temperature = 1 / (Math.log(R/RESISTOR)/THERMISTOR+1/298.15)-273.15;
return temperature;
};
setInterval(function() {
console.log("Current Temperature " + getTemperature());
},2000);

The output of this code will look something like this:

Using the SSH console, these readings will be logged.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.211.92