Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions Relay/Relay.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
int fan = 7; // Pin 7 controls the fan ON and OFF
int state = 0; // state at which the fan is
float tmp = 0; // temperature reading from the temp sensor
void setup()
{
pinMode(fan,OUTPUT); // configuring the fan pin as an output to control the fan
Serial.begin(9600);
}

void loop()
{
int reading = analogRead(A0); // reading the temp sensor value
float voltage = reading*5; // voltage multiplied by its ref value
voltage /= 1024; // divided by 1024(max value of analog range)
tmp = (voltage-0.5)*100; // converting to deg C
Serial.print("Temperature(deg C) is : ");
Serial.println(tmp);// printing temp
delay (500);

/************************logic starts********************/
if(tmp>29)
{
state= 1;
}
else
{
state = 0;
}
/**********************logic ends***********************/
digitalWrite(fan,state); // turning the fan off or on
if (state != 1)
{
Serial.println("Fan OFF"); // printing fan's state
}
else
{
Serial.println("Fan ON"); // printing fan's state
}


}