How can I properly power my circuit without the USB?

Hello,

This is my first post. Hopefully, it meets the standards enough to receive some kind of input. Any help at this point would be amazing. I'm trying to be able to run this on some type of portable power that can fit into my Iron Man helmet.
I am using an Elegoo Nano V3.0, I'm running an MG995 Servo with 2 LED eyes that originally came with a 3V coin battery. Also rather than a push-button switch, I would like to have it activate by using a reed switch so that I can have a hidden button through the helmet. Ideally, I would like it to start out closed with the eyes on, when switched on. and Once I pass the magnet in my glove over the reed switch, I would like it to open up 120 degrees and have the eyes turn off. Pass over the same reed switch, and have it reverse the operation.
When plugged in, the process works. But when I try to unplug and run only on a 9V, the face plate opens and closes immediately. I'm having trouble seeing what causes this. Do I need a different power source? Do I add to the circuit to make it more compatible? Any suggestions would be great.

Here's my code:

const int servoPin = 3; //Servo attached to pin D3
const int buttonPin = 2; //Button in between GND and Pin D2
const int LEDPin = 4; //Eyes attached to pin D4

#include <Servo.h>

Servo visorServo;

void setup() {
  visorServo.write(0);  // Initial position
  visorServo.attach(servoPin);

  pinMode(buttonPin, INPUT_PULLUP);  // LOW when pushed.

  pinMode(LEDPin, OUTPUT);
  digitalWrite(LEDPin, HIGH);  // LED on
}

void loop() {
  static unsigned long lastPushedTime = 0;
  static boolean visorClosed = true;
  static boolean lastButtonState = HIGH;

  boolean newButtonState = digitalRead(buttonPin);

  if (newButtonState == LOW && lastButtonState == HIGH && millis() - lastPushedTime > 100) {
    lastPushedTime = millis();
    if (visorClosed) {
      visorServo.write(120); // Open visor
      visorClosed = false;
      digitalWrite(LEDPin, LOW); // Turn off light
      delay(1000);
    }
    else if (!visorClosed) {  // Visor is open
      visorServo.write(0); // Close visor
      visorClosed = true;
      delay(500);
      digitalWrite(LEDPin, HIGH); // Turn on light
    }
  }
  lastButtonState = newButtonState;
}

Hopefully, I gave enough information to you all.

Screen Shot 2020-12-17 at 10.56.09 PM.png

Screen Shot 2020-12-17 at 10.56.09 PM.png

Hi jvalerio,

Karma++ for posting code as a codesection and a schematic.
If this 9V battery is that type like used in smoke-detectors it is likely that the inner resistance of this battery is too high
for proper operation of the arduino.

a MG995-servo can easily pull 1A of current which is way to much for the onboard-voltage regulator.
You should supply the servo from a second powersupply. The GND of the powersupply for the servo and the powersupply of the Arduino must be connected.

best regards Stefan

That's a good first post, schematic and properly posted code and a clear question.

The battery in your schematic is connected the wrong way round, the long side is positive.

If by 9V battery you mean the block batteries often used in smoke alarms then they are puny and not good for powering anything much, other than smoke alarms.

Maybe 4 x AA batteries in series for the servo might be OK.

hello,
leds are wrong connected (inverse polarity) , they cannot light up
also, it is not advisable to be in parallel, because if they are not exactly the same characteristics, may be, only one light up

StefanL38:
Hi jvalerio,

Karma++ for posting code as a codesection and a schematic.
If this 9V battery is that type like used in smoke-detectors it is likely that the inner resistance of this battery is too high
for proper operation of the arduino.

a MG995-servo can easily pull 1A of current which is way to much for the onboard-voltage regulator.
You should supply the servo from a second powersupply. The GND of the powersupply for the servo and the powersupply of the Arduino must be connected.

best regards Stefan

Thanks for the input!

So it seems like i would need a power source that's between 4.8V-7.2V for the servo alone, and then another power source for the Nano itself?

I'll try the 4 x AA pack as suggested by PerryBebbington, change the 9V to a different battery and pray I can fit it all in my helmet.

Thank you all. I'll post again after I've tried this out.

You can also use a 2s LiPo/LiFe battery and a 3A BEC. Plenty of amperage and a solid 5-6v out of the BEC. Lots of battery sizes to choose from. The BEC will easily handle a servo and Arduino.

You will need a LiPo/LiFe charger.

Very cool! I figured there was a lot more batteries out there than I knew of. So I would buy from 2 out of the 3 links you posted? I noticed the LiPo/LiFe chargers have more than just two wires coming out of them. How would that get connected?

jvalerio:
Very cool! I figured there was a lot more batteries out there than I knew of. So I would buy from 2 out of the 3 links you posted? I noticed the LiPo/LiFe chargers have more than just two wires coming out of them. How would that get connected?

Yes, you would buy a BEC and a battery. The BEC can handle a 2s-6s battery. S=cell. Each cell is 3.7v. This BEC you can choose either 5v or 6v output.

For Arduino and servo power you only need a 2s battery. The more mah the longer the battery lasts, but also the more amps it can crank out.

If you are drawing 1.5A continuous and want it last an hour you would need a 1500mah battery. You also do NOT want to run lipos/lifes down to nothing. It can damage the battery.

Depending how long you want it to last determines the size you would buy. a 500mah 2s battery would last for 2 hours with a 250mah drain. They can also handle large amperage. I think one of the batteries I listed can give you continuous 20c. 1 C = mah rating of battery. So a 500mah lipo rated at 20c can give you 10A.

You are probably better off with a life battery as they are safer than lipo's, but charge the same way.

There are many places to buy BEC's and lipo/life batteries. They are used for RC vehicles. I have been flying RC planes for 30 years.

When you have more than 1 cell you balance charge them with the balance connector and with the +/- connector.

fit it all in my helmet.

Be aware that lithium batteries can produce very high and dangerous currents resulting in the batteries catching fire or the wiring catching fire or both. If you are going to wear this thing you need to consider this. At the very least there should be a fuse located a close as physically possible the battery. If there are 2 batteries in series I'd put the fuse in the connection that links them.