❏ Compile and run the program, and verify that you get
the output shown in Figure 11.
❏ Make sure you are clear on what is going on in this
program. If necessary, review the earlier discussion and
the source code.
void setup()
{
Serial.begin(57600);
Serial.println(“Volts to temp test. rev 1.0”);
// Look from lowest ADC reading in +10 steps
for(float i = LOW_ADC; i < HIGH_ADC; i += 10.0)
{
tempSensorADC = i;
tempSensorVoltage = (tempSensorADC *
VOLTS_PER_ADC_STEP);
tempCelsius = ((tempSensorVoltage-0.5) /
VOLTS_PER_DEGREE);
Lab 3: Sensing Temperature
For this lab, we will reuse the circuit built for the
previous labs and add the temperature sensor to it. We
won't use the light sensor in this lab, but in the next
chapter we will use both sensors together.
showIt();
}
Parts required:
// Look at highest acceptable ADC reading
tempSensorADC = HIGH_ADC;
tempSensorVoltage = (tempSensorADC VOLTS_PER
_ADC_STEP);
tempCelsius = ((tempSensorVoltage - 0.5)/
VOLTS_PER_DEGREE);
showIt();
}
1 Arduino
1 USB cable
1 Arduino proto shield and jumper wires
1 CdS light sensor
1 10,000 Ω resistor
1 MCP9700A temperature sensor
void loop()
{
// do nothing
}temp
Estimated time for this lab: 30 minutes
Check off when complete:
❏ Build the circuit shown in Figures 12 and 13.
void showIt()
{
Serial.print(“tempSensorADC = “);
Serial.println(tempSensorADC);
Serial.print(“tempSensorVoltage = “);
Serial.println(tempSensorVoltage);
Serial.print(“Temperature in Celsius = “);
Serial.println(tempCelsius);
Serial.print(“Temperature in Fahrenheit = “);
// °F = °C x 9/5 + 32
Serial.println( ((tempCelsius 9)/5) + 32);
}
// A101_ch10_sensing_temperature 8/15/14
❏ Load the following program into the Arduino IDE:
#define VOLTS_PER_ADC_STEP 5.0/1024.0
#define VOLTS_PER_DEGREE 0.01
#define temp_BASE -40.0
#define LOW_ADC 20.49
#define HIGH_ADC 358.61
#define LOW_VOLTAGE 0.5
int tempSensorPin = A1; // analog input pin for
// temperature sensor
64 November 2014
■ FIGURE 11:
Volts to
temperature
test.
■ FIGURE 12: Temperature sensor breadboard.