-
Notifications
You must be signed in to change notification settings - Fork 0
/
OhmOS.ino
129 lines (114 loc) · 2.83 KB
/
OhmOS.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
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "ACS712.h"
#include <math.h>
#include <MemoryFree.h>
float c;
int fanPin = 4;
int alarmPin = 3;
LiquidCrystal_I2C lcd(0x27,20,4);
ACS712 sensor(ACS712_20A, A0);
unsigned long time;
long interval = 500;
int alarmState = LOW;
long previousMillis = 0;
char vNum[] = "170817v3.1";
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
return Temp;
}
void setup() {
Serial.begin(9600);
pinMode(fanPin, OUTPUT);
pinMode(alarmPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(String("OhmOS") + " " + (char)244);
lcd.setCursor(0,2);
lcd.print(vNum);
lcd.setCursor(0,3);
lcd.print(String("RAM free:") + freeMemory() + " " + "bytes");
delay(2000);
lcd.clear();
lcd.print("Calibrating... ");
int zero = sensor.calibrate();
delay(1000);
lcd.setCursor(0,1);
lcd.print("Done!");
digitalWrite(alarmPin, HIGH);
delay(100);
digitalWrite(alarmPin, LOW);
delay(100);
digitalWrite(alarmPin, HIGH);
delay(100);
digitalWrite(alarmPin, LOW);
delay(400);
lcd.clear();
}
void loop() {
int voltageSensor = analogRead(A1);
float I = sensor.getCurrentDC();
c = -1 * I;
float voltage = ((voltageSensor * 28.3) / 1023.0) + 0.2;
float power = voltage * c;
float R = voltage / c;
lcd.setCursor(0,0);
lcd.print(String("I : ") + c);
lcd.setCursor(10,0);
lcd.print("A");
lcd.setCursor(0,1);
lcd.print(String("V :") + voltage);
lcd.setCursor(10,1);
lcd.print("V");
lcd.setCursor(0,2);
lcd.print(String("P :") + power);
lcd.setCursor(10,2);
lcd.print("W");
lcd.setCursor(12,0);
lcd.print("STS:");
lcd.setCursor(12,1);
lcd.print("CC-INOP");
if (int(Thermistor(analogRead(2))) > 40 )
{
lcd.setCursor(0,3);
digitalWrite(fanPin, HIGH);
lcd.print(String("T :") + int(Thermistor(analogRead(2))) + char(223)+ "C");
delay(300);
lcd.setCursor(16,0);
lcd.print(" ");
lcd.setCursor(16,0);
lcd.print("TEMP");
alarmSequence();
}
else
{
lcd.setCursor(0,3);
digitalWrite(fanPin, LOW);
digitalWrite(alarmPin, LOW);
lcd.print(String("T :") + int(Thermistor(analogRead(2))) + char(223)+ "C");
lcd.setCursor(16,0);
lcd.print(" ");
lcd.setCursor(16,0);
lcd.print("OK");
delay(300);
}
}
void alarmSequence()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (alarmState == LOW)
alarmState = HIGH;
else
alarmState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(alarmPin, alarmState);
}
}