/*
//HELLO_WORLD_TEST_OK
// C++ code
//
#include <Adafruit_LiquidCrystal.h>
int seconds = 0;
Adafruit_LiquidCrystal lcd_1(0);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
lcd_1.begin(16, 2);
lcd_1.print("hello world");
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
lcd_1.setCursor(0, 1);
lcd_1.print(seconds);
lcd_1.setBacklight(1);
delay(500); // Wait for 500 millisecond(s)
lcd_1.setBacklight(0);
delay(500); // Wait for 500 millisecond(s)
seconds += 1;
}
*/
#include <Adafruit LiquidCrystal.h>
Adafruit_LiquidCrystal lcd(0);
int pirPin = 2; // Sensor PIR
int tempPin = A0; // TMP36
int motorPin = 9; // Motor (PWM)
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(motorPin, OUTPUT);
lcd.begin(16,2);
lcd.setBacklight(1);
Serial.begin(9600);
}
void loop() {
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
int movimento = digitalRead(pirPin);
int leituraTemp = analogRead(tempPin);
float temperatura = (leituraTemp * 5.0 / 1024.0 - 0.5) * 100;
int velocidade = 0;
int nivel = 0;
if (movimento == HIGH) {
if (temperatura >= 11 && temperatura <= 15) velocidade = 42, nivel = 1;
else if (temperatura >= 16 && temperatura <= 20) velocidade = 85, nivel = 2;
else if (temperatura >= 21 && temperatura <= 25) velocidade = 127, nivel = 3;
else if (temperatura >= 26 && temperatura <= 30) velocidade = 170, nivel = 4;
else if (temperatura >= 31 && temperatura <= 35) velocidade = 212, nivel = 5;
else if (temperatura >= 36 && temperatura <= 40) velocidade = 255, nivel = 6;
else if (temperatura < 11) velocidade = 42, nivel = 1;
else if (temperatura > 40) velocidade = 255, nivel = 6;
analogWrite(motorPin, velocidade);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Presenca Detec.");
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.print((int)temperatura);
lcd.print((char)223);
lcd.print("C Vel:");
lcd.print(nivel);
} else {
analogWrite(motorPin, 0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sem Presenca");
lcd.setCursor(0, 1);
lcd.print("Vent. deslig.");
}
delay(1000);
}