How To Build Arduino Thermal Camera

I recently worked on an Arduino project to create a low-cost thermal camera using an IR sensor and pan/tilt hardware. When observing the device image on the left, you will notice an acoustic range finder attached to the top as well.

Arduino Thermal Camera

The tool functions by scanning a pattern of dots and constructing the picture gradually. The result includes two images: 1) an acoustic image showing the distance to the objects in sight and 2) a thermal image displaying the temperature of the objects in sight. I utilize gnuplot for compiling the images. Check out the following scripts.

My intention is to utilize the range finder for determining the spot size of the IR reader. The size of the spot increases proportionally with dh_o/dL=2sin(5). dh_o represents the variation in spot diameter while dL stands for the alteration in distance between the sensor and the object. The five is a constant determined by the 5-degree angle at which the IR sensor can view.

I got the idea for the project from this site: http://www.cheap-thermocam.tk/

 

Assembly progression:

  1. Put together Pan/Tilt with servos. Employ medium-sized servos instead of small ones for the tilt action as the small servos were not powerful enough (observe jitteriness in the video). The servos need a 5V input.
  2. Connect the Ultrasonic transducer to a proto board by threading a wire through holes and soldering on both sides. (ensure holes are aligned on both boards) Place the ultrasonic sensor in the center of the main board so that the ir sensor will be aligned with the center of the ultrasonic sensor.
  3. Installed the laser mount onto the Pan/Tilt hardware with the two right angle mounting holes positioned on the top side for board connection. I utilized the extra screws from the servo to attach the laser mount. I started by making a hole that was just a little bit smaller than the diameter of the screw thread.

Arduino Thermal Camera circuit

  1. Insert the laser completely into the laser holder. Halt and tinker with the laser and basic servo project.
  2. Next, install a 3V power line and ground line, ensuring there is excess wire for flexibility. The ultrasonic transducer is compatible with either 3V or 5V power supply, with the latter providing better resolution. The maximum voltage that the IR sensor is able to handle is 3V. My setup utilizes 3 volts for both the infrared and ultrasonic sensors.
  3. Carefully place the IR sensor and solder the leads without trimming them. Then, connect your 4.7K ohm resistors starting from the power source and leading them towards the ir sensor located on the opposite side of the board.
  4. Create the connections on the board at this point.
  5. Include three additional wires to connect from the board to the arduino. One is allocated for the ultrasound sensor and the ir sensor has two allocated.
  6. Attach the sensor to the laser mount. Utilize the openings on the laser mount. I utilized the additional screws from the servos to create corresponding holes on the sensor board through drilling. It is crucial that all things are aligned at perfect right angles.
  7. Connect the laser wires to the 3V power source (red wire) and ground (white wire).
  8. Now create the connections on the board.
  9. Include three additional wires to connect from the board to the Arduino. One is for the ultrasound sensor and the ir sensor have two.
  10. Attach the sensor to the laser mount. Utilize the openings on the laser bracket for proper installation. I utilized the surplus screws from the servos to create corresponding holes on the sensor board through drilling. It is imperative that everything is perfectly square.
  11. Attach the laser wires to the 3V power (red wire) and GND (white) for connection.
  12. Attach the two power cables and three data cables to an intermediary board (obtained from Radio Shack and cut in half with a coping saw). This middle board will facilitate your move to the arduino pins. I attach 3-pin male headers to this middle board in order to accommodate the servo connectors. Therefore, if a servo gets damaged, there is no need for me to solder it again.
  13. By utilizing the middle board, you are able to establish a shared foundation.
  14. Now, alter the plastic image container to accommodate the servo on the top and allow the wires to pass through the top. I located the middle of the top, marked the size of the servo, drilled holes, and cut out the opening. Next, I made holes to fasten it to the plastic using the hardware for mounting included with the servo. I also removed a rectangular piece from the side to accommodate the usb and power. I positioned the arduino inside the casing, outlined the overall shape, and once more utilized a coping saw to create the hole.
  15. I attached standoffs to the base of my Arduino and simply used hot glue to secure them to both the enclosure and the Arduino’s bottom.
  16. Proceed by passing wires from the sensors through the holes to the middle board and then solder them. Additionally, attach cords to the middle board in order to link them to the arduino.
  17. I applied hot glue to the arduino wires to prevent them from becoming loose.
  18. Seal all openings and use hot glue along the perimeter of the casing to secure it.
  19. Insert USB and plug in power, then upload the code below.

Arduino code:
The program won’t start until you open a serial connection and hit ‘1’ and Enter. It will then outline the area of interest. To proceed hit ‘1’ and Enter again. The arduino will begin to collect data in a 2d array that it will output to the screen when completed.

