The sketch is simple. The sonar sensor detects the obstacle's distance and a motor is turned on!
This works perfectly fine with the USB cable but not with my 9V external battery. I have also tried a 6V battery to no good effect.
Code:
/* HC-SR04 Ping distance sensor]
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 12 Trig to Arduino pin 13
*/
KhuramAshraf:
The sketch is simple. The sonar sensor detects the obstacle's distance and a motor is turned on!
This works perfectly fine with the USB cable but not with my 9V external battery. I have also tried a 6V battery to no good effect.
The voltage regulator in the Arduino has a voltage drop of about 1.5-2.0V, therefore any external power source you use with it must be at least 6.5V (lower limit), or, to be safe, at lease 7V. That automatically rules out your 6V battery. Forget about it.
Now, in the case of the 9V battery, you must make sure it has enough juice to provide at least 7V. Then make sure you are plugging it to the external power Jack (the 5.5 x 2.1 DC jack).
I'm using an arduino nano. This is what I am doing.
Connecting the positive of my external battery to Vin of the arduino, connecting the negative of my battery to the arduino ground. According to the information avaliable on the internet , this should work fine! but it doesn't..
Why would I need the jack here?
You should tell all details when asking any question.
The Arduino variant you are using is kind of an important detail.
You don't need a jack (and you don't have a jack either).
But as explained, you do need a 9 volt battery at maximum capacity.
If you connect the battery, do you see the blue LED on the bottom light up ?
The regulator is about the only thing that differs between external power and USB power.
USB power is separated from external power by a diode, which will generate a small voltage drop.
This voltage drop is supposed to be large enough to have external power (5 volts)win from USB power (5 volts minus tenths of volts).
Your regulator might be defective.
Ways to destroy it are reverse wiring and over voltage, but there must be more creative ways to destroy it.
Yes, measure your arduinos 5 volt pin while trying to run it on the 9 volt battery. Most likely your motor and sonar sensor require more current demand then your 9 volt battery can supply. Those standard small 9 volt batteries were designed to power smoke alarms and garage door transmitters, not motors.