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

84,720

134

18

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

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge
    • For the Home Contest

      For the Home Contest

    18 Comments

    0
    aliashmshl
    aliashmshl

    Question 2 years ago

    I want to ask , why if we are applying heat near the LM35 the motor is rotating ? And why when we are remove the heat source the motor are stop ?
    Anyone?

    0
    ramollaranjith0107
    ramollaranjith0107

    2 years ago

    How the pwm pin control the speed of the fan?
    If we reduce the temperature the speed of the fan is reduced to how much speed?i.e, the values of temp and speed

    0
    Amal Raphael
    Amal Raphael

    Question 4 years ago

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

    0
    MaddieB10
    MaddieB10

    Question 5 years 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

    0
    LarryF29
    LarryF29

    Answer 5 years 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
    Baby Boss Craftk
    Baby Boss Craftk

    5 years ago

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

    0
    Baby Boss Craftk
    Baby Boss Craftk

    5 years ago

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

    0
    citof1
    citof1

    5 years ago

    is it available for only 5v supply?

    0
    EmikoG
    EmikoG

    6 years ago

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

    0
    MeghanaM3
    MeghanaM3

    6 years ago

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

    0
    rashedkhan
    rashedkhan

    6 years ago

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

    0
    MetroidChild.
    MetroidChild.

    7 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?

    0
    DanielP406
    DanielP406

    Reply 6 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
    TuryaB
    TuryaB

    7 years ago

    can you give the specification of the motor used?

    0
    wilsondm
    wilsondm

    7 years ago on Step 2

    BOM DIA,Ótimo Trabalho Pretendo e Fácil. de fazer

    0
    Hesham_Gaber
    Hesham_Gaber

    Reply 7 years ago on Introduction

    thank you,
    it is simply a part of a big project, you might use it in something

    0
    Hesham_Gaber
    Hesham_Gaber

    Reply 7 years ago on Introduction

    it could be involved in a large project like a smert home !