[SOLVED] Problem Ultrasonic sensor HC-SR04

Hi everyone,

I have a problem with the HC-SR04 sensor...

My configuration : (see attached picture)

  • HC-SR04 connected on nRF24L01 (Sunfounder)
  • Arduino Nano (Sunfounder) connected on nRF24L01
  • 2 battery connected on nRF24L01 (BRC 18650, 4200mAh, 3,7V)
    All components are from the DIY 4-DOF Robot Kit from Sunfounder (except the batterys)

Problem :
In the serial monitor, the sensor return allways 0 cm

Solution tested :

  1. I have tested the sensor with the same sketch on an Arduino Uno and everythings work perfectly.
  2. i have connected trigger/echo on the Arduino Uno and vcc/gnd on Arduino Nano (nRF24L01) and it's works, so is not a power supply problem
  3. i have tried to connect trigger/echo in different pins on nRF24L01 (12, 11, 10, 9, 8, etc.) and the problem persist...
  4. on the nRF24L01 (and Arduino nano) i have connected a servo and everythings works fine, so it's seems the nRF24L01 is apparently fonctionnally...

Here is my code :

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <NewPing.h>

#define TRIGGER_PIN 12

#define ECHO_PIN 11

#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {

Serial.begin(9600);

}

void loop() {

delay(50);

unsigned int uS = sonar.ping();

pinMode(ECHO_PIN,OUTPUT);

digitalWrite(ECHO_PIN,LOW);

pinMode(ECHO_PIN,INPUT);

Serial.print("Ping: ");

Serial.print(uS / US_ROUNDTRIP_CM);

Serial.println("cm");

}

Any ideas ???? I search for one week ans i'm out of solutions...
Thanks.

Yvan

sunfounder_documentation.gif

sunfounder_documentation.gif

That appears to be a multi-layer gif and is as such way too hard to read (my dumb-ass Windows image viewer doesn't seem to get it and I can't be bothered to work on it). Just post it in separate images if you want us to have a look.

Krayon70:
3) i have tried to connect trigger/echo in different pins on nRF24L01 (12, 11, 10, 9, 8, etc.) and the problem persist...

An nRF24L01 is a radio communication part, which can't possibly read an ultrasound sensor. What you write doesn't make sense at all.

The HCSR04 needs a 5V supply.

Mine work great on 3.3v. There are different versions of this sensor out there.

You are using a servo controller and plugging the HC-SR04 into the servo signal pins. Does servo signal pin number "x" connect to nano pin "x"?

"Pin sockets for 12 servos"

wvmarle:
That appears to be a multi-layer gif and is as such way too hard to read (my dumb-ass Windows image viewer doesn't seem to get it and I can't be bothered to work on it). Just post it in separate images if you want us to have a look.

i have posted in jpg format... Hope it's ok :wink:

wvmarle:
An nRF24L01 is a radio communication part, which can't possibly read an ultrasound sensor. What you write doesn't make sense at all.

Yes, i know but in the Sunfounder DIY Robot documentation, they say to connect the ultrasonic module in the servo control board (see picture below)... Strange... :o

sunfounder_documentation.gif

sunfounder_documentation.gif

groundFungus:
The HCSR04 needs a 5V supply.

I have checked with 5V and the problem persist...
The question is... Can i connect an ultrasonic module in a servo control board ?????
Sunfounder documentation say thats the way to do... but now i have a doubt !!!

DaveEvans:
Does servo signal pin number "x" connect to nano pin "x"?

Yes, it seems i have connected the nano correctly to the servo control board... Isn't ?? (see picture below)

One thing to check: are the Arduino pins directly connected to those output pins? If so, you should be able to connect stuff there just as if you connect it directly to the Arduino.

It's simple to check. Upload Blink, set it to one of those pins, and see what voltage you get there. You should see the voltage switch between Vcc and 0V on your multimeter. Or set the multimeter to resistance and see if they're connected with zero resistance.

Also suggest you measure the voltage across the servo vcc and gnd pins

wvmarle:
One thing to check: are the Arduino pins directly connected to those output pins? If so, you should be able to connect stuff there just as if you connect it directly to the Arduino.

It's simple to check. Upload Blink, set it to one of those pins, and see what voltage you get there. You should see the voltage switch between Vcc and 0V on your multimeter. Or set the multimeter to resistance and see if they're connected with zero resistance.

Hi,

Thanks for hints... It's a good idea to check with a multimeter...
So, i've uploaded a simple sketch to my arduino (plugged on my servo control board, see picture below)

Here is the sketch :

void setup() {
  pinMode(12, OUTPUT);
}
void loop() {
  digitalWrite(12, HIGH);
}

So i've checked the voltage between pin12 (named "signal" on servo control bord) and GND... => 0V !!!!!!

After i've checked directly on the "pin" on the nano and GND => 4.77V

So, apparently, isn't possible to connect the ultrasonic sensor on the servo control board (nRF24L01).
I don't understand because this is the method that Sunfounder documentation describes !?!? (see the second picture below)

tension.png
sunfounder_documentation.gif

tension.png

sunfounder_documentation.gif

I have contacted the Sunfounder support. After 2 weeks, and a new email, finally the Sunfounder support send me an answer...
It seems that my email was marked as "spam"...

They told me that they were going to find a solution to my problem...

If you look at the back of the Sunfounder board, you should be able to see that some Nano pins are reserved for the radio (including pin 12) and you should be able to figure out which servo signal pin number is connected to which nano pin....

And, clearly, servo signal pin number "x" does NOT necessarily connect to nano pin "x" (see post #4)!

418FWCqRwcL.jpg

PS: this is not a "gotcha" that I was holding onto...I found this image recently.

418FWCqRwcL.jpg

DaveEvans:
If you look at the back of the Sunfounder board, you should be able to see that some Nano pins are reserved for the radio (including pin 12) and you should be able to figure out which servo signal pin number is connected to which nano pin....

And, clearly, servo signal pin number "x" does NOT necessarily connect to nano pin "x" (see post #4)!

418FWCqRwcL.jpg

PS: this is not a "gotcha" that I was holding onto...I found this image recently.

YESSSSSSSSSSSSSSSSSSSSSSSSSS ! :))))

It's works !!!
Thanks...

You right, the numbers of servo control board's pins does not match with the numbers of the arduino nano board's pins when the both boards are connected ! :frowning:

Like you suggest, I watched at the back of the board and i realize that pin 1 and 2 of the servo board match with pin 2 and 3 of the nano board...

I never thought about that... So I modified my sketch and everything is working, FINALLY !

I also found that it took the 3,7v external power supply ; the sensor work with 5V or 3.3V but the servo control board is not powered by arduino nano but only from the power supply (that is directly connected on the servo control board).

Thanks a lot at all for the solution ! Unity is strength ! :wink:

Regards.

Yvan