Picture of Flight Simulator with Arduino and Python
Control the Flight Simulator option of Google Earth using an Arduino and Accelerometer.

Fly virtually around the world; tilting the Accelerometer forward, back, left and right to control the Plane's Pitching and Banking.

* Learn how to send Serial data from Arduino to Python
* Learn how to manipulate strings and lists in Python to read and interpret the data sent from Arduino
* Learn how to use the pywin library for Python to control Windows functions such as Mouse and Keyboard

We use Python as the interface between Arduino and Google Earth. In my Arduino / Raspberry Pi Internet Radio Instructable ( we used nanpy on both Python and Arduino so that Python could issue commands to Arduino and read responses. Life would be boring if we always did stuff the same way, so in this project Arduino talks over Serial USB to Python by use of the pyserial library for Python.

If you don't have Google Earth on your PC download it from here:

BTW, you if you don't want to agree to Google Chrome becoming your Default Browser UNCHECK the box at the License Agreement stage.

Remove these adsRemove these ads by Signing Up

Step 1: You will Need

Picture of You will Need
You will need:

* A Windows PC
* Google Earth installed on the PC
* Python 3.2 installed on the PC
* An Arduino Uno
* An Accelerometer (e.g. )
* A prototyping system or breadboard to wire the Accelerometer to the Arduino (e.g.
* A small push switch

akellyirl (author) 2 years ago
I've had some questions on how to add more buttons.

Here's what you need to do:

Add them on the board and wire them up, as with the one in the project. Connect them to some digital pins e.g. 7,8,9.

See where swpin and swState are used in the Arduino code?

Duplicate those lines and edit to represent a new pin/state e.g.
int  swpin1 = 7;
swState1 = digitalRead(swpin1);  

pinMode(swpin1, INPUT);
digitalWrite(swpin1, HIGH);


Send that as a Serial.print(swState1, DEC); to Python.

In Python; again make a new switch state e.g.: swState1 = int(data[4]) etc....
And duplicate and edit this section so it executes if swState1 is TRUE;
win32api.keybd_event(0x20, 0,0,0)
win32api.keybd_event(0x20,0 ,win32con.KEYEVENTF_KEYUP ,0)

That code section above specifies which key should be pressed and then released (0x20 = 32 decimal = SPACE in ASCII). If you want to activate other keys stick there ASCII Hex code in there instead.

Good luck with it.

Traceback (most recent call last):

File "C:\Users\sai kiran\Desktop\", line 2, in <module>

import serial

ImportError: No module named serial

Can u please tell me why this error is occuring ?

it will help my main project.....

riddalion1 year ago
can tweak this to android smartphone?
akellyirl (author) 2 years ago
Added automatic detection of the COM port.
akhandal692 years ago
Amazing,I will try this soon.
btw,is windows necessary ? I have ubuntu 12.10 and windows as well,but can't this be used in ubuntu ?
As Arduino IDE,google earth,python are all available for ubuntu and so it should work.
akellyirl (author)  akhandal692 years ago
Thanks. It should work with ububtu if you have a python api for that. I specified windows because I used the win32 api which is obviously Windows specific.

Good luck with it.
UOS2 years ago
I am trying to learn python now (I know, I am a a little late!), and after have a little insight in python in this, I will definitely try this! Thanks :)
akellyirl (author)  UOS2 years ago
I was a late starter myself with Python. Although very familiar with programming, I was looking for an all-round programming language and I think I found it with Python. I'd recommend trying out the commands you're trying to use in the IDLE command line. Errors show up immediately and you can find the correct constructs for what you're trying to achieve. I always keep : "Programming Python" O'Reilly , near by. Good Luck.