Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

How To Make Object Detection System using Ultrasonic sensor - Simple circuit

How To Make Object Detection System using Ultrasonic sensor

Here’s an Arduino program that uses an ultrasonic sensor (HC-SR04) and a buzzer. When the ultrasonic sensor detects an object within a certain distance, the buzzer will sound to indicate "Object Detected."

Components:

  • HC-SR04 Ultrasonic Sensor
  • Buzzer
  • Arduino Uno
  • Jumper wires

Circuit:

  • HC-SR04 Ultrasonic Sensor:
    • VCC to 5V
    • GND to GND
    • Trig to Pin 9
    • Echo to Pin 10
  • Buzzer:
    • Positive pin to Pin 3
    • Negative pin to GND

Video Link: - Click Here For Video

How To Make Object Detection System using Ultrasonic sensor simple Circuit: -

How To Make Object Detection System using Ultrasonic sensor Arduino Programming: -

Arduino IDE Program

// Define pins for the ultrasonic sensor and buzzer
#define TRIG_PIN 9
#define ECHO_PIN 10
#define BUZZER_PIN 3
#define LED 6

// Define a distance threshold (in cm) for object detection
#define DISTANCE_THRESHOLD 15
void setup() {
  // Initialize the serial monitor
  Serial.begin(9600);
 
  // Set the pin modes
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  // Trigger the ultrasonic sensor
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
 
  // Read the echo time
  long duration = pulseIn(ECHO_PIN, HIGH);
 
  // Calculate distance (in cm)
  float distanceCm = (duration * 0.0343) / 2;
 
  // Print the distance to the serial monitor
  Serial.print("Distance: ");
  Serial.print(distanceCm);
  Serial.println(" cm");
 
  // Check if the distance is below the threshold
  if (distanceCm <= DISTANCE_THRESHOLD) {
    // Object detected, activate buzzer
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED,HIGH);
    Serial.println("Object Detected!");
  } else {
    // No object, turn off buzzer
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED,LOW);
  }
 
  // Small delay before the next reading
  delay(500);
}


-----------------------------------------------------------------------------------------------------------------------------

Explanation:

  • The ultrasonic sensor measures the distance to an object.
  • If the object is within 20 cm (or any set threshold), the buzzer will sound.
  • You can adjust the DISTANCE_THRESHOLD to change the detection range.

Circuit Simulation:

You can use Tinkercad to simulate this project by adding the ultrasonic sensor, buzzer, and Arduino. Run the simulation to check how it works! Let me know if you need more details or help setting up.

Share, Support, and Subscribe!!! 1. PRO KAM EXPLAINED 2. Knowledge KAM 3. PRO KAM Follow us on 1. Facebook 2. Instagram 3. Pinterest 4. Blogspot 5 Twitter If you have any other ideas to make me design, you can describe them in the comment section and if I can, I will make a designing video on it. So I am waiting #prokam #pro #IDM #Solutions #Hack

Post a Comment

0 Comments

Ad Code

Responsive Advertisement