Give your Arducopter Mega (and APM) a voice!

I have been playing with my Arducopter for a while now. Really cool stuff! It's time for a little contribution myself.

But first a really a big thank you to everybody working on this project and especially Jason for all the cool (and very stable) code he has been contributing!

I had hooked up the Battery Monitoring as described in the WIKI. Works like a charm, however beyond a message in the GCS it was hard to notice when the Voltage (or current, if that is hooked up) reached a critical level.

RTL sounds great, but in most cases it'll be good to get an audible signal when the batteries run low. In fact, I killed one LiPO just having my copter sitting on the desk and forgetting to disconnect the battery. The ACM draws quite a bit of current and low-discharged the LiPO... 20 more bucks down the drain.

So I had a look around in my electronic shop and found a little Piezo buzzer. It runs on 3-6V and only draws about 30mA which is not too much to be driven straight from one of the ACM port pins. It's a YMD1205. It only costs 30 cents - much cheaper than a new LiPO :)

After looking at the schematics of the IMU a usable port was quickly found. The IMU has two "Expansion Ports". As I did not plan to use either for other stuff, they are perfect as the buzzer fits neatly between one of the "gnd" pins and the hole marked "AN6". It looks like it actually belongs there, doesn't it :)













Code was written very quickly as well in case you would like to integrate that into your project.

I wanted it to be configurable via the APM_Config.h file. Also I integrated a quickly audible beep on start-up to know if the Piezo Buzzer is working.

I tested the whole thing and it works like a charm. The nice side effect is, that the buzzer can be used from anywhere in the code for other audible signals via the piezo_on() and piezo_off() functions.

Let's see maybe I can get it to play a song before it takes off :)



// Enables the Piezo buzzer code
#define PIEZO                                         ENABLED
// Required if PIEZO is "ENABLED"
#define PIEZO_PIN                                 AN6
// Optional to enable low Voltage alarm
#define PIEZO_LOW_VOLTAGE             ENABLED

system.pde:void init_ardupilot():

        #if PIEZO == 1

    #if BATTERY_EVENT == 1
        if ( (battery_voltage < LOW_VOLTAGE) || (g.battery_monitoring == 4 && current_total > g.pack_capacity) ) {
                        #if PIEZO_LOW_VOLTAGE == 1
                        // Only Activate if a battery is connected to avoid alarm on USB only
                        if (battery_voltage1 > 1){
                        else {
                else {
                        #if PIEZO_LOW_VOLTAGE == 1

#if PIEZO == 1
void piezo_on()

void piezo_off()

void piezo_beep()
        // Note: This command should not be used in time sensitive loops


Only one small annoyance. It does beep if the ACM is powered by USB cable only. I am wondering if there is a way to detect the presence of the USB cable plugged in, in code, which would allow me to disable the buzzer in that condition. Any hints would be appreciated.

Have fun !





Views: 2101

Comment by Vincent Mees on May 24, 2011 at 4:33am


looks like a nice feature. I have to try it sometime. At the moment I'm using an external battery monitor with voltage indication and buzzer.


Something off topic.

Don't worry about your Lipo, it isen't dead. Just plug it in the charger and load the NiMh program and charge with about 10mA until you reach about 10V again. Then swith your charger program to LiPo. your battery will be as good as new.

Comment by I.S. on May 24, 2011 at 5:49am

Congrats on your implementation. Looks very functional.


However, I am abit worried about mounting the piezo directly on the PCB, because of the noise it can generate.

At least, MK strongly suggest to put the buzzer several inches away from the FlighCtrl.

Comment by Oliver on May 24, 2011 at 6:58am

Vincent, thanks for the tip with the battery. I'll give it a shot.


I.S. Also thanks for the notice. I'll monitor it and see if it generates any issues. Either way as long as its off there definitely should not be any issues. Do you have a link so I can read up on it ?

Comment by Mark Colwell on May 24, 2011 at 7:15am

When re-charging over discharged Lipo or Lion cells with NiMh mode,

Watch as voltage climbs to over 3v per cell or when voltage stops increasing and quickly switch to Lipo mode, then complete full charge.

Or if below 3v stop charging, wait a few second and start again, charge until voltage is 3v per cell.

If your charger can "Balance Charge" use that vs full charge mode,  Do NOT use fast charge mode, You can increase battery life by storing them in refrigerator at nominal charge level. 11.2v 3s,  7.2v for 2s,

Always monitor charge activities to ensure that a fire does not start, I charge in a ceramic crock pot just in case.

I had large ThunderPower  4350 mAh 5 cell pack over charge by a Astro 109 (prior to latest firmware update) Charge voltage jumped to 6 cell mode, All cells were puffed,  I heard a loud pop as first cell vented, I went to charger found battery was about to explode, took it outside where it caught fire in 30 second and burned with a 3 foot flame, very scary day...

Comment by Sebastian Gralla on May 24, 2011 at 11:52am

"I am wondering if there is a way to detect the presence of the USB cable plugged in, in code, which would allow me to disable the buzzer in that condition. Any hints would be appreciated."

not directly, but you can check the voltage reading when only usb is plugged in, and check if it reads something like this


btw look at jose julio's tiny indoor quad, it has a buzzer and exactly these features in code which you are searching for ;)


and REMOVE the delay function. it will crash your quad, doesn't matter when it's called, it corrupts your data even when it's not flying


@I.S.: and it generates a magnetic field -> your magneto wouldn't work

Comment by I.S. on May 24, 2011 at 1:19pm

Sorry, I can't remember/find where I read such a thing.

However, note that a buzzer and a piezo may not be the same thing.

Comment by Oliver on May 24, 2011 at 6:49pm

@Mark: Geez, now i feel like spending the 20 Bucks again given that an exploding LiPO would be quite a show in my street :)


@Sebastian: Good idea, there should be a difference with the Voltage given that the Reference is different between ESC Power and USB Power. Thanks also for the hint on the delay. Was not sure if its a good idea, which you just confirmed. Will remove it or just call it in the init() function on startup when the control loops are not running yet. I did not notice any Magneto interference, but better safe than sorry... Will move it away to one of the Motor Mounts and connect it to AN5 on the backwards expansion connector next to the Voltage dividers.

Comment by Russell B. Sutton on May 25, 2011 at 4:11am

Hey Oliver , great idea!, very useful.  I Haven' t had the chance to fly might quad with AC2 yet and was wondering about how the on board voltage monitor let the pilot know when the battery was dead.  LOL thanks for clearing that up for me.  In the last couple days I have been working with a RGB_LED to help bring my quad to life.  I want to use a RGB_LED on my quad as a beacon  that will allow the quad  to relay information to the pilot through color and patterens.  

Comment by u4eake on September 26, 2011 at 4:01pm

Very nice contribution ! Thanks !

It's good to see people being creative with APM :-)

Comment by Jack on October 6, 2011 at 9:37am


I tried this mod compiled the code and all I get from the buzzer is clicking when arming and disarming. The buzzer is being activated but just a slight click not a buzz. I tried a couple of different Piezos to make sure it wasnt a bad unit but with the same results. Any suggestions




You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service