Hi! I was doing a project for my electronics course, and this was my reference (How To Make An Automatic Object Sensing Smart Dustbin - DIY Project - YouTube). The codes work perfectly whenever it's directly connected to my computer with Arduino open, and the codes were just freshly uploaded. However, it won't work when I plugged in my battery. Did I miss something about this? Can somebody help me?
You certainly did miss something , a circuit diagram , battery type , and your code .
What is "my battery"? A 9 volt rectangular PP3?
Please post schematics.
The link shows a tiny 9v battery - almost certainly the issue , along with powering servos from the Arduino ….
There should be a macro on this site to deal with any post that mentions it !!!!
the battery i'm using is a 9V. there is no schematic diagram provided by the source, but the short video was clear enough.
sorry if i sound dumb. i'm a mechanical engineering student so electronics isn't really my forte. i would appreciate it if you talk with a language beginners could understand. T___T
i also want to add that the light on my arduino board lights up when the battery is connected, but it just doesn't work as programmed
You need to change the power source to something that has more capacity , such as 5v power pack connecting straight to the 5v pin on the Arduino
You shouldn’t really drive a servo direct from the board either - problem with a lot of you tube videos/indistructables / Fritzing diagrams .
A 9v battery , as shown, is just not suitable
Being outdoors flying the drone, only the cell phone was available and no Wifi. Watching video was not on the menue...
If you are using a 9V battery like this.

Expect short run times and many issues involving low power.
The chemistry of a 9Vbatt is such that as the current draw increases the Internal Resistance of the battery increases. Which tends to limit the amount of current the 9Vbatt will supply.
A 9V batt Ah rating is optimistically 500mA and typically 300mAh. mAh is milli amps per hour. Which means a 9Vbat can supply 300mA for one hour. A very cheap servo wants about 800mA or more. A 300mAh 9Vbat supplying 800mA will not last very long.
You should look into a new power source for your project or change your project to operate on a 9Vbatt.
yes, that's what i'm using. i'll find another battery for this just as your suggestion. i have a follow up question, though.
-
i am only using this for demo purposes only—for a powerpoint presentation only. will a 9V battery still won't work?
-
can i use a powerbank as a replacement or will that be too complicated?
thank you for your response.
Does a 9V battery currently work?
https://www.circuitbasics.com/how-to-choose-the-right-battery-to-power-up-your-arduino/
I agree with everyone else here that your battery is insufficient. However, if you want to get it to work with minimal changes, try connecting several 9V batteries together in parallel.
So, if you have a 9V battery clip that you soldered to your Arduino board, and the 9V battery clip has a red wire and a black wire, try getting several 9V battery clips, solder all the red wires together then solder all the black wires together. Now connect the group of red wires to your VIN pin and connect the black wire group to the GND pin. Finally, plug in a 9V battery to each of the clips. Now you should have sufficient power, for a little while at least. I would suggest something like 4 or more batteries all wired together in parallel. Hope this helps!
are examples of good batteries that will supply your project. Those batteries are rated to supply power to motors.
You'll want to pay attention to the C rating of the batteries you want to use with those motors. If the battery does not have a C rating then assume 1C or .5C. I charge Li's without a listed C rating at .5C for safety.
The C rating is, basically, the safe discharge rate of the battery before it starts to overheat. I only charge those high C rated batteries at 1C.
In your original post, are you saying that it works when running from the PC's USB port, but stops when running from a 9V and no USB? If so, could the code be locking up because the virtual serial port, which is sent over USB, is locking up due to no USB connection? Does the code use Serial.begin, or maybe while (!Serial); anywhere?
So draw one.
ultrasonic_led.ino [sic]
//define Pins
int led = 13;
int trigPin = 9;
int echoPin = 8;
// defines variables
long duration;
int distance;
void setup()
{
//Sets the Led as an Output
pinMode(led, OUTPUT);
// Sets the trigPin as an Output
pinMode(trigPin, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin, INPUT);
// Starts the serial communication
Serial.begin(9600);
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
if ( distance <= 14 ) // Change Distance according to Ultrasonic Sensor Placement
{
digitalWrite (led, HIGH );
delay (5000);
}
else
{
digitalWrite (led, LOW );
}
}
ultrasonic_servo.ino [sic]
//define Pins
#include <Servo.h>
Servo servo;
int trigPin = 9;
int echoPin = 8;
// defines variables
long duration;
int distance;
void setup()
{
servo.attach(7);
servo.write(0);
delay(2000);
// Sets the trigPin as an Output
pinMode(trigPin, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin, INPUT);
// Starts the serial communication
Serial.begin(9600);
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
if ( distance <= 25 ) // Change Distance according to Ultrasonic Sensor Placement
{
servo.write(0);
delay(3000);
}
else
{
servo.write(90);
}
}
yoko nga nanto pakasungit
@coldpansit please write your posts in English.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.