Introduction: Intel® Edison Board: IoT Temperature Monitoring

IoT is no longer restricted to just the maker hobbyists and enthusiasts. It has caught the attention of companies who want to start a new industrial revolution using IoT. From smart workplaces to increasing production, IoT has a myriad of applications. In this article, we will show to use the Intel® Edison board simulate an HVAC in a building with manual and cloud-driven controls and monitoring.

In this system a heat lamp mimics the HVAC in heating mode and a ventilator fan is the HVAC in cooling mode. The lamp turns on heating up the temperature sensor and when it reaches the threshold limit, a command from the cloud switches off the lamp and switches on the fan until the temperature drops below the threshold. Hence the main control center that drives the HVAC system is in the cloud where the threshold limits can be changed at will. The fan can also be controlled manually with a push button on the board to turn it on and off. The sketch program will be written in JavaScript* using the Intel® XDK IoT Edition development environment. For more information on the Intel® Edison board and Intel ® XDK download: https://www-ssl.intel.com/content/www/us/en/do-it-yourself/edison.html

Components:

  • Intel® Edison board and power supply
  • External Wi-Fi* antenna (optional)
  • From the Grove* Starter Kit
    • Seeed Studio* base shield
    • Temperature sensor
    • Relay
    • Push button
    • LED
    • LCD
  • Heat lamp and power supply
  • 5V ventilator fan

The majority of the sensors are from the Grove* Starter Kit for Intel® Edison board which is designed to make bread boarding and wiring circuits easy. The base shield slots in on top of the Intel® Edison board and with the Grove cables, you simply plug in one end to the sensor and the other end to the slot on the shield. Always make sure the board is not powered on when changing wires and cables around. Also toggle the Grove shield to be set on 5V, otherwise the sensors in this tutorial will not have enough power.

You can read more about the Grove Starter Kit here: http://www.seeedstudio.com/depot/Grove-starter-kit-plus-Intel-IoT-Edition-for-Intel-Galileo-Gen-2-and-Edison-p-1978.html

Step 1: Sensors - Temperature Sensor

The temperature sensor is the main component of this demo and should be plugged into slot A0 for analog signals. The temperature will be recorded in degrees Celsius in this case. Make sure to place the sensor near the heat lamp to get a good reading.

Step 2: Sensors - Push Button

Plug the push button into D8 for digital input. When you press the button for a second, it will turn the ventilator fan on or off the manually.

Step 3: Sensors - LED

The LED light is an indicator for the ventilator, that is, the LED is ON when the ventilator is ON. It needs to be plugged into D2.

Step 4: Sensors - 5V Ventilator

This device is not part of the Grove Starter Kit, so the wiring is a bit more complex. To power the ventilator, the 5V input wire needs to go into digital pin ~3 as labeled on the side of the board and the Power GND wire needs to go into one of the GND pins on the other side of the board. Make sure not to swap these because it will cause the ventilator circuitry to burn and become unusable. Point the ventilator at the heat lamp so that it cools it down when turned on.

Step 5: Sensors - Relay and Heat Lamp

The relay is plugged into D4 and is responsible for controlling the heat lamp. The heat lamp requires its own external power source in this case as it needs more than 5V, which is the maximum voltage the Intel® Edison board can supply, hence the relay will act as the electronic switch between the board and the lamp to turn it on and off. To connect the heat lamp to the relay, connect the relay’s NO contact (on the left) to the positive contact on the lamp and the CO contact (on the right) to the positive contact that goes into the power source. For the ground, connect the lamp to the power source ground directly.

Step 6: Sensors - LCD

The LCD can go in any of the four I2C slots. The LCD displays the temperature value and the background color changes from green to orange and red depending on thresholds that are passed (below 30 is green, between 30°C and 40°C is orange, and above 40°C is red).

Step 7: Power

Now you can power on the board and the lamp. Plug in the 220V->11.5V converter for the heat lamp; it will not turn on until the Intel® Edison switches the relay on. Next insert the power plug into the Intel® Edison board and the other end into a power outlet. A green light will display on the board.

