Comments on: Interfacing HC-SR04 Ultrasonic Sensor with PIC Microcontroller https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/ You Inspire.....We Create..... Sun, 05 Sep 2021 13:29:41 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: APl https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/10032 Sat, 28 Aug 2021 20:33:41 +0000 https://electrosome.com/?p=8423#comment-10032 Very good tutorial an the HC-SR04 – just some remarks:

1) To avoid unexpected behaviour/results always use “volatile” for variables in context with interrupt routines:

volatile unsigned int a;

instead of:

int a; // there are no negative numbers, so use “unsigned int”

2) always add a counter to check how many times there was a timer overflow to get a correct result (even if in this case an overflow may not be expected)

3) for measuring a pulse width you may also use the capture mode of the CCP module of your PIC (if available)

]]>
By: Ligo George https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/9536 Sun, 16 Feb 2020 15:28:07 +0000 https://electrosome.com/?p=8423#comment-9536 In reply to Mario Ibarra.

It is already explained above.
https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#Timer1_Module

]]>
By: Ligo George https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/9535 Sun, 16 Feb 2020 15:26:53 +0000 https://electrosome.com/?p=8423#comment-9535 In reply to rod.

Yes you can add another one. Just read data from each sensors one by one instead of doing simultaneously. When you do it fast, it will appear as simultaneous for us.

]]>
By: Ligo George https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/9534 Sun, 16 Feb 2020 15:25:20 +0000 https://electrosome.com/?p=8423#comment-9534 In reply to Henry Tan.

48 is the ASCII value of character ‘0’. Basically here we are converting an integer to corresponding character.

]]>
By: Ligo George https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/9533 Sun, 16 Feb 2020 15:24:04 +0000 https://electrosome.com/?p=8423#comment-9533 In reply to Jim Vincent Martinez.

It is already explained above. Please read from below section.
https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#Timer1_Module

]]>
By: Dele Ola-Buraimo https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/7379 Sun, 31 Mar 2019 02:48:16 +0000 https://electrosome.com/?p=8423#comment-7379 In reply to Ruchir Tullu.

Yes it does, however you will have to make some subtle changes. For example, instead of simply typing “RBIF”, you will need to type “INTCONbits.RBIF”. There are many place you will need to do this in the code, including doing the same thing with “TMR1ON” which you would frame as “T1CONbits.TMR1ON”. Once you do that you should be fine. If you paste your code I will be able to tell you exactly how to frame it. Otherwise simply search the word following PIC18 and the syntax should come up on some forum.

]]>
By: Ruchir Tullu https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/7258 Fri, 22 Feb 2019 15:45:17 +0000 https://electrosome.com/?p=8423#comment-7258 Hello. Thank you for providing this amazing tutorial, it is indeed very helpful.

Will this program work with the PIC18F4620?

]]>
By: Chishti https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/7208 Tue, 27 Nov 2018 16:13:22 +0000 https://electrosome.com/?p=8423#comment-7208 Will this ultra-sonic sensor work for a tank having depth of 3-5 feet ?

]]>
By: Jim Vincent Martinez https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/7207 Tue, 27 Nov 2018 12:02:34 +0000 https://electrosome.com/?p=8423#comment-7207 Can someone please explain to me how this was derived? d = (TMR1H:TMR1L)/58.82 cm
especially the 58.82 part. I’m using a 20Mhz osci and I need to calculate my own values to use, but I don’t understand how.

]]>
By: Henry Tan https://electrosome.com/hc-sr04-ultrasonic-sensor-pic/#comments/7146 Fri, 03 Aug 2018 18:19:10 +0000 https://electrosome.com/?p=8423#comment-7146 What‘s difference between the simple and using interrupt methods? does the second method will be more accurate and real-time reaction than the first simple loop one? thanks

]]>