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 the 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