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
The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:
- Control Register
- Logic Low ‘0’
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.
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.
For this example we have bread boarded two Ultrasonic Sensors and connected them to the Pioneer Board.
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.
The ultrasonic receiver is connected to our Opamp component on the Amplifier_plus line, P1.
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 -> P5LP P12
PSoC 4 P4 -> P5LP P12
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.