slight change in sketch means sensor won't let servo run with the +5v connected

Hi hi! I will preface this by saying that I am an artist and don't have a great depth of knowledge with electronics but I am working away at it anyways (what better way to learn?). I have a show coming up where I am using my arduinos and I have them set up with a sketch where a servo runs when my maxsonar EZ sensor is tripped. I have one sketch that I run on most of them and I have modified it slightly for my opening (where the room will be crowded). Basically, I have only changed two variables in my sketch (distance where the sensor will be tripped, from two feet to two inches) and the time between pings from the sonar (from .5 seconds to 1 second) so that they don't run constantly if the room is crowded. Both versions of the sketch upload and have been verified and where it gets weird is when I plug everything together. Using the sketch with the shorter sensor distance, the motor won't run if the sensor is connected to the +5v on my board (I have the adafruit motor shield) but it runs just fine when its only connected to the ground and pin. The initial sketch runs whether its connected to the +5V or not. I don't know enough to know why (other than maybe with the shorter distance it draws less power and the 5v is too much?) so maybe you guys can help! Two questions:

  1. Any ideas as to why this happens?
  2. Do I need to attach my EZ sensor to the +5v on my shield or can I just leave it unconnected (and have it only connected to the ground and analog pin)?

Thanks for any help and I apologize for any wrong language (or if this doesn't make sense).

Without seeing your sketch, it's hard to give advice. However, my suspicion is that 2 inches is too short a range for your ultrasonic sensor to work reliably. Try increasing it.

The specs for the sonar says that it can work from 0 - 255 inches but I will try plugging in a bit longer distance.

If you look at the data sheet or the quick start guide on the Maxbotix website, I think you'll see that the minimum distance is six inches for the EZ although there are other Maxbotix sensors with different ranges.

It's almost always best to change one variable at a time. You'll save tons of debugging time that way.

Hello! This is Tom Bonar from MaxBotix Inc.

@PrinterBird

I see that you are using one of our LV-MaxSonar-EZ sensors in your application, and you are trying to use it to trip an Arduino at a set distance in your sketch. The distance that you mentioned of 2 inches, is not able to be done with our sensors. The LV-MaxSonar-EZ sensors have a minimum reported distance of 6 inches. This means that anything closer than 6 inches is reported as 6 inches. If you change your sketch to trip at 7 or 8 inches, your programming should work. The sensor will provide range data to the detected object from 6 inches to 255 inches.

Please let me know if you have any questions by emailing thomas@maxbotix.com and I will be glad to assist you.

Best regards,

Tom Bonar
Technical Support
of MaxBotix Inc.
Phone: (218) 454-0766
Fax: (218) 454-0768
Email: thomas@maxbotix.com
Web: www.maxbotix.com
Follow us on Facebook at: Redirecting...

Technical support and sales are subject to
the terms and conditions listed on our
website at http://www.maxbotix.com/ MaxBotix,
MaxSonar,EZ0, EZ1, EZ2, EZ3, EZ4, AE0, AE1,
AE2, AE3, AE4, WR1, WRA1, and WRLA1 are
trademarks of MaxBotix Inc.