Components and supplies
LCD Shield Kit w/ 16x2 Character Display - Only 2 pins used!
DHT11 Temperature & Humidity Sensor (4 pins)
Arduino UNO
Adafruit Data Logger Shield
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
DataLog_V55.ino
arduino
This is the final code. Uses Temperature and humidity sensor DHT11.
1/* Arduino Data Logger Version 2015 by Luis Sousa */ 2 3#include <SPI.h> 4#include <SD.h> 5#include <Wire.h> 6#include <RTClib.h> 7#include <dht11.h> 8#include <Adafruit_MCP23017.h> 9#include <Adafruit_RGBLCDShield.h> 10 11#define ECHO_TO_SERIAL 1 // dados no porto serie? 12#define DHT11PIN 2 //pino digital onde liga sensor de temp e humid 13#define redLEDpin 4 //pino digital onde liga LED vermelho 14#define greenLEDpin 3 //pino digital onde liga LED verde 15#define chipSelect 10 //pino digital onde liga CS do SD Card 16#define luzP 3 // pino analogico onde liga LDR 17#define pausa 5000 //5s 18#define ficheiro "dados.txt" //nome do ficheiro de dados 19#define cabecalho "millis,Data,Hora,Vin,Luz,Temperatura,Humidade,DewPoint" //cabecalho da informaao a gravar 20#define RED 0x1 21#define YELLOW 0x3 22#define GREEN 0x2 23#define TEAL 0x6 24#define BLUE 0x4 25#define VIOLET 0x5 26#define WHITE 0x7 27 28dht11 DHT11; // sensor de temp e humidade 29RTC_DS1307 RTC; // Real Time Clock 30Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); 31 32// Inicializao de variaveis 33float Vin = 0; 34byte LCDColor = 1; 35//char ficheiro[] = "dados.txt"; 36int year = 0; 37int month = 0; 38int day = 0; 39int hour = 0; 40int minute = 0; 41byte buttons = 0; 42DateTime now; 43 44//Funoes 45void erro(char *str) 46{ 47 //Sinaliza erro no lcd 48 lcd.clear(); 49 lcd.setBacklight(RED); 50 lcd.setCursor(0, 0); 51 //lcd.print("Erro "); 52 lcd.setCursor(0, 1); 53 lcd.print(str); 54 55 //Sinaliza erro no porto serie 56 Serial.print("Erro: "); 57 Serial.println(str); 58 // red LED = erro 59 digitalWrite(redLEDpin, HIGH); 60 while (1); // HALT 61} 62int RtcAdj(char *str, int valor) 63{ 64 byte sair = 0; 65 byte debounce = 80; 66 lcd.clear(); 67 lcd.setCursor(0, 0); 68 lcd.print("Acertar Relogio "); 69 70 while (!sair) 71 { 72 lcd.setCursor(0, 1); 73 lcd.print (str); 74 lcd.print(valor); 75 buttons = lcd.readButtons(); 76 if (buttons) 77 { 78 if (buttons & BUTTON_UP) 79 { 80 valor ++; 81 delay(debounce); 82 } 83 if (buttons & BUTTON_DOWN) 84 { 85 valor --; 86 delay(debounce); 87 } 88 if (buttons & BUTTON_LEFT) 89 { 90 valor --; 91 delay(debounce); 92 } 93 if (buttons & BUTTON_RIGHT) 94 { 95 valor ++; 96 delay(debounce); 97 } 98 if (buttons & BUTTON_SELECT) 99 { 100 sair = 1; 101 } 102 } 103 } 104 return (valor); 105} 106/* 107//Celsius para Fahrenheit 108double Fahrenheit(double celsius) 109{ 110 return 1.8 * celsius + 32; 111} 112 113//Celsius para Kelvin 114double Kelvin(double celsius) 115{ 116 return celsius + 273.15; 117} 118*/ 119// dewPoint function NOAA 120// reference: http://wahiduddin.net/calc/density_algorithms.htm 121double dewPoint(double celsius, double humidity) 122{ 123 double A0 = 373.15 / (273.15 + celsius); 124 double SUM = -7.90298 * (A0 - 1); 125 SUM += 5.02808 * log10(A0); 126 SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / A0))) - 1) ; 127 SUM += 8.1328e-3 * (pow(10, (-3.49149 * (A0 - 1))) - 1) ; 128 SUM += log10(1013.246); 129 double VP = pow(10, SUM - 3) * humidity; 130 double T = log(VP / 0.61078); // temp var 131 return (241.88 * T) / (17.558 - T); 132} 133/* 134// delta max = 0.6544 wrt dewPoint() 135// 5x faster than dewPoint() 136// reference: http://en.wikipedia.org/wiki/Dew_point 137double dewPointFast(double celsius, double humidity) 138{ 139 double a = 17.271; 140 double b = 237.7; 141 double temp = (a * celsius) / (b + celsius) + log(humidity / 100); 142 double Td = (b * temp) / (a - temp); 143 return Td; 144} 145*/ 146void setup() 147{ 148 pinMode(10, OUTPUT); // SD ChipSelect 149 pinMode(13, OUTPUT); // LED de monitorizaao 150 pinMode(redLEDpin, OUTPUT); 151 pinMode(greenLEDpin, OUTPUT); 152 153 // Inicializaao do porto serie: 154 Serial.begin(9600); 155 156 //Inicializaao do I2C 157 Wire.begin(); 158 159 //Inicializao do LCD 160 lcd.begin(16, 2); 161 lcd.setBacklight(TEAL); 162 lcd.clear(); 163 lcd.setCursor(0, 0); 164 lcd.print("Data Logger V5.5"); 165 lcd.setCursor(0, 1); 166 lcd.print("Luis Sousa-2015"); 167 delay(900); 168 lcd.clear(); 169 170 //Inicializaao do sensor de temperatura 171 Serial.print("DHT11 LIBRARY VERSION: "); 172 Serial.println(DHT11LIB_VERSION); 173 Serial.println(); 174 int chk = DHT11.read(DHT11PIN); 175 Serial.print("Sensor de Temperatura: "); 176 switch (chk) 177 { 178 case 0: Serial.println("OK"); break; 179 case -1: erro("DHT11 Checksum"); break; 180 case -2: erro("DHT11 Time out"); break; 181 default: erro("DHT11 Error"); break; 182 } 183 Serial.println(); 184 185 //Inicializao do SD Card 186 if (!SD.begin(chipSelect)) // Verifica Presena do SD Card: 187 { 188 erro("Introduza SD"); 189 /* 190 Serial.println("Introduza Cartao SD"); 191 lcd.clear(); 192 lcd.setCursor(0, 0); 193 lcd.print("Introduza "); 194 lcd.setCursor(0, 1); 195 lcd.print("Cartao SD"); 196 // Sai por falta de Cartao 197 return; 198 */ 199 } 200 else Serial.println("Cartao SD OK."); 201 202 // cria novo ficheiro 203 //char filename[] = "LOGDAT00.CSV"; 204 //for (uint8_t i = 0; i < 100; i++) 205 //{ 206 // filename[6] = i / 10 + '0'; 207 // filename[7] = i % 10 + '0'; 208 // if (! SD.exists(filename)) 209 // { 210 // // se nao existir, cria novo 211 File logfile = SD.open(ficheiro, FILE_WRITE); 212 // break; // sai do loop! 213 // } 214 //} 215 if (! logfile) 216 { 217 erro("Erro no ficheiro"); 218 } 219 else 220 { 221 Serial.print("Gravando em: "); 222 Serial.println(ficheiro); 223 logfile.println(cabecalho); 224 logfile.close(); 225 } 226#if ECHO_TO_SERIAL 227 Serial.println(cabecalho); 228#endif //ECHO_TO_SERIAL 229 230 //Inicializao do RTC 231 if (!RTC.begin()) 232 { 233 // logfile.println("RTC com avaria"); 234 // Serial.println("RTC com avaria"); 235 erro("RTC com avaria"); 236 } 237 if (! RTC.isrunning()) 238 { 239 Serial.println("RTC parado"); 240 // linha seguinte acerta RTC para data/hora da compilaao 241 RTC.adjust(DateTime(F(__DATE__), F(__TIME__))); 242 Serial.println("RTC ajustado"); 243 // para ajustar para uma determinada data/hora por ex: 244 // 21 de Janeiro de 2014 as 03h escreveria: 245 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 246 } 247} 248 249void loop() 250{ 251 digitalWrite(greenLEDpin, HIGH); // Inicia Escrita 252 253 Vin = (55.00 * analogRead(0) / 1024); 254 int chk = DHT11.read(DHT11PIN); 255 float humid = DHT11.humidity; 256 float tempC = DHT11.temperature; 257 tempC = tempC - 2; // Correco apos calibrao 258 //float tempK = Kelvin(tempC); 259 //float tempF = Fahrenheit(tempC); 260 float dewP = dewPoint(tempC, humid); 261 int luzV = analogRead(luzP); 262 /* 263 if (Vin < 7.50) lcd.setBacklight(0); //modo poupana de energia 264 else lcd.setBacklight(TEAL); 265 */ 266 DateTime now; 267 now = RTC.now(); 268 uint32_t m = millis(); 269 270 //display data 271 lcd.setCursor(0, 0); 272 lcd.print(now.day(), DEC); 273 lcd.print("/"); 274 lcd.print(now.month(), DEC); 275 lcd.print("/"); 276 lcd.print(now.year(), DEC); 277 lcd.print(" "); 278 lcd.print(now.hour(), DEC); 279 lcd.print(":"); 280 lcd.print(now.minute(), DEC); 281 lcd.print(" "); 282 lcd.setCursor(0, 1); 283 lcd.print("T:"); 284 lcd.print(tempC, 0); 285 lcd.print("C H:"); 286 lcd.print(humid, 0); 287 lcd.print("% "); 288 lcd.print("D:"); 289 lcd.print(dewP, 0); 290 lcd.print(" "); 291 292 // log data 293 File logfile = SD.open(ficheiro, FILE_WRITE); 294 if (logfile) 295 { 296 logfile.print(m); // millisegundos desde o inicio 297 logfile.print(","); 298 logfile.print(now.day(), DEC); 299 logfile.print("/"); 300 logfile.print(now.month(), DEC); 301 logfile.print("/"); 302 logfile.print(now.year(), DEC); 303 logfile.print(","); 304 logfile.print(now.hour(), DEC); 305 logfile.print(":"); 306 logfile.print(now.minute(), DEC); 307 logfile.print(":"); 308 logfile.print(now.second(), DEC); 309 logfile.print(","); 310 logfile.print(Vin, 2); 311 logfile.print(","); 312 logfile.print(luzV); 313 logfile.print(","); 314 logfile.print(tempC, 0); 315 logfile.print(","); 316 logfile.print(humid, 0); 317 logfile.print(","); 318 logfile.println(dewP, 0); 319 logfile.close(); 320 } 321 else 322 { 323 erro("Erro no ficheiro"); 324 } 325#if ECHO_TO_SERIAL 326 Serial.print(m); // millisegundos desde o inicio 327 Serial.print(","); 328 Serial.print(now.day(), DEC); 329 Serial.print("/"); 330 Serial.print(now.month(), DEC); 331 Serial.print("/"); 332 Serial.print(now.year(), DEC); 333 Serial.print(","); 334 Serial.print(now.hour(), DEC); 335 Serial.print(":"); 336 Serial.print(now.minute(), DEC); 337 Serial.print(":"); 338 Serial.print(now.second(), DEC); 339 Serial.print(","); 340 Serial.print(Vin, 2); 341 Serial.print(","); 342 Serial.print(luzV); 343 Serial.print(","); 344 Serial.print(tempC, 0); 345 Serial.print(","); 346 Serial.print(humid, 0); 347 Serial.print(","); 348 Serial.println(dewP, 0); 349#endif //ECHO_TO_SERIAL 350 351 digitalWrite(greenLEDpin, LOW); // acabou escrita 352 353 //Teste aos butoes do LCD 354 for (byte i = 0; i < 20; i++) 355 { 356 delay(pausa / 20); 357 buttons = lcd.readButtons(); 358 if (buttons) 359 { 360 if (buttons & BUTTON_UP) 361 { 362 lcd.setCursor(0, 1); 363 lcd.print("Vin: "); 364 lcd.print(Vin, 2); 365 lcd.print("V "); 366 } 367 if (buttons & BUTTON_DOWN) 368 { 369 lcd.setCursor(0, 1); 370 lcd.print("Luz: "); 371 lcd.print(luzV); 372 lcd.print(" "); 373 delay(500); //debounce 374 buttons = lcd.readButtons(); 375 if (buttons & BUTTON_DOWN) 376 { 377 now = RTC.now(); 378 year = now.year(); 379 month = now.month(); 380 day = now.day(); 381 hour = now.hour(); 382 minute = now.minute(); 383 year = RtcAdj("Ano: ", year); 384 month = RtcAdj("Mes: ", month); 385 day = RtcAdj("Dia: ", day); 386 hour = RtcAdj("Hora: ", hour); 387 minute = RtcAdj("Minutos: ", minute); 388 RTC.adjust(DateTime(year, month, day, hour, minute, 0)); 389 lcd.setCursor(0, 1); 390 char msg[] = "RTC Ajustado "; 391 lcd.print(msg); 392 logfile.println(msg); 393 Serial.println(msg); 394 } 395 } 396 if (buttons & BUTTON_LEFT) 397 { 398 LCDColor = LCDColor - 1; 399 if (LCDColor < 1) LCDColor = 1; 400 lcd.setBacklight(LCDColor); 401 } 402 if (buttons & BUTTON_RIGHT) 403 { 404 LCDColor = LCDColor + 1; 405 if (LCDColor > 7) LCDColor = 7; 406 lcd.setBacklight(LCDColor); 407 } 408 if (buttons & BUTTON_SELECT) 409 { 410 if (LCDColor > 0)LCDColor = 0; 411 else LCDColor = (TEAL); 412 lcd.setBacklight(LCDColor); 413 } 414 } 415 } 416} 417 418
DataLog_V55.ino
arduino
This is the final code. Uses Temperature and humidity sensor DHT11.
1/* Arduino Data Logger Version 2015 by Luis Sousa */ 2 3#include <SPI.h> 4#include 5 <SD.h> 6#include <Wire.h> 7#include <RTClib.h> 8#include <dht11.h> 9#include 10 <Adafruit_MCP23017.h> 11#include <Adafruit_RGBLCDShield.h> 12 13#define ECHO_TO_SERIAL 14 1 // dados no porto serie? 15#define DHT11PIN 2 //pino digital onde liga sensor 16 de temp e humid 17#define redLEDpin 4 //pino digital onde liga LED vermelho 18#define 19 greenLEDpin 3 //pino digital onde liga LED verde 20#define chipSelect 10 //pino 21 digital onde liga CS do SD Card 22#define luzP 3 // pino analogico onde liga LDR 23#define 24 pausa 5000 //5s 25#define ficheiro "dados.txt" //nome do ficheiro de dados 26#define 27 cabecalho "millis,Data,Hora,Vin,Luz,Temperatura,Humidade,DewPoint" //cabecalho 28 da informaao a gravar 29#define RED 0x1 30#define YELLOW 0x3 31#define GREEN 32 0x2 33#define TEAL 0x6 34#define BLUE 0x4 35#define VIOLET 0x5 36#define WHITE 37 0x7 38 39dht11 DHT11; // sensor de temp e humidade 40RTC_DS1307 RTC; // Real 41 Time Clock 42Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); 43 44// Inicializao 45 de variaveis 46float Vin = 0; 47byte LCDColor = 1; 48//char ficheiro[] = "dados.txt"; 49int 50 year = 0; 51int month = 0; 52int day = 0; 53int hour = 0; 54int minute = 0; 55byte 56 buttons = 0; 57DateTime now; 58 59//Funoes 60void erro(char *str) 61{ 62 //Sinaliza 63 erro no lcd 64 lcd.clear(); 65 lcd.setBacklight(RED); 66 lcd.setCursor(0, 67 0); 68 //lcd.print("Erro "); 69 lcd.setCursor(0, 1); 70 lcd.print(str); 71 72 73 //Sinaliza erro no porto serie 74 Serial.print("Erro: "); 75 Serial.println(str); 76 77 // red LED = erro 78 digitalWrite(redLEDpin, HIGH); 79 while (1); // HALT 80} 81int 82 RtcAdj(char *str, int valor) 83{ 84 byte sair = 0; 85 byte debounce = 80; 86 87 lcd.clear(); 88 lcd.setCursor(0, 0); 89 lcd.print("Acertar Relogio "); 90 91 92 while (!sair) 93 { 94 lcd.setCursor(0, 1); 95 lcd.print (str); 96 lcd.print(valor); 97 98 buttons = lcd.readButtons(); 99 if (buttons) 100 { 101 if (buttons 102 & BUTTON_UP) 103 { 104 valor ++; 105 delay(debounce); 106 } 107 108 if (buttons & BUTTON_DOWN) 109 { 110 valor --; 111 delay(debounce); 112 113 } 114 if (buttons & BUTTON_LEFT) 115 { 116 valor --; 117 118 delay(debounce); 119 } 120 if (buttons & BUTTON_RIGHT) 121 { 122 123 valor ++; 124 delay(debounce); 125 } 126 if (buttons & 127 BUTTON_SELECT) 128 { 129 sair = 1; 130 } 131 } 132 } 133 return 134 (valor); 135} 136/* 137//Celsius para Fahrenheit 138double Fahrenheit(double celsius) 139{ 140 141 return 1.8 * celsius + 32; 142} 143 144//Celsius para Kelvin 145double Kelvin(double 146 celsius) 147{ 148 return celsius + 273.15; 149} 150*/ 151// dewPoint function NOAA 152// 153 reference: http://wahiduddin.net/calc/density_algorithms.htm 154double dewPoint(double 155 celsius, double humidity) 156{ 157 double A0 = 373.15 / (273.15 + celsius); 158 159 double SUM = -7.90298 * (A0 - 1); 160 SUM += 5.02808 * log10(A0); 161 SUM += 162 -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / A0))) - 1) ; 163 SUM += 8.1328e-3 * (pow(10, 164 (-3.49149 * (A0 - 1))) - 1) ; 165 SUM += log10(1013.246); 166 double VP = pow(10, 167 SUM - 3) * humidity; 168 double T = log(VP / 0.61078); // temp var 169 return 170 (241.88 * T) / (17.558 - T); 171} 172/* 173// delta max = 0.6544 wrt dewPoint() 174// 175 5x faster than dewPoint() 176// reference: http://en.wikipedia.org/wiki/Dew_point 177double 178 dewPointFast(double celsius, double humidity) 179{ 180 double a = 17.271; 181 double 182 b = 237.7; 183 double temp = (a * celsius) / (b + celsius) + log(humidity / 100); 184 185 double Td = (b * temp) / (a - temp); 186 return Td; 187} 188*/ 189void setup() 190{ 191 192 pinMode(10, OUTPUT); // SD ChipSelect 193 pinMode(13, OUTPUT); // LED de monitorizaao 194 195 pinMode(redLEDpin, OUTPUT); 196 pinMode(greenLEDpin, OUTPUT); 197 198 // Inicializaao 199 do porto serie: 200 Serial.begin(9600); 201 202 //Inicializaao do I2C 203 Wire.begin(); 204 205 206 //Inicializao do LCD 207 lcd.begin(16, 2); 208 lcd.setBacklight(TEAL); 209 lcd.clear(); 210 211 lcd.setCursor(0, 0); 212 lcd.print("Data Logger V5.5"); 213 lcd.setCursor(0, 214 1); 215 lcd.print("Luis Sousa-2015"); 216 delay(900); 217 lcd.clear(); 218 219 220 //Inicializaao do sensor de temperatura 221 Serial.print("DHT11 LIBRARY VERSION: 222 "); 223 Serial.println(DHT11LIB_VERSION); 224 Serial.println(); 225 int chk 226 = DHT11.read(DHT11PIN); 227 Serial.print("Sensor de Temperatura: "); 228 switch 229 (chk) 230 { 231 case 0: Serial.println("OK"); break; 232 case -1: erro("DHT11 233 Checksum"); break; 234 case -2: erro("DHT11 Time out"); break; 235 default: 236 erro("DHT11 Error"); break; 237 } 238 Serial.println(); 239 240 //Inicializao 241 do SD Card 242 if (!SD.begin(chipSelect)) // Verifica Presena do SD Card: 243 { 244 245 erro("Introduza SD"); 246 /* 247 Serial.println("Introduza Cartao SD"); 248 249 lcd.clear(); 250 lcd.setCursor(0, 0); 251 lcd.print("Introduza "); 252 253 lcd.setCursor(0, 1); 254 lcd.print("Cartao SD"); 255 // Sai por falta 256 de Cartao 257 return; 258 */ 259 } 260 else Serial.println("Cartao SD OK."); 261 262 263 // cria novo ficheiro 264 //char filename[] = "LOGDAT00.CSV"; 265 //for (uint8_t 266 i = 0; i < 100; i++) 267 //{ 268 // filename[6] = i / 10 + '0'; 269 // filename[7] 270 = i % 10 + '0'; 271 // if (! SD.exists(filename)) 272 // { 273 // // se 274 nao existir, cria novo 275 File logfile = SD.open(ficheiro, FILE_WRITE); 276 // 277 break; // sai do loop! 278 // } 279 //} 280 if (! logfile) 281 { 282 erro("Erro 283 no ficheiro"); 284 } 285 else 286 { 287 Serial.print("Gravando em: "); 288 289 Serial.println(ficheiro); 290 logfile.println(cabecalho); 291 logfile.close(); 292 293 } 294#if ECHO_TO_SERIAL 295 Serial.println(cabecalho); 296#endif //ECHO_TO_SERIAL 297 298 299 //Inicializao do RTC 300 if (!RTC.begin()) 301 { 302 // logfile.println("RTC 303 com avaria"); 304 // Serial.println("RTC com avaria"); 305 erro("RTC com 306 avaria"); 307 } 308 if (! RTC.isrunning()) 309 { 310 Serial.println("RTC 311 parado"); 312 // linha seguinte acerta RTC para data/hora da compilaao 313 RTC.adjust(DateTime(F(__DATE__), 314 F(__TIME__))); 315 Serial.println("RTC ajustado"); 316 // para ajustar para 317 uma determinada data/hora por ex: 318 // 21 de Janeiro de 2014 as 03h escreveria: 319 320 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 321 } 322} 323 324void loop() 325{ 326 327 digitalWrite(greenLEDpin, HIGH); // Inicia Escrita 328 329 Vin = (55.00 * analogRead(0) 330 / 1024); 331 int chk = DHT11.read(DHT11PIN); 332 float humid = DHT11.humidity; 333 334 float tempC = DHT11.temperature; 335 tempC = tempC - 2; // Correco apos calibrao 336 337 //float tempK = Kelvin(tempC); 338 //float tempF = Fahrenheit(tempC); 339 float 340 dewP = dewPoint(tempC, humid); 341 int luzV = analogRead(luzP); 342 /* 343 if 344 (Vin < 7.50) lcd.setBacklight(0); //modo poupana de energia 345 else lcd.setBacklight(TEAL); 346 347 */ 348 DateTime now; 349 now = RTC.now(); 350 uint32_t m = millis(); 351 352 353 //display data 354 lcd.setCursor(0, 0); 355 lcd.print(now.day(), DEC); 356 lcd.print("/"); 357 358 lcd.print(now.month(), DEC); 359 lcd.print("/"); 360 lcd.print(now.year(), 361 DEC); 362 lcd.print(" "); 363 lcd.print(now.hour(), DEC); 364 lcd.print(":"); 365 366 lcd.print(now.minute(), DEC); 367 lcd.print(" "); 368 lcd.setCursor(0, 1); 369 370 lcd.print("T:"); 371 lcd.print(tempC, 0); 372 lcd.print("C H:"); 373 lcd.print(humid, 374 0); 375 lcd.print("% "); 376 lcd.print("D:"); 377 lcd.print(dewP, 0); 378 379 lcd.print(" "); 380 381 // log data 382 File logfile = SD.open(ficheiro, 383 FILE_WRITE); 384 if (logfile) 385 { 386 logfile.print(m); // millisegundos 387 desde o inicio 388 logfile.print(","); 389 logfile.print(now.day(), DEC); 390 391 logfile.print("/"); 392 logfile.print(now.month(), DEC); 393 logfile.print("/"); 394 395 logfile.print(now.year(), DEC); 396 logfile.print(","); 397 logfile.print(now.hour(), 398 DEC); 399 logfile.print(":"); 400 logfile.print(now.minute(), DEC); 401 402 logfile.print(":"); 403 logfile.print(now.second(), DEC); 404 logfile.print(","); 405 406 logfile.print(Vin, 2); 407 logfile.print(","); 408 logfile.print(luzV); 409 410 logfile.print(","); 411 logfile.print(tempC, 0); 412 logfile.print(","); 413 414 logfile.print(humid, 0); 415 logfile.print(","); 416 logfile.println(dewP, 417 0); 418 logfile.close(); 419 } 420 else 421 { 422 erro("Erro no ficheiro"); 423 424 } 425#if ECHO_TO_SERIAL 426 Serial.print(m); // millisegundos desde o inicio 427 428 Serial.print(","); 429 Serial.print(now.day(), DEC); 430 Serial.print("/"); 431 432 Serial.print(now.month(), DEC); 433 Serial.print("/"); 434 Serial.print(now.year(), 435 DEC); 436 Serial.print(","); 437 Serial.print(now.hour(), DEC); 438 Serial.print(":"); 439 440 Serial.print(now.minute(), DEC); 441 Serial.print(":"); 442 Serial.print(now.second(), 443 DEC); 444 Serial.print(","); 445 Serial.print(Vin, 2); 446 Serial.print(","); 447 448 Serial.print(luzV); 449 Serial.print(","); 450 Serial.print(tempC, 0); 451 452 Serial.print(","); 453 Serial.print(humid, 0); 454 Serial.print(","); 455 456 Serial.println(dewP, 0); 457#endif //ECHO_TO_SERIAL 458 459 digitalWrite(greenLEDpin, 460 LOW); // acabou escrita 461 462 //Teste aos butoes do LCD 463 for (byte i = 0; 464 i < 20; i++) 465 { 466 delay(pausa / 20); 467 buttons = lcd.readButtons(); 468 469 if (buttons) 470 { 471 if (buttons & BUTTON_UP) 472 { 473 lcd.setCursor(0, 474 1); 475 lcd.print("Vin: "); 476 lcd.print(Vin, 2); 477 lcd.print("V 478 "); 479 } 480 if (buttons & BUTTON_DOWN) 481 { 482 lcd.setCursor(0, 483 1); 484 lcd.print("Luz: "); 485 lcd.print(luzV); 486 lcd.print(" 487 "); 488 delay(500); //debounce 489 buttons = lcd.readButtons(); 490 491 if (buttons & BUTTON_DOWN) 492 { 493 now = RTC.now(); 494 495 year = now.year(); 496 month = now.month(); 497 day 498 = now.day(); 499 hour = now.hour(); 500 minute = now.minute(); 501 502 year = RtcAdj("Ano: ", year); 503 month = RtcAdj("Mes: ", 504 month); 505 day = RtcAdj("Dia: ", day); 506 hour = RtcAdj("Hora: 507 ", hour); 508 minute = RtcAdj("Minutos: ", minute); 509 RTC.adjust(DateTime(year, 510 month, day, hour, minute, 0)); 511 lcd.setCursor(0, 1); 512 char 513 msg[] = "RTC Ajustado "; 514 lcd.print(msg); 515 logfile.println(msg); 516 517 Serial.println(msg); 518 } 519 } 520 if (buttons & BUTTON_LEFT) 521 522 { 523 LCDColor = LCDColor - 1; 524 if (LCDColor < 1) LCDColor 525 = 1; 526 lcd.setBacklight(LCDColor); 527 } 528 if (buttons & BUTTON_RIGHT) 529 530 { 531 LCDColor = LCDColor + 1; 532 if (LCDColor > 7) LCDColor 533 = 7; 534 lcd.setBacklight(LCDColor); 535 } 536 if (buttons & BUTTON_SELECT) 537 538 { 539 if (LCDColor > 0)LCDColor = 0; 540 else LCDColor = (TEAL); 541 542 lcd.setBacklight(LCDColor); 543 } 544 } 545 } 546} 547 548
Downloadable files
Sensor Diagram
Fritzing Schematic
Sensor Diagram
Display connections
4 wires is all you need to connect this display
Display connections
Display connections
4 wires is all you need to connect this display
Display connections
Temperature and humidity Sensor DHT11 connections
The DHT11 is mounted on the prototyping area of the data logger shield. The diagram is the one showed in this picture.
Temperature and humidity Sensor DHT11 connections
Sensor Connection Diagram
jpg file, showing how to connect the sensors
Sensor Connection Diagram
Temperature and humidity Sensor DHT11 connections
The DHT11 is mounted on the prototyping area of the data logger shield. The diagram is the one showed in this picture.
Temperature and humidity Sensor DHT11 connections
Sensor Connection Diagram
jpg file, showing how to connect the sensors
Sensor Connection Diagram
Comments
Only logged in users can leave comments
lmsousa
0 Followers
•0 Projects
Table of contents
Intro
24
0