Distance Measurement using CloudX CloudX

  • img
Project Details

Ultrasonic range finders are fun little modules that measure distance. You can use them to find the distance to an object, or to detect when something is near the sensor like a motion detector. They’re ideal for projects involving navigation, object avoidance, and home security. Because they use sound to measure distance, they work just as well in the dark as they do in the light. The ultrasonic range finder used in this tutorial is the HC-SR04, which can measure distances from 2 cm up to 400 cm with an accuracy of ±3 mm. 

 

Ultrasonic Range Finder Details

 

The HC-SR04 ultrasonic range finder has four pins: VCC, Trig, Echo, and GND. The VCC pin supplies the power to generate the ultrasonic pulses. The GND pin is connected to ground. The Trigpin is where the CloudX sends the signal to start the ultrasonic pulse. The Echo pin is where the ultrasonic range finder sends the information about the duration of the trip taken by the ultrasonic pulse to the CloudX.

To initiate a distance measurement, we need to send a 5V high signal to the Trig pin for at least 10 µs. When the module receives this signal, it will emit 8 pulses of ultrasonic sound at a frequency of 40 KHz from the transmitting transducer. Then it waits and listens at the receiving transducer for the reflected signal. If an object is within range, the 8 pulses will be reflected back to the sensor. When the pulse hits the receiving transducer, the Echo pin outputs a high voltage signal.

 

I am going to use the 4 digital tube 7 segment display and the TM16374 library.The requirements for this activity is just a basic parts in cloudx, what we have are:

4 Digit 7- segment diplay 

Ultrasonic sensor

CloudX board

Male - Female jumper wires

USB cable

 

Circuit Diagram

 

Code

The code below supports all the cloudx series, so you can either use cloudx Priscilla, cloudx M633 or any other family of the microcontroller board.


#include <CloudX\Ultrasonic.h>
#include <CloudX\Segment_TM1637.h>
#include <CloudX\Ultrasonic.h>

#define trig 5
#define echo 6

#define clk 1
#define dio 2


int distance;
setup(){
//setup here
SegmentTM1637_setting(dio, clk, 5);
Ultrasonic_init(1,trig,echo);
SegmentTM1637_write(0);

loop(){
//Program here
distance = Ultrasonic_read(1);
SegmentTM1637_write(distance);
delay(100);
}

 

Project Testing

                    


 

 

Share this with friends