Installing the InfraRed sensor Library
With everything wired up the next step is to get the appropriate library for the IR sensor into the Arduino IDE. Download the library from http://wiki.wiring.co/images/3/31/I2Cmaster.zip and save it somewhere. If you have an older version of the Arduino IDE you can import the library by choosing the menu item Sketch → Import Library… → Add Library… and navigate to where you saved I2Cmaster.zip to. Import this file.
On more recent versions of the Arduino IDE choose the menu item Sketch → Include Library… → Add .ZIP Library… and import the file.
Calibrating The Y Servo
This servo requires a little calibration to ensure it is sitting in the gimbal correctly.
We'll use a small, dedicated program for this. Load the example program Sweep from the Arduino IDE menu via File → Examples… → Servo → Sweep.
Looking at the program you can see the line myservo.attach(9); in the setup() function. As the Y servo is connected to D10 on the Arduino change the 9 to a 10 in this line of code. The relevant snippet of code that you need to change is shown below:
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
Now the correct pin on the Arduino is being used for our servo, the next step is to alter the for loops in the loop() function. This allows us to determine the start and ending positions (i.e the range) for the Y servo. The relevant code that needs to be changed is shown below.
void loop()
{
for(pos = 70; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos >= 70; pos -= 1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
The up and down motion of the servo will be controlled by these two for loops. The code in blue determines the downward direction of the sweeping, while the code in red makes the servo reverse and go upwards - over the maximum range of 180 degrees. The values for pos state where within the 180 range the servo is to operate. The code above uses the maximum range but we will be using a narrower range.
Connect the X servos signal pin ( yellow pin ) to Pin 9 on Arduino and confirm the Servo is free to do the complete sweep from 70 to 180 degrees.
If it is unable to do the complete sweep, unscrew the servo horn and refit it such that it can do the sweep without problems.
Repeat the same exercise with Y servo and confirm it is able to move freely. Once its done you are ready to move on to next stage.
Connecting The Arduino
Power on the breadboard power supply and connect the Arduino Nano via USB cable to your computer. You may hear the servos make a short sound as power is applied.
Windows
If this is the first time an Arduino has been plugged into your computer you'll notice a device driver will install. When this has completed you may notice a pop up notification in the lower right corner of your screen. It will mention a COM port, possibly COM4. Whatever it is on your computer make a note of what this is.
Alternatively, if you missed what COM port is being used you can always look in the Device Manager. Click on the triangle next to Ports (COM & LPT). This will list all COM ports on the computer but the important one to note has the name USB-SERIAL and the COM port alongside it in brackets. This could be COM4, COM5, or even COM6 depending on which USB port you are using.
Be aware that if you unplug the Arduino from a USB port and plug it into a different USB port without restarting the computer, the COM port may change.
Linux
Open a terminal window and plug in the Arduino. Then issue the command dmesg and you should get output like the following:
[49929.980829] usb 2-1.4: new full-speed USB device number 6 using ehci-pci
[49930.074517] usb 2-1.4: New USB device found, idVendor=1a86, idProduct=7523
[49930.074523] usb 2-1.4: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[49930.074527] usb 2-1.4: Product: USB2.0-Serial
[49930.074913] ch341 2-1.4:1.0: ch341-uart converter detected
[49930.076844] usb 2-1.4: ch341-uart converter now attached to ttyUSB0
Looking at the last line of the output we can see our Arduino can be addressed at /dev/ttyUSB0. Sometimes the dmesg output may show ttyACM0. If this is the case, use /dev/ttyACM0.
Uploading Sweep Code
Before uploading the program check that you have the correct Arduino type selected. In the Arduino IDE, go to the Tools → Board menu and choose Arduino Nano w/ ATmega 328 or just Arduino Nano if that's the closest option. Also under the Tools menu, ensure you have the Arduino selected from the Serial Port or similarly named Port menu. If you are using Windows select the COM port noted from before or if using Linux choose /dev/ttyUSB0 or /dev/ttyACM0 as appropriate.
With that done we're ready to upload. Choose File → Upload on older versions of the Arduino IDE or Sketch → Upload on newer versions. Alternatively, use the keyboard shortcut Control + U. This will check the code is correct enough for the Arduino to run, compile and upload it.
The Y servo should start operating in an up-down fashion. If it appears to go to left-right instead then check you have everything wired up correctly and that you changed the value 9 to 10 in the setup() function. If it does not seem to work at all, check your wiring connections are firm and check the schematic to ensure wiring is correct.
Testing
Listen and watch the servo move. If at any point you think you hear what might be a grinding sound then disconnect the USB cable and switch off the breadboard power supply immediately. It might be that the servo needs to be adjusted in the gimbal as the likelihood of grinding or popping out of the gimbal will be determined by how the servo was installed. Adjust the servo in the gimbal as necessary and try again, but perhaps adjust its positioning.
As the Y servo moves up and down note where the IR sensor points as this arc creates the height of the heatmap image. If you feel it points in the wrong direction, for example, it points upwards too much and you'd rather it spent more time facing forward, then this can be changed.
To do this, as the gimbal approaches the upmost position, unplug the USB cable and turn off the power to the breadboard power supply to make it stop completely. With the servo near the top of its range in the stopped position you can now remove the white servo arm and adjust the top part of the gimbal as you need. You'll likely only need to move it a small amount unless it is wildly out.
Reattach the white servo arm, screw it in place and turn on power to the breadboard. Watch the Y servo again and check to see that the range of movement is more or less what you need. If not simply repeat the steps above until it's correct. Then you can install the screw in the servo arm.
Uploading IR code to the Arduino Nano
Grab the heatSensor.ino sketch and load it into the Arduino IDE.
After uploading code the Arduino should output data which can be seen in the Arduino IDE's serial monitor. You can view this output by choosing Tools → Serial Monitor or by using the keyboard shortcut Control + Shift + M.
At this point the Arduino will reset and run the code from the beginning again. You should see a series of lines with comma separated values being produced where each line shows the temperature as recorded by the IR sensor and the x and y coordinates of the servos, like in the example below:
26.00,180,110
26.00,179,110
26.50,178,110
26.35,177,110
26.00,176,110
26.00,175,110
...
If you do not see output, or the output appears garbled, ensure the baud rate on the Serial Monitor is set to 57600.
Installing Oracle Java 8
The IR thermal viewer requires Oracle Java 8 rather than OpenJDK Java. If you are using Microsoft Windows, Java can be downloaded from http://www.java.com/. Once installed, Java needs to be useable from the Command Prompt. The Java installer should take care of this but to confirm, open a Command Prompt window and type java -version. You should see output similar to this:
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode, sharing)
If you get an error then your Java may not be complete. Check out the help at http://www.java.com/ and try again.
If you are using Ubuntu Linux, Linux Mint or another Ubuntu derived distribution there is a handy repository with instructions for installing Oracle Java at http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html. Otherwise you can always get it direct from Oracle's website at http://www.java.com/en/download/manual.jsp#lin if you are using a different distribution of Linux.