Академический Документы
Профессиональный Документы
Культура Документы
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.
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.
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.
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.