Jump to content
JeysonZG

[Energia Library] Ping4Pins: For 4-pins and 3-pins PING sensor

Recommended Posts

- INTRODUCTION
 
Hi everybody, I want to share a library for controlling a 4-pins PING sensor (HC-SR04 ICStation) basically, although you can also control the 3-pins PING))) sensor conventional of Parallax (URL). 
 
This library is a modification of the Caleb Zulawski's library for PING))) sensors. I made basic improvements in calculations, I added a function to calculate the distance in millimeters and added the option to change the "input trigger signal" [10uS for HC-SR04 and 5uS for PING)))]
 
 
- CHANGE LOG
 
v2.1 (26/08/2014)
 
* Fixed calculations of distance in inches.
 

v2.0 (25/08/2014)
 
* Fixed problems with measurements adjustments.
* New function for modification of a single unit.

 v1.0 (24/08/2014)
 
* Basic modification of Caleb Zulawski's library.
* Added the calculation of distace in millimeters.
* Identified problems with measurements adjustments.
 
- TESTING
 
Tested on: Tiva C (TM4C123GXL) & Arduino UNO R3
 
- COMPARISON SECTION
 
A small comparison between the 2 sensors is: 
 
* HC-SR04 sensor: 
 
1. Working Voltage: 5V (DC) 
2. Output signal: Electric frequency signal, high level 5V, 0V low level. 
3. Sensor angle: Not more than 15 degrees. 
4. Detection distance: 2cm-450cm
5. High precision: Up to 0.3cm 
6. Input trigger signal: TTL impulse 10uS 
7. Mode of connection
   1. VCC 
   2. TRIG ( T ) 
   3. ECHO ( R ) 
   4. GND 
 
* PING))) sensor: 
 
1. Working Voltage: 5V (DC) 
2. Output signal: Electric frequency signal, high level 5V, 0V low level. 
3. Sensor angle: Not more than 15 degrees. 
4. Detection distance: 2cm-300cm
5. High precision: Up to 0.3cm 
6. Input trigger signal: TTL impulse 5us 
7. Mode of connection
   1. GND 
   2. VCC 
   3. SG
 

- DOWNLOAD SECTION
 
v2.1: Ping4Pins v2.1.zip

 

v2.0 (Not recommended)Ping4Pins v2.0.zip

 
v1.0 (Not recommended): Ping4Pins v1.0.zip

 
- INSTRUCTIONS OF INSTALLATION
 
1. Download the latest version of the library
2. Unzip the zip-folder. 
3. Copy the "Ping4Pins" folder in the location of the libraries depending of your trainer:
  * For Arduino: <Arduino IDE directory>\hardware\libraries\
  * For Tiva C: <Energia IDE directory>\hardware\lm4f\libraries\
 
Note: If you used an older version of the library, I recommend deleting the folder and copy the new folder "Ping4Pins".
 
- EXAMPLES SECTION
 
In the "examples" folder are 5 examples for Arduino and 5 examples for Tiva. I'll post the example # 1:
 

/*Example # 1 for TivaC / ArduinoCreated by Jeyson Zu

post-38194-0-06979800-1409031381_thumb.jpg

post-38194-0-94825700-1409031384_thumb.jpg

post-38194-0-59036500-1409031388_thumb.jpg

post-38194-0-41514800-1409031391_thumb.jpg

Share this post


Link to post
Share on other sites

After the sensor is given a power supply, it works for a short time, and then goes into the zero display mode permanently. Could you please provide a solution to this ?? I have used the same code provided by you.

Share this post


Link to post
Share on other sites

Hi @@SKS and welcome to 43oh

 

It isn't clear to me from your description what the problem is but here are some suggestions:

  • The SR04 is a 5V device.  You don't state what microcontroller you are using but most LaunchPads are 3.3V and are not 5V tolerant (although I believe the Tiva C in the original post is).  In any case, I would not hook up a 5V input to a LaunchPad pin as this can damage the pin in the worst case, or not give the desired results in the best case.
  • The SR04 is a really simple device and a library isn't really necessary.  The basic algorithm is 1) initiate a ping, 2) measure the time it takes for it to return, and 3) calculate the distance knowing the speed of sound.

Here is an Energia sketch that includes a description of a voltage divider to reduce voltage to 3.3 V: https://github.com/fmilburn3/Distance_Sensor_HC-SR04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×