Search code examples
arduinobattery

Arduino - Detect external power


I have an external power source (6v) that is connected to a motor and a servo, and on my arduino board I have a couple of LEDs which are powered by the onboard 5v. The external power is connected to a switch so I can turn on the motor and servo (to save battery). My main board just blinks the different LEDs. What I want to happen is that the moment my external power is switched on, the LEDs stop blinking and the code to move the servo and motor is executed. As a result I have a boolean called intro. When it is true, the LED code executes, when it is false the motor and servo code will execute. The only problem I am having is that how can the Arduino know if the external power is switched on so that the boolean can be set to false? Is there a way that the arduino can detect if the external power is on (for example checking the pins of the motor/servo?)?


Solution

  • The general idea is to connect the external power to an I/O pin so you can read its status. You'll also want a pull-down on the I/O pin so that it doesn't float and give random values when power is not connected.

    Don't connect 6V directly to an Arduino I/O pin, it will be far enough above Vcc that the clamp diodes on the pin will activate. A series resistor like 10K to reduce the clamp current will probably be OK but still isn't the best design practice. I'd recommend a 3V3 zener diode clamp such as that on this page:

    http://www.kevinmfodor.com/home/My-Blog/microcontrollerinputprotectiontechniques