-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path411_AutoFan.ino
136 lines (92 loc) · 3.03 KB
/
411_AutoFan.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <Wire.h>
#include "SSD1306.h"
#include "SSD1306Wire.h"
#include <math.h>
SSD1306 display(0x3c, 14, 15); //OLED display setup
const int analogPin = A0; //TMP36 Data Pin
const int Relay = 21; //Relay Pin
//Temperature Values
int RawValue= 0;
float voltage = 0;
float tempC = 0;
float tempF = 0;
const int buttonPin = A5; // choose the input pin (for a pushbutton)
int buttonState = 0; // variable for reading the pin status
boolean lastButton = LOW; //Push button
boolean relayOn = false; // Push button trick
void setup(){
//OLED Setup
display.setFont(ArialMT_Plain_24);
Serial.begin(115200);
display.init();
pinMode (13, OUTPUT); //Yellow LED
pinMode (12, OUTPUT); //Green LED
pinMode (27, OUTPUT); //Red LED
pinMode(Relay, OUTPUT); //Relay
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
display.clear();
RawValue = analogRead(analogPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
voltage = RawValue/1024.0;
// now print out the temperature
tempC = (voltage - 0.5)* 100; //converting from 10 mv per degree wit 500 mV offset
// now convert to Fahrenheit
tempF = (tempC * 9.0 / 5.0) + 32.0;
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t milli volts = "); // shows the voltage measured
Serial.print(voltage,0); //
//Serial.print("\t Temperature in C = ");
//Serial.print(tempC,1);
Serial.print("\t Temperature in F = ");
Serial.println(tempF,1);
//OLED Message on Screen
String message = "";
message += tempF;
String message1 = message + "°F";
display.drawString(0, 0, message1);
display.display();
delay(1000);
if (tempF < 70) //when temp is below 35 degrees
{
digitalWrite(13, LOW); //yellow led is off
digitalWrite(12, HIGH); //green led is on
digitalWrite(27, LOW); //red led is off
digitalWrite(Relay, LOW);
Serial.print("Low");
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH && lastButton == LOW) {
// turn relay/fan on:
relayOn = !relayOn;
lastButton = HIGH;
//digitalWrite(Relay, HIGH);
Serial.print("High");
} else {
// turn relay/fan off:
lastButton = buttonState;
//if (buttonState == LOW){
digitalWrite(Relay, relayOn);
Serial.print("Low");
}
}
else if (tempF > 75) //when temp is above 40 degrees
{
digitalWrite(13, LOW); //yellow led is off
digitalWrite(12, LOW); //green led is on
digitalWrite(27, HIGH); //red led is off
digitalWrite(Relay, HIGH);
Serial.print("High");
}
else //when between 70-75 degrees
{
digitalWrite(13, HIGH); //yellow led is on
digitalWrite(12, LOW); //green led is off
digitalWrite(27, LOW); //red led is off
}
}