Step 1 Connect the ServoMotor To the Arduino Mega 2560
- Connect the Vcc of the servo Motor to the 5v of the Arduino Mega 2560.
- Connect the gnd of the bluetooth to the Gnd of the Arduino Mega 2560.
- Connect the Vin of the bluetooth to the 09 of the Arduino Mega 2560.
Step 2 Connect the Temperature Sensor To The Arduino mega 2560
- The first pin can be connected to the Vcc of the 5V to an Arduino board.
- The second pin can be connected to the A1 of analog side to an Arduino board.
- The third pin can be connected to the Gnd to an Arduino board.
Programming
- float temp;
-
- int tempPin = A1;
-
- int tempMin = 25;
-
- int tempMax = 70;
-
- int fan = 9;
-
- int fanSpeed = 0;
-
- void setup()
- {
-
- pinMode(fan, OUTPUT);
-
- pinMode(tempPin, INPUT);
-
- Serial.begin(9600);
-
- }
-
- void loop()
- {
-
- temp = analogRead(tempPin);
-
- temp = (temp * 5.0 * 100.0) / 1024.0;
-
- Serial.println(temp);
-
- delay(1000);
-
- if (temp < tempMin)
- {
-
-
- fanSpeed = 0;
-
- digitalWrite(fan, LOW);
-
- }
-
- if ((temp >= tempMin) && (temp <= tempMax))
-
- {
-
- fanSpeed = map(temp, tempMin, tempMax, 32, 255);
-
- analogWrite(fan, fanSpeed);
-
- }
-
- }
Explanation
- In this article I explained about the temperature based fan control
- When the fan is ON/OFF it has be based on the temperature I have fixed.
- When the temperature is low it can be started.
- When the temperature is high it can be stopped.