1. Starting on the Project, “My Own Thermometer” Hi. This time, I’ll show you how sensor and actuator are working together. I call this project as ‘My Own Thermometer’. I do not know which board you are using among ‘Galileo 1’, ‘Galileo 2’ and “Edison”. If you are using the board for the first time, first install JDK(Java Development Kit). Because I’m using 64bit Windows OS, I downloaded the JDK at www.iotedu.co.kr accordingly. Download ‘arduino1.5.3-intel.1.0.4’ folder from www.iotedu.co.kr and put it at C:\ directory. If there is an existing Arduino IDE icon at ‘taskbar’ in your PC, delete it. Click IDE icon located in the ‘arduino-1.5.3-intel.1.0.4’ folder with the mouse right button and select ‘Pin to Taskbar’.
Are you using ‘Edison’ as I am? There are three kind of Edison: ‘Intel® Edison Module‘, Intel® Edison Breakout Board Kit’ and ‘Intel® Edison Kit for Arduino’. From now on, if I say Edison I do mean the ‘Intel® Edison Kit for Arduino’ which is actually ‘Intel® Edison Module’ plus ‘Intel® Arduino expansion board’.
Make sure mount the Edison Module to the Arduino expansion board and install 4 plastic placers properly. You can notice that there is no power adapter in Edison.
For this experiment, USB cable is enough to apply power and upload compiled source code to Edison. Find the microswitch in between the USB ports on the expansion board. Switch the microswitch toward to the micro USB ports. Now, plug the USB cable between the top micro-USB connector on the expansion board and your PC.
In ‘Control Panel’ of your PC, click ‘System and Security,’ ‘System,’ and ‘Device Manager’ in order. Can you see ‘CDC Serial’ and ‘RNDIS’ under ‘Other devices’? It’s time to install the Intel Edison software driver.
Download ‘IntelEdisonDriverSetup1.0.0.exe’ from www.iotedu.co.kr and install it. If you see ‘Intel Edison Virtual Com Port(COMx)’ under ‘Port (COM&LPT)’ then you completed the installation.
If you are using Galileo 1 or 2 for the first time, apply power and connect USB cable between the board and PC. In ‘Control Panel’ of your PC, click ‘System and Security,’ ‘System,’ and ‘Device Manager’ in order. Can you see ‘Gadget Serial v2.4’ under ‘Other devices’? Right-click it and select ‘Update Driver Software..,’ then click ‘Browse my computer for driver software.’ Click on ‘Browse..’ and search to the ‘tools’ folder from the ‘arduino-1.5.3-intel.1.0.4” folder in a new small window. Click ‘OK’ and the small window will be closed. Now, click ‘Next’ to finish to install the Galileo driver.
If you see ‘Galileo(COMx)’ under ‘Port (COM&LPT)’ of ‘Device Manager’ then the installation is completed! Whenever you power on Galileo and connect a USB cable, you need to wait until you can see ‘Galileo(COMx)’. Are you a ‘Galileo 1’ user and want to keep it for this experiment or changed it to ‘Galileo 2’? Connect the power cord and the USB cable to the board. In ‘Control Panel’, click ‘System and Security,’ ‘System,’ and ‘Device Manager’ in order. Rightclick the ‘Galileo(COMx)’ and select ‘Uninstall’. Check in the box of ‘Delete the driver software for this device’ and click ‘OK’. If you can see ‘Gadget Serial v2.4’ under ‘Other devices’, take the same steps that were mentioned before.
You need to update the firmware of your board especially if you are ‘Galileo 1’ board because it is relatively old one and may not work properly with the new Software. First, make sure you are connected to internet. Go to the Arduino IDE and click ‘Help’ menu then select ‘Galileo Firmware Update’.
2. Understanding the ‘Temperature sensor’ and bringing a Sketch for it Before we make our own thermometer, we need to know about the ‘temperature sensor’ which is the Input deceive that detects surrounding temperature.
I chose ‘TMP36’ produced by ‘Analog Devices’.
‘TMP36’ is one of the most
commonly used temperature sensors, as it is easy to use and has a wide measurement range.
The range is from -40 degrees to 125 degrees, and it is possible to measure temperature below zero. It is not suitable for precise measurement because the accuracy deviation is about 2 degrees. Take out three Jumper wires and a ‘bread board’ from the Starter Kit. Plug the ‘TMP36’ into the ‘Bread Board’.
Face the ‘temperature sensor’ so that you can read the letters ‘TMP36’ on it, and
connect the left pin to Edison’s 5V. Connect the middle pin to Edison’s A0 and the right pin to Edison’s GND. Now apply power to Edison.
Connect the USB between Edison and PC. Before the experiment, I downloaded ‘Tsenor’ folder from www.iotedu.co.kr and copied it to the desktop of PC.
Go to the ‘Device Manager’. Do you notice ‘Intel Edison Virtual Com Port’ at ‘Ports(COM&LPT)’? You need to remember the COM number. Then open the
‘Arduino IDE’. Make sure that ‘Serial Port’ in the Tools’ menu is selected with right COM number and the ‘Board’ is checked as Edison.
Lastly, click the ‘File’ menu and select ‘Open’. Find the ‘Tsensor’ folder on the desktop and select the ‘Tsensor.ino’ file in the folder.
3. Review a Sketch to check the operation of the ‘temperature sensor’
Click the ‘Upload’ icon under the menu bar. You can see a message saying that compile is complete on a black screen in the bottom of IDE.
Click the ‘Serial Monitor’ on the right end of the line in which ‘Upload’ icon is located. In the new screen, you will see that current temperature keep printing in Celsius and Fahrenheit in real time.
Let’s have a look at the source code. The part within the red outline is the source code that receives the input from ‘TMP36’ and calculates to the real temperature based on ‘TMP36’ specification. The calculating process differs for each temperature sensor.
‘analogRead()’ command receives the input from the temperature sensor. There is an ADE component in Edison, which changes analog input values from 0
to 5 volt to digital values ranging from 0 to 1023. The part within the arrow shape is the source code that allows us to print the information in the ‘Serial Monitor’ window as we want.
Hold the ‘TMP36’ with your fingers. Do you see that the serial monitor numbers are changing? The Input value increases as our finger heat is added on to it. Now, take your hands off, and you will notice that the input value decreases. Until the next experiment, disconnect the power and the USB cables from Edison.
4. ‘Servo motor’ and ‘PWM’ Output We call it an ‘actuator’ if it can move or controls an object through energy source like electricity. Unlike ‘DC motor’, the movement range of the ‘servo motor’ is constrained from 0 degree to 180 degrees, and you can check the angle using a ‘horn’ which is bundled with ‘servo motor’.
One of the most important characteristics of ‘servo motor’ is it can rotate to a specific location by a command and it stays in the location until it gets another command to move to a different location. Therefore, you can use it in a ‘door lock’ or use it to change the direction of the car or to control ‘drone’. The product I will use for this experiment is Hextronik’s ‘HXT900’. Horn is a stick that is attached to the shaft of the ‘servo motor’. Its angle is determined as the PWM signal is delivered to the ‘servo motor’. Therefore, the ‘servo motor’ should be connected to the pin that is applicable for PWM. The PWM technology or “Pulse Width Modulation” uses the ‘Duty Cycle’ concept to change amount of Energy after shortening the cycle of Pulse extremely.
Let’s say that the pulse signal is 5V. If the signal is on for the 20% of the cycle and off for the rest of the cycle, we say that the duty cycle is 20%. For instance, if we set the ‘Duty Cycle’ as 20% using PWM, only 20% of the energy is generated and transferred. PWM creates the Analog effect, so we use “analogWrite()” command. However, PWM is actually a digital technology, which operates only in digital pins which have ‘tilt’ symbol on Edison.
5. Connection and Sketch to check operation of the ‘servo motor’
To confirm if the ‘servo motor’ operate properly, first thing I need to do is selecting three Jumper wires from the starter kit that have similar colors with the built in lines of the ‘servo motor’. Then by matching the color, connect the Jumper wires into the connector of servo motor. Now we need to connect the opposite end of the jumper wires to Edison board.
Connect the darkest colored jumper wire to Edison’s GND pin. Connect the jumper wire in the middle to Edison’s 5V pin and the remaining jumper wire to Edison’s Digital pin 5. The reason I chose the 5th pin is because it supports the PWM function. To start the real experiment, connect power to Edison and connect a USB cable between Edison and PC.
I downloaded the ‘Servo’ folder from www.iotedu.co.kr and copied it to ‘desktop’ of my PC. Let’s open the sketch to check operation of servo motor. Frist, bring ‘Arduino IDE’ by clicking its icon in the taskbar. Select the ‘File’ menu and open the ‘Servo.ino’ file in the ‘Servo’ folder on the desktop in your PC.
6. Analyzing the sketch for ‘servo motor’
Look at the ’servo motor’ Sketch. The area within the outline in red on the first line shows that you declare to use the ‘Servo’ library included in Arduino IDE. Thanks to libraries, programmers can more focus on functions without considering low level details on hardware specification. The code within the blue outline defines that the variable ‘ms’ is an Instance of ‘Servo’ object. ‘ms’ acts like an avatar of ‘Servo’. The area within the green outline indicates that you use Digital Pin 5 which allows ‘PWM’ function in order to control the ‘servo motor’.
You can move the Horn by simply defining the angle within the loop function, thanks to the ‘servo’ library. For example, if the angle is coded as 90 degrees, the servo library sends the appropriate PWM signal through Digital Pin 5. ‘servo motor’ receives the PWM signal and moves the Horn according to its specification. If you code the angle as 0 degree or 30 degrees, the servo motor will move the horn accordingly. That is, we don’t need to know how the servo motor interprets and uses the PWM signal. We can simply code values of angle we want.
7. Solution to the issues in the ‘servo motor’ experiment. What would happen if you click the upload icon? You can notice that the horn of servo motor does not exactly point to 0 degree and 180 degrees. I’ll tell you why this issue happens and ho w to resolve it.
Normally, servo motor receives ‘PWM’ signal of 48Hz, or 20ms cycle pulses. Just for your reference, have a look at how the servo motor of ‘HS-55’ from ‘HiTec’ changes its horn location depending on each PWM Duty cycle. You can get an idea of relation between the angle and the duty cycle. I’m using HXT900 which has slightly different specification than the servo library in our IDE. I’ll show you why.
Open
the
‘servo.h’
file
in
the
‘arduino-1.5.3-
intel.1.0.4/hardware/arduino/edison/library/Servo’ folder.
There are 2 statements of ‘#define MIN_PULSE_WIDTH 544’ and ‘#define MAX_PULSE_WIDTH 2400’. They assume that 0 degree of servo motor is 2.7% of duty cycle (544us) and that of 180 degrees is 12% of duty cycle(2400us) respectively. You can solve HXT900 issue by changing the numbers to 450 and 2450 respectively
to comply with its specification. Click the ‘Upload’ icon and see how much it has improved. For the next step, separate the power and USB cables from Edison.
8. Connecting servo motor and temperature sensor to Edison Let’s put thermal sensor and servo motor together. I will slightly change the position of the jumper wires from the ‘bread board’ which was used at the temperature sensor experiment before. This is because we lack 5V pins on Edison’s connector.
Pick the jumper wire whose one end is connected to the 5V pin, or on the left of the temperature sensor. Plug the other end of it to a hole in the ‘+’ lane on ‘Bread Board’.
Pick the jumper wire whose one end is connected to the GND pin, or on the right of the sensor. Plug the other end of it to a hole in the ‘-‘ lane on ‘Bread Board’.
Bring a red jumper wire from the starter kit and connect it to Edison’s 5V pin and the other end to a hole in the ‘+’ lane of ‘Bread Board’.
Take out a black jumper wire from the starter kit and connect it to Edison’s GND pin and the other end to a hole in the ‘–‘ lane on the bread board. As a result, 5V and GND of the temperature sensor is connected to Edison’s 5V and GND connector pins respectively.
Now, it’s time for the servo motor. Among the three jumper wires, connect the darkest colored one to a hole in the ‘–‘ lane of the ‘bread board’. Connect the jumper wire connected to the middle of the servo motor to a hole in the ‘+’ lane. As a result, they are connected to Edison’s GND and 5V connector pins respectively.
Then, connect the remaining jumper wire of the servo motor to the digital pin 5 of the Edison board.
9. Connecting Backing sheet and bringing the final sketch To do this experiment, I have prepared some backing sheets, which look like analog thermometers. To show the current temperature measured from thermal sensor, I made an arrow and connected it to the horn of a servo motor. To experiment in a wide range of temperatures, I set each baking sheet to have a different temperature range.
For assemble, hold the servo motor in one hand and a backing sheet in other hand, and place the backing sheet on to the axis of servo motor. Next, connect the arrow which was attached to Horn to the axis of servo motor. The best is when the backing sheet is placed on the floor, which requires several trials and errors. Until then, carry out the experiment holding the backing sheet and the servo motor in your hands. Connect the power cable and the USB cable to the Edison. I downloaded the ‘MyT’ folder from www.iotedu.co.kr and copied it on to the desktop of my PC. Now I will bring the sketch for ‘my own thermometer’ experiment.
Click the file menu on the IDE screen and click open. Find the ‘MyT’ folder on the desktop and select the ‘MyT.ino’ file in the folder. This sketch is a combination of the source codes of the temperature sensor and the servo motor which we reviewed individually before.
10. Completing ‘my own thermometer’ experiment What should we do if the temperature range in the backing sheet is different from the one of servo motor? For example, the horn of servo motor moves in between 0 degree and 180 degrees. Instead, the backing sheet has ranges from 15 to 35 degrees. In this case, we should use the function called map() which maps and matches the different ranges.
The map() function calculates integers and only the integers within the designated range are returned. The decimal points are discarded without being rounded off. An important point is that the map() function does not limit the values of input and output. That is, when the real temperature goes beyond the thermometer range in the baking sheet, the calculated values that are mapped on to the servo motor also deviate from the range that the servo motor can move actually. To prevent this situation, we can limit range of values to the specific data using the constrain() function. Click ‘upload’ and ‘serial monitor’ ions respectively. Let’s solve a few problems by modifying the source code.
First, the arrow of the horn moves too sensitively. Thus, change ‘delay’ from 500 to 2000. Next, in order to get a more accurate temperature by rounding it off, we will add a line of source code.
Lastly, change two contents in the map() function
because the backing sheet in my hand ranges from 15 to 35 degrees. When you change the positions of 0 and 180 degrees in the map() function, you do not need to switch the angles marking at the backing sheet, as it goes against common sense. This is one of the strong abilities that the map() function provides.
Now click upload icon with the modified source code. Hold the ‘TMP36’
temperature sensor with your fingers for a minute and then release it. Do you see that the numbers of the serial monitor are changing? The arrow on the backing sheet also changes accordingly and properly. Congratulations!! You succeeded to experiment on your own thermometer.