-
Notifications
You must be signed in to change notification settings - Fork 0
/
humidity_sensor_3.0.ino
141 lines (95 loc) · 3.08 KB
/
humidity_sensor_3.0.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
137
138
139
140
141
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define pinSensor 2
DHT dht(pinSensor,DHT11);
//SAMPLING TIME
int time_sam=8000;
//ISTOGRAM ROW
int row;
//SECOND-LAST PIXEL POSITION
int y_p_pre;
//MAXIMUM DATA E MINIMUM DATA
int max_hum=0;
int min_hum=99;
//LAST PIXEL POSITION
int x_p=3;
int y_p;
void setup() {
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { //DISPLAY INITIALIZATION
while(true);
}
display.clearDisplay();
dht.begin(); //SENSOR INITIALIZATION
}
void loop() {
int humidity_percentage = dht.readHumidity(); //SAMPLING
if(humidity_percentage>max_hum){
max_hum=humidity_percentage;
}
if(humidity_percentage<min_hum){
min_hum=humidity_percentage;
}
if (x_p==127){ //OVERFLOW DISPLAY
display.clearDisplay();
x_p=3;
}
row = map(humidity_percentage, 0, 100,0,127);
y_p = map(humidity_percentage, 0, 100,63,17);
axis();
//ISTOGRAM
display.drawRect(0,0,127,16,SSD1306_WHITE);
display.fillRect(0,0,row,16,SSD1306_WHITE);
//CURRENT HUMIDITY TEXT
display.setTextSize(2);
display.setTextColor(SSD1306_BLACK);
display.setCursor(1,1);
display.println(("H:"));
display.fillRect(80,0,24,16,SSD1306_WHITE);
display.setCursor(21,1);
display.println((humidity_percentage));
display.setCursor(45,1);
display.println(("%"));
//MAX HUMIDITY TEXT
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(4,53);
display.println(("MAX:"));
display.fillRect(28,53,11,8,SSD1306_BLACK);
display.setCursor(28,53);
display.println((max_hum));
display.setCursor(40,53);
display.println(("%"));
//MIN HUMIDITY TEXT
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(60,53);
display.println(("min:"));
display.fillRect(84,53,11,8,SSD1306_BLACK);
display.setCursor(84,53);
display.println((min_hum));
display.setCursor(96,53);
display.println(("%"));
//GRAPH
display.drawLine(x_p, y_p_pre,x_p, y_p,SSD1306_WHITE);
x_p++;
y_p_pre=y_p;
display.display();
delay(time_sam);
}
void axis(){
display.drawLine(2,61,127,61, SSD1306_WHITE); //X AXIS
display.drawLine(125,63,127,61, SSD1306_WHITE);
display.drawLine(125,59,127,61, SSD1306_WHITE);
display.drawLine(2,61,2,17, SSD1306_WHITE); //Y AXIS
display.drawLine(0,19,2,17, SSD1306_WHITE);
display.drawLine(4,19,2,17, SSD1306_WHITE);
display.display();
}