Problem with Ultrasonic Sensor Distance HC-SR04

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
trawakarolek_49
Level 1
Level 1
First question asked Welcome!

Hello, I am new to the psoc product. I'm trying to use a distance sensor. The firmware does not work as it should and I do not know if it is the fault of a faulty sensor or software errors. The sensor is connect correctly (the pins are exactly the same as in the psoc wizard). The sensor shows a random value and does not refresh it until I lift the object (large cardboard) above the sensor, I put it in another place in the plug, a different value is displayed, not similar to the real one. Can someone please help me?

0 Likes
1 Solution
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

The trigger pulse must be very short (~ 10 microseconds):
............................
for(;;)
{
/* Place your application code here. */
// while(echo_Read() == 0 )
// {
Trigger_out_Write(1);
CyDelayUs(10u); // positive Trigger pulse time 10 microseconds
Trigger_out_Write(0);
CyDelay(1); // waiting for sending 8 pulses (0,5 mSec)
// }
while(echo_Read() == 1){};
...............................

diagram.png


On this forum you will find many examples of working with the HC-SRO4.

eg: Ultrasonic Distance Sensor HC-SRO4

View solution in original post

0 Likes
1 Reply
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

The trigger pulse must be very short (~ 10 microseconds):
............................
for(;;)
{
/* Place your application code here. */
// while(echo_Read() == 0 )
// {
Trigger_out_Write(1);
CyDelayUs(10u); // positive Trigger pulse time 10 microseconds
Trigger_out_Write(0);
CyDelay(1); // waiting for sending 8 pulses (0,5 mSec)
// }
while(echo_Read() == 1){};
...............................

diagram.png


On this forum you will find many examples of working with the HC-SRO4.

eg: Ultrasonic Distance Sensor HC-SRO4

0 Likes