Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #define trigPin 11 // Trigger Pin
- #define echoPin 12 // Echo Pin
- #define spekerPin 8
- LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
- int toneArr[8] = {523, 587, 657, 698, 784, 880, 987};
- long duration, distance;
- byte time;
- void setup()
- {
- Serial.begin (9600);
- lcd.begin(16, 2);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- digitalWrite(trigPin, LOW);
- }//End of setup function
- void loop()
- {
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- Serial.print("Distance = ");
- lcd.setCursor(0, 0);
- lcd.print("Distance = CM");
- lcd.setCursor(10, 0);
- distance = duration / 58;
- Serial.println(distance);
- lcd.print(distance);
- if (distance < 60) {
- tone(spekerPin, toneArr[2]);
- delay(distance * 5);
- tone(spekerPin, toneArr[5]);
- delay(distance * 2);
- }
- else
- noTone(spekerPin);
- delay(50);
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement