Introduction: Using a Temperature Sensor to Control the Speed of a Motor Using Arduino

This application is simple just by using temperature sensor LM35 with an arduino kit to control a fan and change its speed with respect to the temperature read by the micro-controller which in this case is the arduino kit .

The temperature sensor LM35 is connected with the arduino with an analog input pin A0 (the temperature is an analog signal), while the fan is connected with a PWM (Pulse Width Modulation) pin 6 which controls the speed of the fan with respect to the output temperature using a function map in the arduino IDE.

The Components needed :

1. Arduino
2. Temperature Sensor LM35
3. 1K Resistor
4. Diode 1N4007
5. Dc Motor or a simple DC fan
6. NPN transistor BC547
7. A voltage source with 12Volts
8. hook up wires
9. optional : voltage source socket

Step 1: Conecting All Together

Schematic

•using the NPN transistor BC547 here as a buffer to isolate the first circuit which is the connection to the arduino and the other one with the fan.

•using an inverted PN-junction parallel to the fan to prevent moving current in the opposite direction and make damage to the arduino kit.

•using a PWM pin is to modulate the signal given to the fan with respect to the read temperature and by using the map function to control the fan speed.

•it is important to put in consideration that the input voltage for the temp sensor is 5v from the arduino itself, and the 12volt voltage given to the motor or fan must be from an external voltage source, in this case we collect all the GND together weather the GND of the arduino and the external voltage source.

Step 2: Time for Coding

Using the arduino software and write this code down .

float temp;

int tempPin = A0; //arduino pin used for temperature sensor

int tempMin = 25; // the temperature to start the buzzer

int tempMax = 70;

int fan = 6; // the pin where fan is connected

int fanSpeed = 0;

void setup() {

pinMode(fan, OUTPUT);

pinMode(tempPin, INPUT);

Serial.begin(9600);

}

void loop() {

temp = analogRead(tempPin);

temp = (temp *5.0*100.0)/1024.0; //calculate the temperature in Celsius

Serial.println(temp);

delay(1000); // delay in between reads for stability

if(temp < tempMin) { // if temp is lower than minimum temp

fanSpeed = 0; // fan is not spinning

digitalWrite(fan, LOW);

}

if((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimum range

{

fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan

analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed

}

}

Now after verifying and uploading the code to the arduino, you can open the serial monitor up at the right of the arduino software to show the temperature of the surrounding.
you will noticed that i have added the " Serial.begin(9600); " function that shows the temperature in the serial monitor.
To increase the temperature you can heat it by transferring heat from your body by touching it .
you can edit the tempMin and tempMax the values you want depending on your application specification.

Attachments