//Arduino Thermal Camera
#include <i2cmaster.h>
#include <Servo.h>

Servo mvert;
Servo mhorz;

// Pins: 7=sonar; 4&5=ir sensor; 8=vert servo; 9=horz servo
//
//
//
const int pwPin = 7;
const int dev = 0x5A<<1;

long count = 0;

///Servo Ranges
int home_p = 0;
int j_done = 0;
int even = 0;
int xskip = 1;
int yskip = 1;
int xstart = 60;
int xstop = 75;
int ystart = 80;
int ystop = 70;

const int xnum = abs(xstart-xstop)+1;
const int ynum = abs(ystart-ystop)+1;

double therm[16][11];
double acous[16][11];

void setup(){

//sonar pin
pinMode(pwPin, INPUT);

//Servo pins
mvert.attach(8);
mhorz.attach(9);

//Home position servos
mvert.write(xstart); //1485
mhorz.write(ystart);  //1530

Serial.begin(9600);
Serial.println("Setup...");

i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups

}

void loop(){

int i,j,jt;
int hpos,vpos,hpos2,vpos2;
double tempData1 = 0x0000; // zero out the data
double sonrData1 = 0x0000;

if(Serial.available()){

if(home_p == 0){
i = 0;
Serial.flush();
Serial.println("Sweeping Viewing Space");
Serial.println("Enter 1 to confirm space");
mvert.write(ystart);
mhorz.write(xstart);
delay(30);
do
{
//This will sweep through window of view
for(int hpos=xstart;hpos<=xstop;hpos++){
mvert.write(ystart);
mhorz.write(hpos);
delay(20);
}
for(int vpos=ystart;vpos>=ystop;vpos--){
mvert.write(vpos);
mhorz.write(xstop);
delay(20);
}
for(int hpos=xstop;hpos>=xstart;hpos--){
mvert.write(ystop);
mhorz.write(hpos);
delay(20);
}
for(int vpos=ystop;vpos<=ystart;vpos++){
mvert.write(vpos);
mhorz.write(xstart);
delay(20);
}
i=Serial.read();
}while (i<=0);
Serial.println("Starting Calculation");
home_p=1;
}

if(j_done == 0){
for(int i=ystart;i>=ystop;i-=yskip){
for(int j=xstart;j<=xstop;j+=xskip){
if(even == 0){
jt = j;
mhorz.write(j);
delay(20);
}
else{
jt=xstop-(j-xstart);
mhorz.write(jt);
delay(20);
}

sonrData1 = readSonar(1);
tempData1 = readMLX(1);

//58uS per cm
double cm = sonrData1;
double celcius = tempData1 - 273.15;
//double fahrenheit = (celcius*1.8) + 32;

//Serial.print("temp,dist,i,j: ");
//Serial.print(celcius);
//Serial.print(", ");
//Serial.print(cm);
//Serial.print(", ");
//Serial.print(ystart-i);
//Serial.print(", ");
//Serial.println(xstop-jt);
//Serial.print("Fahrenheit,inches: ");
//Serial.println(fahrenheit,inches);
therm[xstop-jt][ystart-i] = celcius;
acous[xstop-jt][ystart-i] = cm;
delay(400); // wait a second before printing again
}
mvert.write(i);
delay(20);
if(even == 0){
even = 1;
}else{
even = 0;
}
}
//Output data
Serial.println("Outputting Data");
for(int j=0;j<ynum;j++){
for(int i=0;i<xnum;i++){
Serial.print(therm[i][j]);
Serial.print(", ");
Serial.print(acous[i][j]);
Serial.print(", ");
Serial.print(i);
Serial.print(", ");
Serial.println(j);
Serial.flush();
}
Serial.println(" ");
}
j_done = 1;
}
}}

double readMLX(int Tt) {

int data_low = 0;
int data_high = 0;
int pec = 0;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);

// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point

// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.228;

return tempData;
}

double readSonar(int St) {

long pulse;

//Used to read in the pulse that is being sent by the MaxSonar device.
//Pulse Width representation with a scale factor of 147 uS per Inch.
pulse = pulseIn(pwPin, HIGH);

double sonrData = (double) ((pulse)/58.0);

return sonrData;
}

Gnuplot code:
I will correct this issue later, for now, just transfer the data displayed on the screen from the code above into a file named data.txt. The units are in Celsius for temperature, in centimeters for distance, and in x-y coordinates. Next, make a new file named _plot.gnu and insert the following code into it. Next, you can run the gnuplot script by entering gnuplot ./_plot.gnu . Ensure that both data.txt and _plot.gnu are located in the identical directory.

Major Components in Project

List of materials:

Source : How To Build Arduino Thermal Camera

 


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top