This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HC-SR04

Other Parts Discussed in Thread: TM4C123GH6PM

How do you interface ultrasonic sensor HC-SR04 with tva c    tm4c123gh6pm?

  • Hello Thero,

    The device is a 5V device and TM4C123 has a 5V tolerant IO's but not 5V drive. So you would require a level shifter between the two when driving the Input Pulse. If you can get the same device in 3.3V variant then it would be better.

    To get the time you would need to use a timer in input edge time mode.

    When you send the start pulse, you will have to start the timer with the output from the HC-SR04 connected to the CCP pin of the timer. When the output goes from low to high the timer will capture the count value, which can be used to measure the distance. Then disable the timer and restart it from count 0 for the next pulse.

    Regards

    Amit

  • Do u have any c code for interfacing HC-SR04 with tm4c.
  • It probably would be a good exercise for you to actually develop the code. It's not that hard but still would be a good challenge.

    You can search for "SRF04", it has the same interface. Also take into consideration Amit's advises. If you have any doubts later developing your welcome to ask and I can give you some guidance