Hi, i'm new to this arduino and really hope there is someone able to help, i'm wanted to create a fan control for an enclosure, if the temperature reach 55 degree celsius the fan will turn on 255, when it lower then 55 degree celsius it would turn off.
the code i'm making is like this, hope someone can correct me if i'm wrong:
#include <dht.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht DHT;
#define DHT11_PIN 7
float temp;
int tempPin = 7; //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.0100.0)/1024.0;
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 minimmum range
{
fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
}
