Tag Archives: Measure Distance

Arduino Tutorial 60: Add a Go Button to your Distance Sensor

Ultrasonic Distance Sensor
This is our completed build of a portable, ultrasonic distance sensor.

In this lesson we add a “GO” button to our portable distance measurement system. Note that from the work done in Lesson 59, we are only left with digital pin 13. The problem is that pin 13 is connected to the on-board diode, so trying to use pin 13 as a button pin will not work.

Never fear we can use one of the analog in pins. To use an analog in pin as the button pin, in the void setup, you need to declare the pin as an INPUT, and then digitalWrite the pin to HIGH. This will connect it to 5V through a pullup resistor. Now you just have to do a digital read to that pin. When button is untouched, you will read a “1”, and when you press the button, you will read a “0”.

We are building this with parts from our Elegoo Kit , so if you get this kit, you will be using the same hardware we are using.

A challenge with this project is to keep the build neat and compact, which is much easier if you use an Arduino Nano, which allows the project to be built on a single breadboard. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.

This video takes you through the explanation step-by-step:

This is the code used in this project:

 

Arduino Tutorial 53: Understanding and Connecting the HC-SR04 Sensor

This is our HC-SR04 Ultrasonic Sensor Connected to our Arduino Nano.

In this lesson we explore using the HC-SR04 from our Arduino Kit to measure distance. The sensor sends out a ping, and then waits to hear the echo. It measures the time between when the ping is sent and when the echo is heard. Knowing pingTravelTime, allows you to calculate distance from the sensor. In this lesson we will show you how to connect the sensor, and program it to read pingTravelTime. In future lessons we will show you how to change this into distance.

Notice we used an Arduino Nano, which allows the entire project to be build on a single breadboard. This allows a neater, smaller build, and one less likely to have problems from poor or loose connections. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.

Connecting up the HC-SR04 sensor is simple, as illustrated in this diagram:

Schematic for Connecting the HC-SR04 to an Arduino

This video will take you through our build and initial work step-by-step.

The simple code below is what we used in the video to begin making measurements with the sensor.