element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Cypress Kits
  • Products
  • Dev Tools
  • Cypress Kits
  • More
  • Cancel
Cypress Kits
Forum PSoC 4 Pioneer Kit Community Project#038 – Ultrasonic Distance Measurement
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Cypress Kits to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 25 subscribers
  • Views 1915 views
  • Users 0 members are here
  • 100projects
Related

PSoC 4 Pioneer Kit Community Project#038 – Ultrasonic Distance Measurement

cy.wbz
cy.wbz over 12 years ago

Hello!

 

Today’s project will increase the complexity of our schematic design and uses more than 10 components. The project is designed to measure the distance of an object using Ultrasonic sensor. This project uses two 40 kHz ultrasonic transducers (one for each transmitter and receiver). The time between the transmission and reception of pulses is measured to calculate the distance.

 

This example project uses the following hardware:

  • Pioneer Kit
  • GLCD Shield

 

Forum Post Attachments:

 

At the bottom of this post we are including the following items:

  • Example Project Zip File
  • Zip File of Images
  • Project Schematic
  • Component Configurations

 

Components Used:

 

The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:

  • TCPWM
  • UART
  • SPI
  • Timer
  • Opamp
  • Comparator
  • CyClock
  • Control Register
  • ISR
  • Logic Low ‘0’
  • CyPin

 

The components are configured by right clicking on the component in your Top Design schematic view and selecting Configure. Please enable the following selections in the Configuration windows for the listed components above.

 

Firmware Description:

 

The main.c firmware is included in the example project. Please review the commented sections for more details.

 

The Ultrasonic distance measurement method uses a polling method. It continuously sends the pulses of 40 kHz by enabling the TIMER, TCPWM in infinite loop then after 125ms (duration of transmitting 5 pulses) the TCPWM is turned off. An extra 2ms delay is provided so that the object is detected even if the object is at maximum distance. On the timer capture the output pulse of the ISR interrupts and stops the counting of the timer. The ISR also sets the flag on the capture and flag setting circles showing that the object is displayed.

 

Distance calculation is done using the equations that are obtained by Curve fitting method in MATLAB. We used two equations for plotting and distance calculation 1st equation from distance 3cm-10cm, 2nd equation for distance 10cm -30cm.

 

If the object is nearer than 15cm the red LED is turned ON, if object is within range but farther than 15cm green LED is turned ON, else blue LED is turned ON. The distance is also shown at the top of LCD in centimeters. If the object is out of range GLCD shows “xx”.

 

The Ultrasonic waves after reflection from the object are received at the Ultrasonic receiver which gives out the same 40 kHz transmitted pulses. But the received signal is weak, so an amplification circuit is required. We used an inverting amplification circuit (Rf/Rin =20).

 

After the amplification the output is fed into the comparator, and zero crossing detection is done. The comparator output is fed to the Capture input of timer (which captures the timer value). Then on the capture an interrupt is triggered and the TIMER is stopped.

 

The time of flight method is used for finding the distance between the transmitter and the object. The transmitter sends out a burst of pulses and a receiver detects the reflected echo. The time delay between the corresponding edges of the transmitted and received pulses is measured. This gives the time of flight. Substituting the time delay and the velocity of ultrasound in air (330 meters/second) in the following formula we can determine the distance between the transmitter and the target, figure shows the transmitted and received pulses.

 

Hardware Connections:

 

For this example we have bread boarded two Ultrasonic Sensors and connected them to the Pioneer Board.

  • SQ-40-T
  • SQ-40-R

 

Referencing our Creator Schematic design, we will connect our ultrasonic transmitter to our TCPWM component. In this case the sensor is connected to the PWM_out connection, P1[0].

 

The ultrasonic receiver is connected to our Opamp component on the Amplifier_plus line, P1[5].

 

A UART has been added to the project to report the values to hyperterminal. Please make the following connections to enable the PSoC 5LP device’s USB-UART capabilities:

 

PSoC 4 P4[1] -> P5LP P12[6]

PSoC 4 P4[0] -> P5LP P12[7]

 

This example also requires you to connect the GLCD shield to the Pioneer Kit.

 

Test Your Project:

 

Connect up your hardware and program the PSoC 4 device. Launch the hyperterminal software and begin moving the sensors forwards and backwards from a wall. The values will be reported on the PC through the hyperterminal and on the GLCD shield. In the current setup the sensors are limited to 30cm detection. The object that the sensors are detecting must be perpendicular to the surface they are detecting. For example a wall, door, or piece of paper.

 

I hope this example can help you in your design.

 

Best,

Matt

Attachments:
Ultrasonic sensor based distance measurement.zip
34038.Project Images.zip
  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 12 years ago

    I have an idea for some improvement of precision:

     

    Since sonic speed is (nearly) allone dependent on temperature you could measure the die-temperature of the PSoC5 and use the standard formula of calculating the sonic speed.

     

    Bob

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago

    Hello!

    I'm new to PSoC and I got kind of lost in this project, it would be really nice if you could help me out.

     

    -When amplifying the signal, I'm supposed to connect the receiver to the plus input of the opamp and the manage the gain with the resistors  (I added a picture of my circuit)?

    -For the comparator's inputs, comp_p should be the signal of the receiver amplified and comp_n gnd?

     

    Thanks

     

    S.

    Attachments:
    image
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Hi, Sunil here..

     

    This message is to just ask the connection of ultrasonic sensor to the cy8ckit-042-BLE..

    like you have mentioned as

    PSoC 4 P4[1] -> P5LP P12[6]

    PSoC 4 P4[0] -> P5LP P12[7]

     

    If you have any Image of your board and the connections. do attach the same, so it will be very helpful!!

     

    Can you help with the same at the earliest..

     

    Thank you in advance..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube