/*an ai that is not so ai, when you get closer to hc-sr04,
the buzzer will make a sound in hight pitch and the lcd will say "How can i help you?"
but if not that close, buzzer will make sounds but in low pitch and the lcd will
say "Who's there" (i want to make ai, use buzzer instead of speaker and hc-sr04
instead of camera)*/
#include <LiquidCrystal_I2C.h> //for display text
LiquidCrystal_I2C lcd(0x27,16,2); //create an object of lcd
#include <HCSR04.h> //for detect if human is there
UltraSonicDistanceSensor hc(4, 3); //create object of UltraSonic
int buzzer = 2;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
pinMode(buzzer, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (hc.measureDistanceCm() > 100 || hc.measureDistanceCm() >= 400) {
noTone(buzzer);
lcd.clear();
lcd.println("...");
Serial.println("...");
}
else if (hc.measureDistanceCm() >= 50) {
tone(buzzer, 400);
lcd.clear();
lcd.print("Who's there?");
Serial.println("Who's there?");
}
else if (hc.measureDistanceCm() < 20) {
tone(buzzer, 700);
lcd.clear();
lcd.print("How can i help");
lcd.setCursor(0, 1);
lcd.println("you?");
Serial.println("how can i help you?");
}
delay(100);
}