Let's say you want to control FlightGear's throttle with Arduino. You need a sensor that can measure variable values within a certain range. A slide potentiometer would be usefull for that. We'll start with that now. It's cheap and easy to handle.
There are lots of more complex and less cheap sensors out there in the market. We'll investigate them later on.
Find a slide potentiometer, maybe a 10KOhm one (higher values will be good too if you're not looking for top performances and high precision), a few cables and connect it to Arduino like that:
We're going to mimic the "Analog Read Serial" tutorial since that's all we need. Read the details here: http://arduino.cc/en/Tutorial/AnalogReadSerial
That's basically a voltage divider, the potentiometer splits the 5V in two. The middle pin senses a voltage proportional to the wiper position.
Arduino translates this voltage into a digital value with its internal ADC (Analog to Digial Converter) returning to the programmer a value between 0 and 1023 (Arduino's ADC has a 10bit resolution).
We're going to use this measured value to control FlightGear's throttle position.
How do we change the throttle position in FlightGear? Simply by changing its attribute in the property tree. Let's see how.
Start up FlightGear without worrying about any serial connection right now. Choose a simple aircraft like the C172 which has only one engine.
From the Main Menu on top choose Debug -> Browse Internal Properties. A window will open up, that's a browser that lets you inspect (and update) FlightGear's property tree.
Dive into the /controls/engines/engine
node, you'll finally see the throttle
node, it's zero when you start FlightGear, and it can be increase up to 1.
Notice it's a "double" (consider that like a "float" value as of now).
This is a "normalized" property, i.e. its values are in the 0..1 range. You'll see many properties are normalized inside FlightGear. To any normalized property, 0 and 1 are its extreme values; 0 generally meaning min/empty/start and 1 generally meaning max/full/end.
All we need to do now is to make Arduino send a normalized value over the serial line, make Flightgear read it and assign it to /controls/engines/engine/throttle
property.
....
....
As usual, very basic stuff. Copy this code inside the Arduino IDE; compile it and upload it to your Arduino board.
The sketch is reading Arduino's pin A0 analog input and sending the value over the serial line.
Open up the Serial Monitor and check what happens while moving the slider in opposite directions.
...
...
...
...