3 December 2012

Analog IR Temperature gauge


Introduction:
The IRTEMP module from Freetronics is an infrared remote temperature sensor that can be incorporated into your Arduino / microcontroller projects. It can scan a temperature between -33 to +220 C, and can be operated using a 3.3 to 5V power supply. It can be powered directly from the Arduino 5V pin.  This module can also provide an ambient temperature reading if required.
The Servo used in this project is a SG-5010 standard servo which will be utilised to display the temperature reading from the IRTEMP module.



Parts Required:
Freetronics Eleven or any compatible Arduino.
Freetronics IRTEMP module
MG-995  or SG-5010 Standard servo
Mini Breadboard 4.5cm x 3.5cm
Protoshield and female header pins (not essential - but makes it more tidy)
9V Battery and Battery Clip
Wires to connect it all together

Gauge parts:
Paper (to print the face of the gauge), and some glue to stick it to the wood.
MDF Standard panel (3mm width) - for the top and base of the gauge.
Galvanized bracket (25x25x40mm)
Timber screws: Hinge-long threads csk head Phillips drive (4G x 12mm)





The Video:



The Arduino Sketch:



     The above sketch was created using Fritzing.





Arduino Code:
You can download the Arduino IDE from this site.

The IRTemp gauge requires a driver library to be installed into the Arduino IDE.
The latest IRTemp driver library can be found here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -------------------------------------------------------
Analog IR Temperature Gauge: written by ScottC on 1st Dec 2012.
http://arduinobasics.blogspot.com/2012/12/arduino-basics-analog-ir-temperature.html


 * Some of the code was adapted from a sketch by Andy Gelme (@geekscape)
 * For more information on using the IRTEMP 
 see www.freetronics.com/irtemp
 
 * IRTemp library uses an Arduino interrupt:
 * If PIN_CLOCK = 2, then Arduino interrupt 0 is used
 * If PIN_CLOCK = 3, then Arduino interrupt 1 is used
 ---------------------------------------------------------*/

#include "IRTemp.h"
#include <Servo.h> 

Servo servo1;
static const byte PIN_DATA = 2;
static const byte PIN_CLOCK = 3; // Must be either pin 2 or pin 3
static const byte PIN_ACQUIRE = 4;

static const bool SCALE=false; // Celcius: false, Farenheit: true

/* Used to capture the temperature from the IRTEMP sensor */
float irTemperature;
int temp;

/* The minimum and maximum temperatures on the gauge. */
static const int minTemp = -45;
static const int maxTemp = 135;


/* The servo minimum and maximum angle rotation */
static const int minAngle = 0;
static const int maxAngle = 175;
int servoPos;

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);



/*----------------------SETUP----------------------*/

void setup(void) {
 
 servo1.attach(9); // turn on servo
}


/*-----------------------LOOP-----------------------*/

void loop(void) {
 irTemperature = irTemp.getIRTemperature(SCALE);
 printTemperature("IR", irTemperature);

 /* If you want the ambient temperature instead - then use the code below. */
 //float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
 //printTemperature("Ambient", ambientTemperature);

}

/*-----------printTemperature function---------------*/

void printTemperature(char *type, float temperature) {
 
 temp=(int) temperature;
 servoPos = constrain(map(temp, minTemp,maxTemp,minAngle,maxAngle),minAngle,maxAngle);
 
 if (isnan(temperature)) {
 //is not a number, do nothing
 }
 else {
 
 /* To test the minimum angle insert the code below */
 //servoPos = minAngle;
 
 /*To test the maximum angle, insert the code below */
 //servoPos = maxAngle;

 /* Rotate servo to the designated position */
 servo1.write(servoPos);
 }
}

The code above was formatted using hilite.me

Notes:
Ambient temperature: If you want to get the ambient temperature from the IRTEMP module, then have a look at lines 58-59.
Servo Angles: You will notice on line 36, the maximum servo angle used was 175. This value was obtained through trial and error (see below).

Calibrating the servo angles
You may need to calibrate your servo in order to move through an angle of 0 to 180 degrees without straining the motor.Change the minAngle on line 35 to a safe value (for example: 10), and the maxAngle on line 36 to a value like 170. Remove the comment tag (//) on line 76, and then run the sketch. Lower the minAngle until it reaches the minimum value on the gauge, making sure that the servo doesn't sound like it is straining to keep it in position.

Add the comment tag (//) back in, and then take out the comment tag for line 79. And follow a similar process, until you reach the maximum value on the gauge. Once again, make sure that the servo is not making a straining noise to hold it at that value. Make sure to add the comment tag back in, when you have finished the calibration.

In this example, the servo's minAngle value was 0, and maxAngle value was 175 after calibration, however, as you can see from the video, the physical range of the servo turned out to be 0 to 180 degrees.




The Temperature Gauge Picture

The following gauge was created in Microsoft Excel using an X-Y chart.  Data labels were manually repositioned in order to get the desired numerical effect.




2 comments:

  1. Hi, I am trying to get the IRTemp sensor to work however having issues with the sample readTemperature example given with the library it continually says its Failed.

    Im currently only connecting this to computer via USB (iMac and MBP) both with the same results (ive also tested with different boards and other IRTemp sensors) with the same issue. Did you run into this early on whilst experimenting with this ?

    Currently I am just using the stackable header with breadboard wires and using that in my mini breadboard then plugging them into the appropriate PINS, which to the best of my knowledge should at least be enough to get the example working.

    ReplyDelete
    Replies
    1. Hi Paul,
      No, I did not have any issues with the module. However, I did solder some female header pins to the module to ensure I had a good connection, (see 0:43 - of the youtube video).
      Also make sure that you have the module in the correct orientation (ie make sure that you haven't got it upside down).
      The last thing to check is that you have a recent version of the Arduino Software installed, and that you install the latest library as per the following website:
      http://www.freetronics.com/pages/irtemp-infra-red-temperature-sensor-quickstart-guide#.URt1e6WsiSo

      And don't try to scan an object too close.

      Regards
      Scott


      Delete

Feel free to leave a comment about this tutorial below.
Any questions about your particular project should be asked in the ArduinoBasics forum.

Comments are moderated due to large amount of spam.