0% found this document useful (0 votes)
26 views3 pages

IV. Circuit Diagram

The program code controls a fan based on temperature readings from a temperature pin. It uses PWM to vary the fan speed between off, 30%, 60%, and 100% depending on whether the temperature is below 23°C, between 23-27°C, 28-32°C, or above 33°C respectively. It prints the temperature, PWM value, and fan speed to the serial monitor and waits for a pin to be pressed before restarting the process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

IV. Circuit Diagram

The program code controls a fan based on temperature readings from a temperature pin. It uses PWM to vary the fan speed between off, 30%, 60%, and 100% depending on whether the temperature is below 23°C, between 23-27°C, 28-32°C, or above 33°C respectively. It prints the temperature, PWM value, and fan speed to the serial monitor and waits for a pin to be pressed before restarting the process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

IV.

Circuit Diagram

V. Program Code

int fan=11;
int tpin=5;
int temp,pin=1,x=0,a=0;

void setup() {
Serial.begin(9600);
pinMode (pin,INPUT_PULLUP);
}

void loop() {
while (x==0)
{analogWrite(fan,0);
Serial.println("PINDUTIN MO NA!!!");
delay (1000);
if (digitalRead(pin)==LOW)
{ delay (2000);
x=1;}
}

while ( x==1)
{a=analogRead(tpin);
temp=a*0.48828125;
if (temp>=23 && temp<=27)
{ analogWrite(fan,77);
Serial.print("TEMPERATURE= ");
Serial.print(temp);
Serial.print(" CELSIUS");
Serial.print("\t PWM VALUE=77");
Serial.println("\t FAN SPEED=30%");
delay(1000);
if (digitalRead(pin)==LOW)
{ delay (2000);
x=0;}}

if (temp>=28 && temp<=32)


{ analogWrite(fan,153);
Serial.print("TEMPERATURE= ");
Serial.print(temp);
Serial.print(" CELSIUS");
Serial.print("\t PWM VALUE=153");
Serial.println("\t FAN SPEED=60%");
delay(1000);
if (digitalRead(pin)==LOW)
{ delay (2000);
x=0;}}
if (temp>33)
{ analogWrite(fan,255);
Serial.print("TEMPERATURE= ");
Serial.print(temp);
Serial.print(" CELSIUS");
Serial.print("\t PWM VALUE=255");
Serial.println("\t FAN SPEED=100%");
delay(1000);
if (digitalRead(pin)==LOW)
{ delay (2000);
x=0;}}
if (temp<23)
{ analogWrite(fan,0);
Serial.print("TEMPERATURE= ");
Serial.print(temp);
Serial.print(" CELSIUS");
Serial.print("\t PWM VALUE=0");
Serial.println("\t FAN SPEED=OFF");
delay(1000);
if (digitalRead(pin)==LOW)
{ delay (2000);
x=0;}
}
}
}

You might also like