Wednesday, December 18, 2024

Blind_stick_Arduino_Uno

 #define TRIG_PIN 9

#define ECHO_PIN 10

#define BUZZER_PIN 11

#define VIBRATION_PIN 12


void setup() {

  pinMode(TRIG_PIN, OUTPUT);

  pinMode(ECHO_PIN, INPUT);

  pinMode(BUZZER_PIN, OUTPUT);

  pinMode(VIBRATION_PIN, OUTPUT);

  Serial.begin(9600);

}


void loop() {

  long duration, distance;


  // Send a 10µs pulse to the TRIG pin

  digitalWrite(TRIG_PIN, LOW);

  delayMicroseconds(2);

  digitalWrite(TRIG_PIN, HIGH);

  delayMicroseconds(10);

  digitalWrite(TRIG_PIN, LOW);


  // Read the echo pin duration

  duration = pulseIn(ECHO_PIN, HIGH);


  // Calculate the distance in cm

  distance = duration * 0.034 / 2;


  // Display distance in the Serial Monitor

  Serial.print("Distance: ");

  Serial.print(distance);

  Serial.println(" cm");


  // Activate buzzer and vibration motor if an obstacle is detected

  if (distance > 0 && distance <= 50) { // Obstacle within 50 cm

    digitalWrite(BUZZER_PIN, HIGH);

    digitalWrite(VIBRATION_PIN, HIGH);

  } else {

    digitalWrite(BUZZER_PIN, LOW);

    digitalWrite(VIBRATION_PIN, LOW);

  }


  delay(100); // Short delay to stabilize readings

}


No comments:

Post a Comment

MUD Three Mode operation Manual Automatic GPS

 Code for three mode operation: /*   3-Mode Headlight Controller   - Manual mode (driver uses a toggle to pick high/low)   - Auto mode (LDR...