Step 8: Connect to Wi-Fi*

Next, you need to configure the Intel® Edison board to connect to the local wireless network. Make sure the micro-switch is towards the micro USB slot’s side and connect the micro-USB cable to the connector closest to the corner of the board to a PC/Mac. This micro-USB cable slot is for serial connection communication (puTTY). You do not need to use the other micro-USB slot, it is for power (which was connected above with the power supply directly), Ethernet, Arduino* sketches, and storage devices.

If the Wi-Fi signal is low or weak, plug in the external antenna to the Intel® Edison board as shown below.

PC instructions:

a. Once the USB cable is plugged in, the Intel® Edison board will appear in the Device Manager under Ports (COM &LPT) as a ‘USB Serial Port’. Remember the COM number for the next steps.

b. Next download PuTTY to make a serial connection from the computer to the board. http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

c. Open PuTTY, select connection type Serial, and then enter in the value for Serial line as the COM port obtained in the previously, COM7 in this case. For Speed type in 115200. Then click Open.

Mac* instructions:

a. Open a terminal window (to find one, use Spotlight to search for ‘terminal’) and enter the command ls /dev/tty.* to identify the USB serial port name.

b. Download goSerial* to make a serial connection from the computer to the board. http://www.furrysoft.de/?page=goserial

c. Open goSerial, select the Serial Port usbserial and select the Speed 115200. Click OK.

A serial window should now be open on your PC or Mac computer:

If nothing appears initially, press Enter. A screen of scrolling text indicates that the board still booting, it will finish after a few minutes.

If you have not configured your board yet, login with username root and execute the command configure_edison --setup to set up a password. Otherwise login as username ‘root’ with your password.

Then type in configure_edison --wifi and a list of available networks will appear after it scans for a couple seconds. If your network is not listed, it might be a hidden network. Select your network or the hidden network option.

It will ask to confirm that the network is correct. Type y and press Enter. If you selected a hidden network, it will prompt you for the network name.

Then type in the network password if prompted.

The Intel® Edison board is now connected to the Wi-Fi network.

You can confirm this by going to http://'Edison ip address' from the browser on your computer as long as your computer is on the same network. Or type in wpa_cli status in the serial window and make sure that wpa_state is COMPLETED and there is an ip_address assigned.

Step 9: IoT Cloud

The data and control rules are stored in the cloud in the Intel® IoT Developer Kit Cloud-based Analytics system. Every five seconds the Intel® Edison sends the recorded temperature value to the cloud where it is displayed in a graph. The system also checks to see whether the data triggers any of the rules and sends a signal back to the Intel® Edison board if necessary.

IoT Agent Website: https://dashboard.us.enableiot.com/ui/auth#/login

If you do not already have an account, have not installed the IoT Agent on the Intel® Edison board, or activated your device yet, the setup instructions are here: https://software.intel.com/en-us/node/530666

The IoT Agent already has several default components
available for use with data collection. In this case the temperature.v.10 and the powerswitch.v1.0 component fit the need for this HVAC system. To register them for the board to start using, enter the following into a serial connection window:

iotkit-admin register temp temperature.v1.0

iotkit-admin register relay powerswitch.v1.0

The ventilator and heat lamp rules need defined on this website as well.

Step 10: IoT Cloud - Setting Up Controls

Click button on the top right side to display for the side menu, and then click on Control. This opens the Controls window for sending commands to the board. Select your device, the relay powerswitch component, the LED(0,1) for the parameter name with a value of 1, and click Add action. Next click Save as complex command and call it ventilator_ON. Repeat this again and instead use parameter value of 0 and call it ventilator_OFF.

Step 11: IoT Cloud - Setting Up Rules

Now you are ready to create the rules to trigger the commands. Click Rules on the side menu to open the My Rules window that shows the active and archived controls for the demo on the Intel® Edison board. You will create two rules, one for when the temperature is below 30° C it sends a notification to the board telling it to turn the ventilator off and the heat lamp on. And a second rule for when the temperature rises above 40° C, it sends a notification to turn the ventilator on and the heat lamp off.

