Notifications
Clear all

HC-SR04 Ultrasonic sensor sketch on Arduino Nano v3.0 Failing

4 Posts
3 Users
0 Likes
853 Views
 Dano
(@dano)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

I’ve hooked up the HC-SR04 on my Arduino Nano v3.0 (ATmega328P) using the tutorial video and sketches. The basic demo works perfectly as shown in the video. The other sketches using the “NewPing” library do not work for me. The result is always a result of “Out of Range”, that is a reading of “zero” from the device. The sketch with “NewPing” compiles and uploads OK.

incidentally, for this particular Arduino Nano, I did have to choose the “Use Old Bootloader” option in the IDE for the upload to work at all. I am using the same hookup as the video and downloaded sketches provided.

My environment is Raspberry Pi 4 with Raspberry OS Buster and Arduino IDE 1.8.13.

Any suggestions as to what might be the problem?


   
Quote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@dano

Posted by: @dano

I’ve hooked up the HC-SR04 on my Arduino Nano v3.0 (ATmega328P) using the tutorial video and sketches. The basic demo works perfectly as shown in the video. The other sketches using the “NewPing” library do not work for me. The result is always a result of “Out of Range”, that is a reading of “zero” from the device. The sketch with “NewPing” compiles and uploads OK.

It's hard to say, given that you state the basic demo works.

What exactly are these other sketches doing differently?


   
ReplyQuote
(@magicchristian)
Member
Joined: 3 years ago
Posts: 10
 

1. The old bootloader on Nano  should not make a difference; I used both bootloader and if the downloading closes with success you can be shure it worked well.

2.  There are 2 ways to control the SR04:  one to start a measuring cycle with the trigger input and to measure the time until the edge on the output.   The other possibility is to use the same pin for triggering and the signal when reflection was recognized.  In this case you have a different wiring and you have to switch the connected pin on Arduino from output to input!

can we find the "New ping" library somewhere to look at?


   
ReplyQuote
 Dano
(@dano)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

@frogandtoad

the NewPing library makes new methods available to the sketch which Bill demonstrated in his examples such as “sonar.ping_cm()”. I just used his example sketch as is.

I can get the NewPing sketch to work if I use an Arduino Uno as was used in the demonstration video. I want to use the Nano instead for cost and size reasons so I would like to get it to work the same.

I will try your suggestion for using one pin for trigger and response as was also a demonstrated case in the tutorial video.

Thanks.


   
ReplyQuote