In: Electrical Engineering
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Arduino code:-
int val;
int tempPin = A0;
const int fanpin = 2;
void setup()
{
Serial.begin(9600);
pinMode(fanpin, OUTPUT);
}
void loop()
{
val = analogRead(tempPin);
//conversions from analog to celsius and farenheit
float a = ( val/1024.0)*5000;
float cel = a/10;
float farh = (cel*9)/5 + 32;
//these lines are used to display the temperature in the serial
monitor.
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
int threshold = 28; // you can change the threshold value
according to your requirement.
if (cel > threshold )
{
digitalWrite(fanpin, HIGH);
}
else
{
digitalWrite(fanpin, LOW);
}
delay(1000);
/* uncomment this to get temperature in farenhite
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
*/