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); } }
|