Electronic Project 21: Automatic switching on/off the electric fan when temperature increases using temperature sensor

in #utopian-io8 years ago (edited)

image.png

What Will I Learn?

At the end of this tutorial:

♦ The readers will be able to create an automatic electric fan when temperature increases and switch off when decreases

♦ The readers will be able to know how the circuit works.

♦ Learn to apply the circuit in making electronic projects that needs the function of a temperature sensor .

Introduction

In this tutorial, we are able to create an automatic switching on/off an electric fan using temperature sensor. This sensor can be programmed using arduino uno to be the input component. As the name implies, its main function is to detect the increase or decrease of the surrounding temperature.

You can read more here

Requirements

Electronic Components

♦ Arduino Uno

♦ LM35 temperature sensor

♦ Resistor

♦ Capacitor

♦ Relay

♦ DC motor (as electric fan)

♦ Transistor

♦ LED

♦ Switch

♦ Battery

♦ Fuse

♦ Breadboard

♦ Connecting wires

Software

♦ Fritzing application

Difficulty

♦ Advance

Tutorial Contents

Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard

Part I. Schematic Diagram

So first let us construct our circuit diagram.

image.png

Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 temperature sensor, 4 resistors, 1 led, 1 DC motor, 1 transistor, 1 switch, 1 fuse, 1 battery and 1 capacitor.

image.png

Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
In this tutorial the input components will be the temperature sensor. The rest of the components are for the output side.

image.png

Now let us construct our circuit diagram. So at input side of our microcontroller is the temperature sensor. The sensor has three terminals, Vcc, Vout & ground terminal. The Vcc terminal will be connected to the 5V source output of the arduino, the Vout terminal will be our input signal. I will use pin A2 as our input pin. Then the ground terminal will be directed to the ground.

image.png

At the output side of our circuit is the led diode and the base resistor of the transistor. We will use two output pin, pin 11 & 13, though you can use any of them.

image.png

Then we have an external circuit connection between our electric fan, relay, fuse, switch, battery and a resistor. This separate circuit will be connected in series.

image.png

Now we need the output of our amplifier circuit to trigger the relay of the external circuit. So we connect the collector terminal to the input of the relay.

image.png

So here is our final circuit diagram.

image.png

When the temperature sensor detects that the temperature of the area is greater than the minimum room temperature, it will give an output signal. This output signal is then connected to the input pin 2 of the microcontroller.

image.png

The arduino uno is programmed to give output when the temperature is above the minimum temperature. The output signal will flow through the led diode and the base resistor of the transistor.

image.png

This amplified signal from the collector terminal is being fed to the input of the relay. When relay triggers, it will allow current to flow the circuit due to the source battery.

image.png

Now the current will flow through the external circuit and the fan will start turning on.

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

The input of our microcontroller is the output of our temperature sensor. We declare the input and output pins for our microcontroller. Pin 2 is the input pin and pin 11 & 13 as output pin.

int tempPin = 2;
int ledPin = 13;
int resPin = 11;

image.png

Since our main goal is to start the electric fan when temperature increase, so here we will assign an initial value for minimum and maximum temperature to start and stop the fan.

int temp;
int tempMin = 25; //Turn off the fan
int tempMax = 50; //Turn on the fan at 100 % speed
int fanSpeed;

image.png

For output and input setup.

void setup () {
pinMode(resPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(tempPin, INPUT);
}

image.png

void loop () {
temp = readTemp();      //read the temperature
if (temp < tempMin) {   // if temp is lower than minimum temperature fan is off
    fanSpeed = 0;
    digitalWrite (resPin, LOW);
}

If ((temp >= tempMin) && (temp <= tempMax)) { // if temp is higher than minimum temperature
    fanspeed = map (temp, tempMin, tempMax);
    analogWrite (resPin, fanSpeed); // switch on the fan
}
If (temp > tempMax) {  //if temp is higher than tempMax turn on the led
DigitalWrite(ledPin, HIGH);
} else {                        // else turn off the led
digitalWrite(ledPin, LOW);
}

image.png

int readTemp() { //get the temperature and convert it to degree celsius
temp = analogRead(tempPin);
Return temp *0.4882;
}

image.png

So here is our arduino codes.

int tempPin = 2; 
int ledPin = 13; 
int resPin = 11; 
int temp; 
int tempMin = 25; 
int tempMax = 50; 
int fanSpeed; 
void setup () { 
pinMode(resPin, OUTPUT); 
pinMode(ledPin, OUTPUT); 
pinMode(tempPin, INPUT); 
} 
void loop () { 
temp = readTemp();                
if (temp < tempMin) {   
            fanSpeed = 0; 
            digitalWrite (resPin, LOW); 
}  
If ((temp >= tempMin) && (temp <= tempMax)) { temperature 
            fanspeed = map (temp, tempMin, tempMax); 
            analogWrite (resPin, fanSpeed); 
}   
If (temp > tempMax) {   
DigitalWrite(ledPin, HIGH); 
} else {                        
digitalWrite(ledPin, LOW);   
} 
int readTemp() { 
temp = analogRead(tempPin); 
return temp *0.4882; 
} 

Part III. Breadboard

Click on the breadboard.

image.png

Arrange each component in the breadboard before connecting.

image.png

Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard

image.png

Application

The readers can create their own automatic fan controlled by the thermometer sensor and arduino uno.
Like the example below.

link source

Curriculum

Here are my other tutorials for electronic projects.

ELECTRONIC PROJECTS

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @rfece143 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

greetings excellent information are very good tutorials that you present in your account!

Coin Marketplace

STEEM 0.13
TRX 0.34
JST 0.034
BTC 114291.84
ETH 4421.20
SBD 0.87