In the age where technology is advancing at an exponential rate, the use of arduino has become an essential part of our daily life. Arduino is a microcontroller board which is used for controlling various electronic devices. Arduino boards can be used for a wide range of applications such as controlling motors, lights, and other devices. One such application is temperature control. Nowadays, temperature controlled fans are becoming increasingly popular due to their versatility and ease of use.
A temperature controlled fan is a device that automatically adjusts the speed of a fan based on the temperature of the room. This is done by using a temperature sensor and an Arduino board. The Arduino board is programmed to read the temperature of the room and adjust the fan speed accordingly. The fan speed is usually adjusted by changing the voltage supplied to the fan motor.
The Arduino Uno board is an excellent device for controlling temperature controlled fans. It is a very versatile board which can be programmed using the Arduino programming language. The Arduino Uno board can be easily connected to a variety of sensors, allowing it to read the temperature of the room and adjust the fan speed accordingly. In this article, we will discuss the Arduino Uno code for temperature controlled fan.
Hardware Setup
The hardware setup for the Arduino Uno code for temperature controlled fan is fairly simple. The components required are an Arduino Uno board, a temperature sensor, and a DC motor. The Arduino board should be connected to the temperature sensor and the motor. The temperature sensor should be connected to analog pin A0 of the Arduino board. The DC motor should be connected to digital pin D9 of the Arduino board.
Arduino Code
The Arduino code for the temperature controlled fan is given below. This code is written in the Arduino programming language and should be uploaded to the Arduino board. The code will read the temperature from the sensor and adjust the fan speed accordingly.
void setup() {
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = (sensorValue*5.0) / 1023.0;
float temperature = (voltage – 0.5) * 100.0;
Serial.println(temperature);
int fanSpeed = map(temperature, 0, 100, 0, 255);
analogWrite(9, fanSpeed);
delay(1000);
}
Explanation of the Code
The code above is written in the Arduino programming language. The main purpose of the code is to read the temperature from the sensor and adjust the fan speed accordingly. The code starts off by setting up the pin modes of the Arduino board. This is done by using the pinMode() function. The analog pin A0 is set up as an input pin while the digital pin D9 is set up as an output pin.
The code then reads the temperature from the sensor and converts it to a voltage. This is done by using the analogRead() and map() functions. The code then converts the voltage to a temperature using the formula (voltage – 0.5) * 100.0. The temperature is then printed out to the serial monitor using the Serial.println() function.
Finally, the code adjusts the fan speed according to the temperature. This is done by using the map() function. The map() function takes the temperature as an input and maps it to a range of 0 to 255. This value is then written to the digital pin D9 using the analogWrite() function. The fan speed is then adjusted accordingly.
Conclusion
In this article, we discussed the Arduino Uno code for temperature controlled fan. We discussed the hardware setup and the code required to control the fan speed. We also discussed the explanation of the code and how it works. This code can be used to control the fan speed based on the temperature of the room. With this code, you can easily control the fan speed and make your environment more comfortable.