Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
41 views

Now Code

This code controls a fan and LCD display based on temperature readings from a sensor. It initializes an LCD display and temperature sensor pin, then enters a loop to continuously read the temperature, adjust the fan speed if needed, and display the temperature and fan speed on the LCD. If the temperature is below a minimum, the fan is turned off. If it is within a range, the fan speed is mapped proportionally between a minimum and maximum based on the temperature.

Uploaded by

david ukilo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Now Code

This code controls a fan and LCD display based on temperature readings from a sensor. It initializes an LCD display and temperature sensor pin, then enters a loop to continuously read the temperature, adjust the fan speed if needed, and display the temperature and fan speed on the LCD. If the temperature is below a minimum, the fan is turned off. If it is within a range, the fan speed is mapped proportionally between a minimum and maximum based on the temperature.

Uploaded by

david ukilo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include

LiquidCrystal lcd(7,6,5,4,3,2);
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;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,4);
}
void loop() {
temp = analogRead(tempPin);
temp = (temp *5.0*100.0)/1024.0; //calculate the temperature in Celsius
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
}
lcd.print("TEMP: ");
lcd.print(temp);

// display the temperature

lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FANS: ");
lcd.print(fanLCD);

// display the fan speed

lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius

temp = analogRead(tempPin);
return temp * 0.48828125;
}

You might also like