139k views
1 vote
Write code to design of an Arduino-based obstacles detection system. When detect any object; calculate distance between Ultrasonic sensor and an object and view the result on the virtual terminal. When the distance above 400 cm; the alarm (buzzer and warning message) will be activated. - Design your system using Proteus simulator. - Write your code in Arduino editor - Test your design and make screen shots of your result.

User Satran
by
7.9k points

1 Answer

3 votes

The code to design of an Arduino-based obstacles detection system.

// Define constants for ultrasonic sensor pins and buzzer pin

const int trigPin = 2;

const int echoPin = 3;

const int buzzerPin = 4;

// Define constants for distance threshold and alarm distance

const int distanceThreshold = 400; // in centimeters

const int alarmDistance = 100; // in centimeters

void setup() {

Serial.begin(9600); // Initialize serial communication for virtual terminal

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(buzzerPin, OUTPUT);

}

void loop() {

// Trigger ultrasonic sensor to send and receive a pulse

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW

User Benzy Neez
by
7.4k points