arduino lm35 temperature sensor with 12v fan and leds.

Mr.ElectroUino
0

arduino lm35 temperature sensor with fan and leds

  Tutorial  @Mr ProjectsoPedia

In this blog, you will learn about how to use the lm35 temperature sensor and control 12v fan and LEDs.

LM35 sensor feature:

  • We measure temperature between -55°C to 150°C 
  • The supply voltage ranges from 4 to 30.
  • The Accuracy of the sensor is ±0.5°C 
  • Its low-cost analog output temperature sensor.

Component requirement for temperature sensor:

1. Arduino Uno. 2. LM35. 3. 12v fan. 4. 12v Power supply. 5. TIP41c NPN transistor. 6. LEDs x 5. 7. 220 ohm resistor x 5. 8. 1k ohm resistor. 9. breadboard.
10. Jumper wire.

Measuring the temperature of surroundings using LM35 and displaying it on the serial monitor of Arduino.
CIRCUIT DIAGRAM:
arduino lm35 sensor
  • Connect lm35 VCC pin to arduino 5v pin.
  • Connect lm35 out pin to arduino A1 pin.
  • Connect lm35 GND pin to arduino GND pin. 
CODE:
const int sensor = A0; // Assigning analog pin A5 to variable 'sensor'
float tempC; //variable to store temperature in degree Celsius
float tempF; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading

void setup() {
  pinMode(sensor, INPUT); // Configuring sensor pin as input
  Serial.begin(9600);
}

void loop() {
  vout = analogRead(sensor); //Reading the value from sensor
  tempC = (vout * 500) / 1023; // Storing value in Degree Celsius
  tempF = (vout * 1.8) + 32; // Converting to Fahrenheit

  Serial.print("in DegreeC=");
  Serial.print("\t");
  Serial.print(tempC);
  Serial.print(" ");
  Serial.print("in Fahrenheit=");
  Serial.print("\t");
  Serial.print(tempF);
  Serial.println();
  delay(500); //Delay of 1 second for ease of viewing
}

Control 12v fan and LEDs with lm35 sensor.
Arduino Uno is used to converting lm35 analog values into temperature values. So we can use those values to drives the transistor to control the 12v fan. For example, when the temperature goes above 100°C, Arduino sent the signal to the transistor base pin to switch the GND and turn on the fan, or else the fan will stop. 
LED is used to indicate the temperature like, when white LEDs turn on, which means the temperature is 30°C and the red LEDs turn on, which means the temperature is 100°C.

Circuit diagram:
arduino lm35 temperature sensor
LM35 connection:
  • Connect lm35 VCC pin to arduino 5v pin.
  • Connect lm35 out pin to arduino A1 pin.
  • Connect lm35 GND pin to arduino GND pin. 
12v fan connection:
  • Connect arduino digital 13 pin to 1k resistor and connect the resistor to transistor base pin.
  • Connect arduino ground pin to transistor emitter pin.
  • Connect power supply (12v) positives pin is connected to Fan positive terminal and negative pin is connected to transistor emitter pin.
  • Connect Fan negative terminal to transistor collector pin.
Led connection:

Connect the LEDs on the breadboard and make sure that the cathode pin is connected to the ground.
  • Connect arduino digital pin 6 to led 1 indicate as 100°C.
  • Connect arduino digital pin 5 to led 2 indicate as 90°C.
  • Connect arduino digital pin 4 to led 3 indicate as 70°C. 
  • Connect arduino digital pin 3 to led 4 indicate as 50°C. 
  • Connect arduino digital pin 2 to led 5 indicate as 30°C.
Don't forget to add a current limit resistor to the led Anode pin. Its value is 220 resistor.

 
CODE:

const int sensor = A0; // Assigning analog pin A5 to variable 'sensor'
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading

#define led1 2
#define led2 3
#define led3 4
#define led4 5
#define led5 6

#define fan 7

void setup() {
  pinMode(sensor, INPUT); // Configuring sensor pin as input
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(fan, OUTPUT);
  
  Serial.begin(9600);
}

void loop() {
  vout = analogRead(sensor); //Reading the value from sensor
  vout = (vout * 500) / 1023;
  tempc = vout; // Storing value in Degree Celsius
  tempf = (vout * 1.8) + 32; // Converting to Fahrenheit

  Serial.print("in DegreeC=");
  Serial.print("\t");
  Serial.print(tempc);
  Serial.print(" ");
  Serial.print("in Fahrenheit=");
  Serial.print("\t");
  Serial.print(tempf);
  Serial.println();
  delay(500); //Delay of 1 second for ease of viewing
  if (tempc > 30) {
    digitalWrite(led1, HIGH);
  }
  else {
    digitalWrite(led1, LOW);
  }
  if (tempc > 50) {
    digitalWrite(led2, HIGH);
  }else {
    digitalWrite(led2, LOW);
  }
  if (tempc > 70) {
    digitalWrite(led3, HIGH);
  }else {
    digitalWrite(led3, LOW);
  }
  if (tempc > 90) {
    digitalWrite(led4, HIGH);
  }else {
    digitalWrite(led4, LOW);
  }
  if (tempc > 100) {
    digitalWrite(led5, HIGH);
    digitalWrite(fan, HIGH);
  }else {
    digitalWrite(led5, LOW);
    digitalWrite(fan, LOW);
  }
}

 Watch This Tutorial: 



Post a Comment

0Comments

Post a Comment (0)