#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>
#include <Servo.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
LiquidCrystal_I2C lcd(0x27,16,2);
Servo myservo;
Servo myservo2;
unsigned long previousMillis = 0;
unsigned long elapsedMillis = 0;
int pos ;
int ledState = LOW;
int debounceTime = 100;
void setup()
{
mlx.begin();
lcd.init();
lcd.backlight();
myservo.attach(4);
myservo2.attach(5);
pinMode(9, INPUT);
lcd.setCursor(1,0);
lcd.print("Hello Everyone");
lcd.setCursor(1,1);
lcd.print("Loading. . . . .");
delay(2000);
lcd.clear();
}
void loop()
{
Handsanit();
}
void Handsanit(){
elapsedMillis = millis() - previousMillis;
if(digitalRead(9) == LOW && elapsedMillis > debounceTime){
if(ledState == HIGH){
ledState = LOW;
lcd.setCursor(1,0);
if(mlx.readObjectTempC()>37){
delay(100);
lcd.print("suhu anda tinggi!!");
}
lcd.print(" NonContact ");
lcd.setCursor(2,1);
lcd.print("Suhu: ");
lcd.print(mlx.readObjectTempC()+2.2);
lcd.print("C ");
delay(500);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
for (pos = 40; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}else{
for ( ;pos <= 80; pos += 1)
{
myservo.write(pos);
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5);
}
ledState = HIGH;
lcd.setCursor(1,0);
if(mlx.readObjectTempC()>37){
delay(1000);
lcd.print("Suhu Anda Tinggi!!");
}
lcd.print(" NonContact ");
lcd.setCursor(2,1);
lcd.print("Suhu: ");
lcd.print(mlx.readObjectTempC()+2.2);
lcd.print("C ");
delay(500);
}
previousMillis = millis();
}
}<br>
Comments