Arduino with HC
Arduino with HC
monitor.
Introduction
HC-SR04 sensor is used to read and write the distance in the serial monitor.
1) Arduino UNO
2) HC-SR04 sensor (Ultrasonic Sensor)
3) Few jumpers wire
1. Arduino IDE
Arduino IDE
Hardware description
Arduino UNO
Ultrasonic sensor
This device measures distance by emitting high frequency sound waves and
analyzing the echo that returns after hitting an object. These sensors are
widely used in various applications such as robotics, automative systems,
industrial automation, and smart home devices due to their ability to provide
accurate and reliable distance measurement without using physical contact.
Sound waves typically above 20kHz is sent from a transmitter; these waves
encounter an object and bounce back. The sensor’s receiver captures the
reflected waves.
The sensor determines the distance to the object using the formula
Jumper wires
Jumper wires are simple electrical wires with connector pins at both ends
designed to connect various components in a circuit without soldering. They
are widely used in prototyping and breadboarding allowing hobbyists and
engineers to quickly and efficiently build and test circuits.
1. Male to Male : Both ends have pins that fit into female connectors or
breadboard holes.
2. Male to Female: One end has a pin(male), and the other has a
socket(female), making them suitable for connecting breadboards to
components or modules with male headers.
3. Female to Female: Both ends have sockets, ideal for connecting
components or modules with male pins.
Jumper wires are usually color-coded( eg., red for power, black for
ground) to help organize and distinguish connections.
Circuit Diagram
// for Ultrasonic sensor
Step 2: Connect the GND of Ultrasonic Sensor to the GND of the Arduino
Step 3: Connect the Trigger pin of the Ultrasonic Sensor the pin 10 of the
Arduino.
Step 4: Connect the Echo Pin of the Ultrasonic Sensor the pin 11 of the
Arduino.
int trigPin=10;
int echoPin=11;
void setup() {
Serial.begin(9600);
//Define inputs and outputs
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
void loop() {
digitalWrite(trigPin,LOW);
delayMicroseconds(5);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
pinMode(echoPin, INPUT);
duration=pulseIn(echoPin, HIGH);
cm=(duration/2)/29.1;
inches=(duration/2)/74;
Serial.print(inches);
Serial.print("in,");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(250);
}