Setting up the software to extract new custom sensor data via MAVLink seems to be harder than it should be.
Step one is to make the quadcopter send off the data.
- First, you need to define a new MAVLink message type using XML in mavlink/message_definitions. You can just make up a new unused integer for the message_id.
- Second, you generate the message pack/unpack functions using the MAVLink generator.
- Then you'll need to add code to ArduCopter/GCS_Mavlink.pde in data_stream_send to build and send off your message. You do need to be a little careful here, because the flight dynamics start to degrade if your sensor reads stop the main loop for more than a few milliseconds, especially for a small quad or flying indoors (that's what the "gcs_out_of_time" business is about). I'd add a new sensor to the STREAM_EXTRA3 trigger.
- Rebuild and upload the new flight firmware.
The other half of the project is on the PC, where you need to modify the ground station software to read your MAVLink packets out of the telemetry stream. I have no clue where you'd begin to do this to Mission Planner, which seems like a really sophisticated piece of software. But luckily it dumps raw radio telemetry to the "tlog", so you might be able to build a completely separate program that looks for your new MAVLink packet from the tlog. (You certainly don't want an Arduino Sketch for this, since a Sketch runs on the Arduino, not the PC.)
If this sounds intimidating to you, you're not alone! For our indoor quad, we ended up building our own radio communication protocol and "ground station", since we couldn't use GPS or waypoints or the other MAVLink features, and dealing with the complexity of MAVLink wasn't worth it to us.