#include <NewPing.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27,16,2);
DHT dht(9, DHT22);
NewPing sonar(3,2,400);
Servo s;
char data[3];
char pass[3] = {'c', 'a', 't'};
int index = 0;
void setup()
{
Serial.begin(9600);
dht.begin();
pinMode(9, INPUT);
s.attach(7);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
Serial.println("Text here:");
lcd.begin(16, 2);
lcd.setCursor(3,1);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("type pass:");
}
void loop()
{
//passCheck();
//Serial.println(analogRead(A0));
//delay(1000);
//Temperature();
sonar();
}
void passCheck(){
if (Serial.available()) {
data[index] = Serial.read();
index++;
Serial.print("*");
if (index == 4) {
Serial.println(" ");
for (int i = 0; i < 3; i++) {
if (pass[i] != data[i] && (analogRead(A0) <= 333 || analogRead(A0) >= 444)) {
lcd.clear();
Serial.println("Wrong pass");
lcd.setCursor(3,0);
lcd.print("Wrong pass");
lcd.setCursor(0,1);
lcd.println("You're criminal?");
index = 0;
return;
}
if(analogRead(A0) > 333 && analogRead(A0) < 444){
Serial.print(data[i]);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("true pass!");
lcd.setCursor(4,1);
lcd.print("Welcome!");
// delay(5000);
}
}
index = 0;
}
}
}
void Temperature(){
//lcd.clear();
delay(100);
float t =dht.readTemperature();
lcd.setCursor(0,0);
lcd.print("Temperatur:");
lcd.print(t);
if(t <= 18){
lcd.setCursor(0,1);
lcd.print("very cold");
}
else if(t > 18 && t < 24){
lcd.setCursor(0,1);
lcd.print("Normal ");
}
else if(t >= 24){
lcd.setCursor(0,1);
lcd.print("very hot ");
Servovertalet();
}
}
void Servovertalet(){
delay(500);
s.write(0);
delay(500);
s.write(360);
}
NewPing sonar(11,12,400);
void setup() {
Serial.begin(9600);
for(int i = 9; i < 11; i++){
pinMode(i, OUTPUT);
}
}
void sonar() {
unsigned int dist = sonar.ping_cm();
delay(100);
Serial.println(dist);
if(dist > 200){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
else{
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
}