Вы находитесь на странице: 1из 7

PH-315 Portland State University

Temperature-Controlled Fan
By Gabriel Eng

Materials needed
 5V Power Supply
 5V, 0.20A Fan
 TIP120 NPN Darlington
 TMP36GT9Z Temperature Sensor
 1kΩ resistor
 5kΩ Potentiometer (a 1kΩ or 10kΩ should work too)
 An Arduino and Computer
 2 Ammeters

Experiment

1. Connect the fan to a 5V power supply with an ammeter inline (Fig. 1) and measure
the current passing through the fan. Make sure it is ~0.20 A.

Fig. 1. Testing the maximum fan current.


Fig. 2. Tip120 pin-out.

2. Now connect the circuit shown in Fig. 3 using a 1-kΩ resistor and a Tip120 Darlington.
Note the pin-out for the Tip120 in Fig. 2. The current through the fan should be
nearly the same as when the fan was connected directly to the power supply. The
base current should be less than 1 or 2 mA. BE SURE YOU HAVE LOW BASE
CURRENT, AS IT WILL BE SUPPIED BY THE ARDUINO, WHICH CANNOT HANDLE HIGH
CURRENTS.

Fig. 3. Testing the maximum base current with the maximum collector current.
3. Connect the Arduino to the computer ONLY and upload the following code:

//arduino code:
int fan = 9;
int tempPin = A0;
int potPin =A4;
float potCutoff = 0.1; //set this just above the minimum voltage from your pot
float tempTrigger = 20; //set this just above your room temperature.
float tempVal = 0;
float tempMv = 0;
float tempC = 0;
float potV = 0;

void setup() {
Serial.begin(9600);
pinMode(fan, OUTPUT);
}

void loop() {
tempVal = analogRead(tempPin);
tempMv = 1000*5*tempVal/1024;
tempC = .1*tempMv-50;
potV = analogRead(potPin)*5.0/1023;
if(potV>potCutoff){
analogWrite(fan, 2*255/5 + 3*255*potV/25);
}
else{
if(tempC>tempTrigger){
analogWrite(fan, 255);
}
else{
analogWrite(fan, 0);
}
}
Serial.print(millis());
Serial.print(", ");
Serial.print(potV);
Serial.print(", ");
Serial.println(tempC);
}

4. Disconnect the Arduino from the computer and connect the circuit shown in Fig. 4. BE
SURE THE ARDUINO IS GROUNDED TO THE POWER SUPPLY, BUT IS NOT
CONNECTED TO THE POWER SUPPLY’S +5V.
5. Connect the Arduino to the computer.

Fig. 4. Fan with speed controlled manually by a potentiometer.


6. Open the serial monitor. You will see three numbers separated by commas as in Fig.
5. The first number is a timestamp in milliseconds. The second number is the voltage
at pin A4 of the Arduino which is varied with the potentiometer. The third number is
the temperature in ˚C. At this point there should only be valid values for the first two
numbers since the temperature sensor is not yet connected.

Fig. 5. Output of the serial monitor

7. Turn the potentiometer through its range and watch the middle number
change. At this point, the fan should increase in speed with the voltage at A4.

8. Turn the potentiometer until the middle number reaches zero. When it does,
the fan should turn off.

If the fan does not turn off and the middle number doesn’t reach zero,
take note of its minimum value. Return to the code and set the variable
potCutoff to something just above your minimum value. Upload the code
again and make sure you can turn the fan off.
Fig. 6. TMP36GT9Z temperature sensor pin-out.

9. Disconnect the Arduino from the computer and connect the TMP36GT9Z
temperature sensor as shown in Fig. 7 noting the pin-out in Fig. 6.

10. Connect the Arduino to the computer. The potentiometer now acts as a
manual override. Turn the potentiometer to the setting that turned the fan off
before.

Fig. 7. Finished circuit.


11. With the potentiometer at its minimum setting, the fan will only turn on if the
temperature is greater than 20˚C. Open the serial monitor. Take note of the third
number. It is the ambient temperature detected by the sensor. Return to the code
and set the variable tempTrigger to some value just above the recorded
temperature. Upload the code and the fan should be off.

12. With the serial monitor open, use your fingers (or some reasonable heat source) to
raise the temperature of the temperature sensor to the trigger value you just set
and the fan should come on.

Bonus

Once you have the functional circuit, restart the Arduino by closing the serial monitor,
unplugging the Arduino from the computer, plugging it in again, and reopening the
serial monitor. Then heat the temperature sensor to a few degrees above your trigger
temperature and then allow it to cool off, once with the fan pointed at it, and once
without. Copy the text from the serial monitor into a plain text editor and save it with
the extension .csv. Then open the file in excel and graph the data. Compare the cool
down rate with and without the fan pointed at the sensor.

Вам также может понравиться