To create the below 30° C rule, click Add a rule. Give it a name, description, priority, and choose notification type of Actuation. Choose the actuation of ventilator_OFF. Click Next and select your Intel® Edison device. Click Next again and check Enable Automatic Reset, choose temp as the ‘Monitored Measure’ and have it ‘Trigger When’ the Basic Condition is set to < 30. Then click Done. Repeat for the above 40° C rule but send the ventilator_ON actuation and choose > 40 for the ‘Trigger When.’

Step 12: Code

The following is the code to use with the Intel® XDK. You can learn more about getting started and how to run an application here: https://software.intel.com/en-us/getting-started-...

var mraa = require('mraa');

var dgram = require('dgram');

var mqtt = require('mqtt');

var fs = require('fs');

var upm_lcd = require ('jsupm_i2clcd');

var tempSensor = new mraa.Aio(0); // temperature sensor connected to analog IO pin 0

var powerswitch = new mraa.Gpio(8); // push button connected to digital IO pin 8

var led = new mraa.Gpio(2); // LED connected to digital IO pin 2

var ventilator = new mraa.Gpio(3); // ventilator connected to digital IO pin 3, i.e. red cable ( 5 V ) to GPIO 3 on breakout board and black cable ( ground ) to GND.

var relay = new mraa.Gpio(4); // relay connected to digital pin 4

var lcd = new upm_lcd.Jhd1313m1(6, 0x3E, 0x62); // LCD connected to the I2C bus, any connector on I2C will do.

powerswitch.dir(mraa.DIR_IN);

led.dir(mraa.DIR_OUT);

ventilator.dir(mraa.DIR_OUT);

relay.dir(mraa.DIR_OUT);

// Touch Sensor Parameters

var ventilatorON = 0; /* for this demo, ventilatorON is equivalent to light ( =heat source ) off */

var switchstate = 0;

// Temperature Sensor Parameters

var B = 3975;

// Create MQTT Client

var mqttClient = mqtt.createClient(1884);

// Create UDP Client

var udpClient = dgram.createSocket('udp4');

// UDP Options

var rec_port = 41235;

// LCD Parameters

var lcdMessage = "";

// LCD Setup

lcd.write("Intel Edison");

lcd.setCursor(1,0);

lcd.write("TEMP: ");

led.write(0);

ventilator.write(0);

relay.write(1);

// Start Activities

touchActivity();

lcdTempActivity();

function touchActivity()

{

switchstate = powerswitch.read(); //read the digital value of the pin

if(switchstate == 1 ) /*change ventilatorstate */

{

if ( ventilatorON == 0 )

{

relay.write(ventilatorON);

ventilatorON = 1;

}

else

{

relay.write(ventilatorON);

ventilatorON = 0;

}

led.write(ventilatorON);

ventilator.write(ventilatorON);

}

setTimeout(touchActivity,1000); //check every second ( = 1000 millisec ) for status of the switch.

}

function lcdTempActivity() {

// Get temperature

var reading = tempSensor.read();

var resistance = (1023 - reading) * 10000 / reading; // Get the resistance of the sensor

var temperature = (1 / (Math.log(resistance / 10000) / B + 1 / 298.15) - 273.15).toPrecision(3); // Convert to temperature via datasheet

lcdMessage = temperature + " C";

lcd.setCursor(1,6);

lcd.write(lcdMessage);

if(temperature > 40 )

{

lcd.setColor(255,0,0); // Color screen red above 40 degrees

}

else if(temperature > 30)

{

lcd.setColor(255,100,0); // color screen orange above 30 (and below 40 ) -- zone where ventilator will switch on automatically -- need 2 rules in IOT Analytics tool.

}

else

{

lcd.setColor(0, 255, 0); //Green as long as temp is below 30

}

// Send observation to the cloud

sendObservation("temp", temperature, new Date().getTime());

setTimeout(lcdTempActivity,5000); /* update tempearture every 5 sec */

}

