Send simple message from additional sensor to pixhawk2


in my project we need to send two kind of sensor data via arduino to PX2 and forward to PC, which is connected with another arduino. And currenctly I have a lot of things that I need to ask about.

One of the sensor’s output will only be 0 or 1, will there be a simplier way to send it than to build a driver for this sensor.

The second one is smoke sensor, I wonder if there will be some kind of faster solutions too for that too?

And what do you think about the current method that need two arduinos?

Thank you for advance!!!

The binary sensor you could attach as a “button” input.
The other sensor you need to tell us more about. What signal does it output?

Thank you for this! Sorry for my poor skill and knowledge in pixhawk and mavlink, I need to confirm with few things:
So this AP_button code can be used to build message via Pixhawk’s serial port connection? I mean by requesting data from sensor <-> arduino <-> PX connection to the arduino connected to ground control?
If it is possible, I assume the Telem1/Telem2 can be set as pins?

And about the second sensor, I am not sure the exact term for the signal name.

no worries. The button library just sends a mavlink message when the pin it is connected to changes state (toggles from high to low or low to high) - for that sensor, you don’t need the arduino, just connect it to an Aux pin on the Pixhawk, and set the button parameters for that pin ( That will get the data to the groundstation, where you can do whatever you need to with it.
The gas sensor you linked has two options: either an analog voltage (link says 0-5V), or a digital pin - which is binary on/off, based on a manually set threshold (trimpot). If you just need a binary result, you could set it up as a button, same as above. If you need to read the analog value, the easiest thing to do is pretend it is RSSI, and follow the guide for analog RSSI ( This will again get your data logged and sent down over mavlink, for you to handle how you need to.

Good to know, thank you for telling me this. When I tried to include the AP_Button, there have shown different warnings related to other h. and cpp. files that the AP_button included, I assume some of them are because I am using Arduino.

Do you know if there is a safe way to “cut” some of the other files?

You don’t need the arduino. Just set the parameters in ardupilot and connect the sensor to your Pixhawk

Oh I see. So this ap_button data can be viewed in ground station (for example mission planner)? But shouldn’t I use the codes from the first link to set the output.

and if I want to send the out put digital data forward, I just need to follow the driver codes that are already in Mission planner?

All the links I’ve posted are for features already built into ardupilot, so you only need to set up the parameters (as linked above)

Perfect. And do you know which one in the mission planner’s user item I need to set so that the button change can display?

Also which of the code drivers (in mavlink/common/mav_data_stream I suppose?) can send the button change data forward.