#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2);
#define PINO_TRIGGER 10
#define PINO_ECHO 9
int PINO_NTC = A0;
const float BETA = 3950;
int PINO_LDR = A3;
//int polegadas = 0;
//int centimetros = 0;
long readUltrasonicDistance() {
digitalWrite(PINO_TRIGGER, LOW);
delayMicroseconds(2);
digitalWrite(PINO_TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(PINO_TRIGGER, LOW);
return pulseIn(PINO_ECHO, HIGH);
}
void setup() {
pinMode(PINO_TRIGGER, OUTPUT);
pinMode(PINO_ECHO, INPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Fund. Bradesco ");
lcd.setCursor(0,1);
lcd.print(" IOT ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bancos de Dados ");
lcd.setCursor(0,1);
lcd.print("Aplicados a IoT ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Projeto ");
lcd.setCursor(0,1);
lcd.print(" IOT ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Componentes: ");
lcd.setCursor(0,1);
lcd.print("Eduardo R. Dias");
delay(2000);
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Recuperar dados");
lcd.setCursor(0,1);
lcd.print(" dos sensores ");
delay(5000);
int centimetros = 0.01723 * readUltrasonicDistance();
int polegadas = (centimetros / 2.54);
int temp_c = 1 / (log(1 / (1023. / analogRead(PINO_NTC) - 1)) / BETA + 1.0 / 298.15) - 273.15;
int temp_f = (temp_c * 9) / 5 + 32;
int valor_LDR = analogRead(PINO_LDR);
int luminosidade = map(valor_LDR,8,1015,100,0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Dist.: ");
lcd.print(centimetros);
lcd.print(" cm ");
lcd.setCursor(0,1);
lcd.print("Dist.: ");
lcd.print(polegadas);
lcd.print(" pol ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp.: ");
lcd.print(temp_c);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Temp.: ");
lcd.print(temp_f);
lcd.print(" F");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Obtido: ");
lcd.print(valor_LDR);
lcd.setCursor(0,1);
lcd.print("Calculado: ");
lcd.print(luminosidade);
lcd.print(" %");
delay(2000);
}