Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- // Initialize the LCD display
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // Define the fan and temperature sensor pin numbers
- const int fanPin = 9;
- const int tempPin = A1;
- void setup() {
- lcd.begin(16, 2); // Initialize the LCD with 16x2 characters
- pinMode(fanPin, OUTPUT);
- pinMode(tempPin, INPUT);
- Serial.begin(9600);
- digitalWrite(fanPin, LOW); // Start with the fan off
- lcd.print("Fan Status: OFF");
- lcd.setCursor(0, 1);
- lcd.print("LOADING ...");
- for (int i = 0; i < 16; i++) {
- delay(1500);
- lcd.scrollDisplayLeft();
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("GROUP 6");
- }
- void loop() {
- lcd.setCursor(0, 0);
- Serial.print("ITS WORKING");
- // Read temperature from the sensor
- int temperature = analogRead(tempPin);
- float voltage = temperature * (5.0 / 1023.0);
- float celsius = (voltage) * 100.0;
- // Adjust the fan speed based on the temperature
- int fanSpeed = 0; // Default fan speed
- if (celsius <= 28.0) {
- fanSpeed = 0; // Fan off
- } else if (celsius <= 30.0) {
- fanSpeed = 64; // 25% fan speed (out of 255)
- } else if (celsius <= 32.0) {
- fanSpeed = 128; // 50% fan speed (out of 255)
- } else if (celsius <= 34.0) {
- fanSpeed = 192; // 75% fan speed (out of 255)
- } else {
- fanSpeed = 255; // 100% fan speed (out of 255)
- }
- analogWrite(fanPin, fanSpeed);
- // Display the temperature at the top row
- lcd.print("Temperature: ");
- lcd.print(celsius);
- lcd.print(" C");
- // Display the fan speed at the bottom row
- lcd.setCursor(0, 1);
- lcd.print("Fan Speed: ");
- lcd.print(map(fanSpeed, 0, 255, 0, 100));
- lcd.print("%");
- delay(500); // Update the status every 1 second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement