when plugged into the computer the arduino mega 2560 does exactly what i tells it to how ever when plugged into power supply it does not get correct ultrasonic sensor readings and starts only doing the if statement. do i need more power?
Post the code using code tags in future.
In this case the code has absoloutly nothing to do with your problem.
You have a hardware problem probbly caused by the lack of a common ground.
No you fix the grounding problem.
You have hardly given us anything to work on.
Concentration the differences between the external power and USB power.
Tell us what your set up is, and what the rating of your power supply is and how you have connected it up.
i have a autonomous robot with 1 ping sensor and 2 7.2 rc batteries at 2400mah and a fuse for the arduino with a power supply also going to the adafruit motor shield and 2 dc motors i cut a usb cable open to power the arduino mega that is coonected to the fuse to one of the batteries
the shield is an adafruit motor shield that is all i have and the arduino mega and two dc motors on motor 1 and 2 with battery connected to motor shield
Hi, its time for a circuit diagram please, the main question is, are all the negative terminals of the power supplies and arduino connected together.
But a circuit diagram will be of great assistance.
Tom.