// Send observation to the cloud (MQTT)

function sendObservation(name, value, on) {

var msg = JSON.stringify({

n: name,

v: value,

on: on

});

//console.log("Sending observation: " + msg);

mqttClient.publish("data", msg);

}

// listen for UDP message from local agent

udpClient.on("error", function (err) {

console.log("udpClient error:\n" + err.stack);

udpClient.close();

});

udpClient.on("message", function (msg, rinfo)

{

var sensorName = "LED"; /* ventilator is the component defined in the Analytics tool */

console.log("udpClient got: " + msg + " from " +

rinfo.address + ":" + rinfo.rec_port);

// Ignore messages unless they are local

if(rinfo.address != "127.0.0.1")

{

console.log("Ignoring remote UDP message");

return;

}

var js = JSON.parse(msg);

var component = js['component'];

var command = js['command'];

var argvArray = js['argv'];

console.log("component: " + component);

console.log("command: " + command);

for(var i = 0; i < argvArray.length; i++)

{

var name = argvArray[i]['name'];

var value = argvArray[i]['value'];

console.log("name: " + name);

console.log("value: " + value);

if (name == sensorName)

{

console.log("cloud (de)activation command for ventilator received");

if(parseInt(value) == 1 ) /*switch ventilator ON */

{

if ( ventilatorON == 0 )

{

relay.write(ventilatorON);

ventilatorON = 1;

led.write(ventilatorON);

ventilator.write(ventilatorON);

}

}

else

{

if( ventilatorON == 1 )

{

relay.write(ventilatorON);

ventilatorON = 0;

led.write(ventilatorON);

ventilator.write(ventilatorON);

}

}

console.log("Ventilator state changed through cloud command to :" + ventilatorON );

}

}

});

udpClient.on("listening", function () {

var address = udpClient.address();

console.log("udpClient listening " +

address.address + ":" + address.port);

});

udpClient.bind(rec_port);

Make sure the package.json has MQTT listed in the dependencies.

{

"name": "blankapp",

"description": "",

"version": "0.0.0",

"main": "main.js",

"engines": {

"node": ">=0.10.0"

},

"dependencies": {

"mqtt": "^0.3.8"

}

}

Step 13: End

About the Content Creator

Dirk Roziers is an IoT Developer Community Evangelist in the Software and Services Group, working on building out and supporting an Intel IoT developer community in EMEA.

About the Author

Whitney Foster is a software engineer at Intel in the Software Solutions Group working on scale enabling projects for Android applications and IOT.

Notices

No license (express or implied, by estoppel or otherwise) to any intellectual property rights is granted by this document.

Intel disclaims all express and implied warranties, including without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement, as well as any warranty arising from course of performance, course of dealing, or usage in trade.

This document contains information on products, services and/or processes in development. All information provided here is subject to change without notice. Contact your Intel representative to obtain the latest forecast, schedule, specifications and roadmaps.

The products and services described may contain defects or errors known as errata which may cause deviations from published specifications. Current characterized errata are available on request.

Copies of documents which have an order number and are referenced in this document may be obtained by calling 1-800-548-4725 or by visiting www.intel.com/design/literature.htm.

Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.

*Other names and brands may be claimed as the property of others

**This sample source code is released under the Intel Sample Source Code License AgreementLike SubscribeAdd new commentFlag as spam .

© 2015 Intel Corporation.Flag as inappropriate Flag as Outdated

Comments

author
IoT-Platform (author)2016-12-25

Nice work.. will be interesting to see such stuff coming out as Services on a Platform!

author
Brunohais (author)2015-12-25

Brilliant Project....

author
varerysan (author)2015-12-12

I think it's not good to connect fan directly to digital pin because maximum current that allows an output pin in the Arduino Expansion Board is 32mA at 5V, and 24mA at 3.3V. Fan may damage the pin. Better to use relay of motor driver.