Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] High the Echo Signal in HC SR04

Not open for further replies.

Kishore Varsha

Newbie level 4
Oct 7, 2015
Reaction score
Trophy points
Activity points
I am using CC3200 along with HC SR04...i like to write the code in CCS...i have done but there was a problem while high the echo signal so i have problem in starting the timer...i need timing count to calculate anyone have the idea in it...

Thanks for the support hobbyckts... but my question is how can i high the echo pin...while i'm giving 1 it doesn't execute i don't know what's happening...whether i want use interrupt...

Echo pin is the output pin from the sensor module which means it is input to your controller. You should not control rather you need to just monitor it. If there is a rising edge in the ECHO pin from the sensor then you need to proceed for the timing calculation.

Trigger pin is input to the sensor module which means it is output from the your controller. You need to control this pin inorder to make the sensor work. You need to make high for starting the operation.
Exactly that is my question how can i monitor the echo pin... while it receive the signal or not...

- - - Updated - - -

Actually,I have connected the Sensor pins to GPIO pin's P4 and P3,

I will make the Trigger pin High which is attached to P4 of launchpad for 10microseconds,then make it low,after that I should see echo pin which P3,which will go high for a certain period of time which depends on the distance it measured and it will be also in microseconds.

The total amount of time period, when the P3 pin stays in high level can be used to calculate the distance.

You either need a capture module or timer module + external interrupt pin for calculating the pulse duration. With just GPIO you may not be able to calculate pulse duration unless you implement a polling + timer module. But it is not a good practice, if your controller has capture module use it.

Hope this helps.


if your application is just to take the distance
(no other job in parralele)
you can simply use pooling mode of the input and count number of cycle machine.

Send trigger pulse of 10µs to arm the measurment

unsigned long BigCounter;
.. arme measurement

while (p3==1)
 Bigcounter ++; 
 // optional delay
 // delay_ms(1);
// calul in mm

you know FOSC ,
one Instruction => 4/Fosc µSec
ie: 8MHz => 0.5µS

In the asm result of compiler
you can count number of cycle for one loop
you can calculate the elapsed time
BifCounter * duration of one loop..

and do a conversion in physical unit
BigCounter * K => distance in mm
You may get into infinite loop condition if any unexpected contact issue happened at the sensor side or wiring. if it isn't a problem for your application go for what paulfjujo has said.

Use inline asm instead of C code for better precision.
Thank you anandpv2009 and paulfjujo, it very help for me...and i have doubt that when i am read p3==1 it reacts nothing...


It is hard to predict the problem.

1. Make sure your controller direction reg is correct. Connect an LED to check trigger pin. Connect gnd/vcc to ensure working of input pins.

2. Check Ultrasonic module wiring and power supply.

Also check code composer studio IO read/write syntax.

After sending the signal to the trigger input
you need to wait a minimum time of 2+200+2=204 µS
before to enter in the loop witch suvey the P3 input (feeback echo)..

:-? some details **broken link removed** (sorry,in French and double sorry for PIC !)

Not open for further replies.

Part and Inventory Search

Welcome to