Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com 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.

Arduino NewPing Problem

Status
Not open for further replies.

pic.programmer

Advanced Member level 3
Joined
Aug 19, 2015
Messages
773
Helped
141
Reputation
284
Reaction score
140
Trophy points
43
Activity points
7,531
I am using Ultrasonics sensor HC-SR04 with Arduino (UNO, Nano, Mega2560) and the NewPing v1.7 Library is only working with Mega2560. For UNO and Nano it is giving 0cm all the time. What is the problem ? I am using Genuine Arduino Boards, I have tested with 4 Ultrasonic Sensors and 2 UNO and 3 Nano boards but all I get is 0cm. If I test it with Mega2560 then it gives correct values.

Can somebody provide the old versions of the NewPing library ?

I had used NewPing library some 2 years back with US-020 Sensor and I was getting exact 700 cm values.

All I can say is Sketch doesn't have problem because it is working fine with Mega2560. Is it a bug of NewPing v1.7 Library ?

Edit:

It worked with UNO R3 and Mega2560 but not working with Nano v3.0.
 

Attachments

  • distanceMeasurement.rar
    630 bytes · Views: 44
Last edited:

Did you check carefully the pins and their correspondence with the (device that works) pins?
 

Yes, I have checked the pins correctly and also I changes three set of wires for Nano testing. Nano is working fine. It is printing 0cm but distance is not reading. I have tried with 4 Nano's and 3 iTead Nano Shield and the same problem exists. I think it is a bug of NewPing v1.7 Library. I don't have the older versions of the library for testing.

Earlier when I used NewPing library 2 years back with US--020 sensor it was giving 700 cm max but now with NewPing v1.7 library it is giving only 240 cm.
 

Did you try with the sample program with your sensor? If yes, then try to fiddle with the paramters. Is the arduino going other tasks simultaneously? Can you print out the times (ms) within the loop? Did you also try the arduino forums? You also have reduced the baud rate and you need to play with the delays..
 
Last edited:

I tried the example NewPing Sketch also but changed the baudrate to 9600 bps. It is printing 0cm continuously. I told that the same sketch works fine with UNO and Mega2560.
 

I am not so sure but the timings might have been hard coded in the library with the baud rate. Why did you reduce the baud rate? If you reduce the baud rate by a factor of 12, each ping sequence will take 12 times longer to get out and receive. Keep the 115200 as the baud rate and try again. I do not have the newping lib but it is not a big deal, you too can figure it out by reading the code...
 

It has nothing to do with baudrate. I told I am using same sketch with Nano, UNO and Mega2560. Baudrate is only used for UART. It doesn't affect Ultrasonic Sensor code.
 

is there any supply voltage difference applied to the ultrasonic sensor(+V) among the three kits?
 

@srizbf

No, I am powering all the Arduinos with 5V from USB and also powering Ultrasonic module with 5V. All connections are correct and also all voltages. I think it is a bug of NewPing library or Arduino IDE because I tested both in hardware and also Proteus and I only get 0cm when using Nano.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top