Sistem Wiper Mobil Otomatis Menggunakan ESP32
Berikut adalah program arduino untuk sistem wiper mobil otomatis, dalam hal ini adalah miniaturnya menggunakan komponen sebagai berikut:
- ESP32
- Dua buah Servo
- Sensor Rain Drop
Dengan fungsi sensor hujan yang dipasang pada mobil mendeteksi air yang jatuh di permukaannya, lalu mengaktifkan wiper secara otomatis tanpa perlu ditekan tombolnya. Pengemudi jadi bisa tetap fokus berkendara tanpa terganggu saat hujan tiba-tiba turun.
#include
const int rainSensorPin = 34; // Pin analog input ESP32 (contoh: GPIO34)
const int servoPin1 = 18; // Servo pertama (PWM pin, contoh GPIO13)
const int servoPin2 = 19; // Servo kedua (PWM pin, contoh GPIO14)
const int threshold = 2000; // Ambang batas sensor hujan (atur sesuai kebutuhan)
Servo servo1;
Servo servo2;
void setup() {
Serial.begin(115200);
// Allow allocation of all timers
ESP32PWM::allocateTimer(0);
//ESP32PWM::allocateTimer(1);
// Set up first servo
servo1.setPeriodHertz(50); // standard 50 hz servo
servo1.attach(servoPin1, 1000, 2000); // attaches the servo on pin 18
// Set up second servo
servo2.setPeriodHertz(50); // standard 50 hz servo
servo2.attach(servoPin2, 1000, 2000); // attaches the servo on pin 19
servo1.write(0); // Mulai dari posisi 0 derajat
servo2.write(0);
}
void loop() {
int rainValue = analogRead(rainSensorPin);
Serial.println(rainValue); // Tampilkan nilai untuk debugging
if (rainValue < threshold) {
// Jika tidak ada air
servo1.write(180);
servo2.write(180);
delay(500);
servo1.write(0);
servo2.write(0);
delay(500);
servo1.write(180);
servo2.write(180);
delay(500);
servo1.write(0);
servo2.write(0);
delay(500);
servo1.write(180);
servo2.write(180);
delay(500);
servo1.write(0);
servo2.write(0);
delay(500);
servo1.write(180);
servo2.write(180);
delay(500);
servo1.write(0);
servo2.write(0);
} else {
servo1.write(0);
servo2.write(0);
}
delay(500); // Tunggu sebentar sebelum pembacaan berikutnya
}
0 Response to "Sistem Wiper Mobil Otomatis Menggunakan ESP32"
Post a Comment