#include <NewPing.h>
#include <Bounce2.h>
#define TRIG_PIN D2
#define ECHO_PIN D3
#define BUZZER_PIN D4
#define BUTTON_PIN D18
NewPing sonar(TRIG_PIN, ECHO_PIN);
Bounce debouncer = Bounce();
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
debouncer.attach(BUTTON_PIN);
debouncer.interval(10);
Serial.begin(115200);
}
void loop() {
debouncer.update();
// Check if the button is pressed
if (debouncer.fell()) {
startVoiceNavigation();
}
delay(50);
int distance = sonar.ping_cm();
if (distance > 0 && distance <= 30) {
// Obstacle detected within 30 cm
digitalWrite(BUZZER_PIN, HIGH);
delay(500); // Adjust as needed
digitalWrite(BUZZER_PIN, LOW);
}
}
void startVoiceNavigation() {
// Add code here to trigger voice search or any other actions
// on your connected mobile device (e.g., using Bluetooth or Wi-Fi).
// This can involve sending specific commands or messages to a mobile app.
}