Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include <NewPing.h>
#include <Servo.h>.
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define TRIG_PIN 2
#define ECHO_PIN 3
#define MAX 40
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX);
const int trigPin = 2;
const int echoPin = 3;
const int ledPin1 = 13;
const int ledPin2 = 12;
const int ledPin3 = 11;
long duration;
int distance;
Servo myServo;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
Serial.begin(9600);
myServo.attach(9);
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Mesafe: ");
}
void loop() {
int distance = sonar.ping_cm();
lcd.setCursor(0, 1);
if (distance > 0 && distance <= MAX) {
lcd.print(distance);
lcd.print(" cm ");
} else {
lcd.print("GUVENLIK YOGUN");
}
delay(30);
for(int i=15;i<=165;i++){
myServo.write(i);
delay(30);
distance = calculateDistance();
// LCD ekranı her hareket sırasında güncelle
lcd.setCursor(0, 1);
if (distance > 0 && distance <= MAX) {
lcd.print(distance);
lcd.print(" cm ");
} else {
lcd.print("GUVENLIK YOGUN");
}
// LED'leri mesafeye göre yakma
if (distance > 40) { // Uzak mesafe (100cm ve üzeri)
digitalWrite(ledPin1, HIGH); // LED 13 yanar
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
else if (distance > 20) { // Orta mesafe (50cm - 100cm)
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH); // LED 12 yanar
digitalWrite(ledPin3, LOW);
}
else { // Yakın mesafe (50cm ve altı)
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH); // LED 11 yanar
}
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
for(int i=165;i>15;i--){
myServo.write(i);
delay(30);
distance = calculateDistance();
// LCD ekranı her hareket sırasında güncelle
lcd.setCursor(0, 1);
if (distance > 0 && distance <= MAX) {
lcd.print(distance);
lcd.print(" cm ");
} else {
lcd.print("GUVENLIK YOGUN");
}
// LED'leri mesafeye göre yakma
if (distance > 40) { // Uzak mesafe (100cm ve üzeri)
digitalWrite(ledPin1, HIGH); // LED 13 yanar
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
else if (distance > 20) { // Orta mesafe (50cm - 100cm)
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH); // LED 12 yanar
digitalWrite(ledPin3, LOW);
}
else { // Yakın mesafe (50cm ve altı)
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH); // LED 11 yanar
}
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
int calculateDistance(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
return distance;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team