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

58,212

130

16

Intro: 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.

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest

    16 Discussions

    0
    None
    Amal Raphael

    Question 4 months ago

    Motor is still on even after the temperature is below than the Minimum Temperature.
    How to fux this?

    0
    None
    MaddieB10

    Question 6 months ago on Step 1

    If you wanted to use a thermocouple like the MAX 6675 instead of the LM35, could you still set the temp min the same way

    1 more answer
    0
    None
    LarryF29MaddieB10

    Answer 6 months ago

    providing that the value of the thermistor is the same , you basically make a voltage divider , example- series a 10k resistor with a 10k thermistor, where the thermistor is junction to the resistor is where you would connect A0

    0
    None
    Baby Boss Craftk

    7 months ago

    What is the pin of the green wire on the arduino.

    0
    None
    Baby Boss Craftk

    7 months ago

    What is the pin of the green wire on the arduino.

    0
    None
    citof1

    7 months ago

    is it available for only 5v supply?

    0
    None
    EmikoG

    1 year ago

    The fan is still running below the temp min, how do i get the temperature sensor to control the fan

    0
    None
    MeghanaM3

    1 year ago

    motor is not controlling its speed ?? how can i control it please give me the solution for that immediately

    0
    None
    rashedkhan

    2 years ago

    my fan is rotating though i have reduced the min temp but motor is not stopping.it is spinning

    0
    None
    MetroidChild.

    2 years ago

    what exactly does the diode that goes across the fan terminals do? Is that a safety measure in case the fan spins backwards by itself to prevent frying the npn transistor or something, or is it just there for show?

    1 reply
    0
    None
    DanielP406MetroidChild.

    Reply 2 years ago

    You might've had this question answered, but for others who are curious - the fan is an inductive load, and the diode therefore serves as a 'flyback diode'.

    Technically, the fan's motor develops a magnetic field in order to spin. When the fan suddenly loses power (when you turn it off at the switch), it tries to 'feed itself' using the motor's collapsing magnetic field as its source, instead of the original source - which is now missing.
    Depending on the magnitude of this field, the inductor creates a negaitve potential where it was once positive, and the inductive load tries to essentially 'force' the voltage across the power switch, creating an arc. This is dangerous for the circuit.

    A diode is therefore placed across the motor such that the intended source won't bypass the fan when operating, and the inductor will 'power itself down' PROPERLY (until it dies) when the fan is turned off.

    Hope this helps :)

    0
    None
    TuryaB

    2 years ago

    can you give the specification of the motor used?