Sunday 4 October 2015

PiAware - Aircraft Overhead Indicator LED

I've been using the PiAware software to track aircraft flying near me and I liked the idea of turning an LED on when a plane was overhead (or at least near by!).

The first step was creating a way of reading data from PiAware using Python 3, so I created a module called

Once I had the data it was simply a case of looping through each of the aircraft signals found, calculating the distance between my gps co-ordinates and the gps position of the aircraft. If the distance was less than 10km I turned the led on!

I 'reused' the code to calculate the distance between 2 GPS co-ords from codecodex.

Setting up

You'll need PiAware installed on your Raspberry Pi, up and running and tracking aircraft.

You'll need an LED, appropriate resistor, breadboard and a couple of Male/Female jumper cables to connect it togther.

The LED is connected to ground and pin 17 with the resistor in between.

cd ~
git clone
Launch the flightlight program passing the latitude (lat) and longitude (lon) of your PiAware station (use to find your gps location) and the range that should be used to detect if an aircraft is overhead.
usage: [-h] lat lon range
e.g. using GPS coords of 52.4539, -1.7481 (Birmingham, UK Airport) with a range of 10km
cd ~/flightlight/flightlight
sudo python3 52.4539 -1.7481 10
import RPi.GPIO as GPIO
import argparse

from flightdata import FlightData
from haversine import points2distance
from time import sleep

#pin of the LED to light

class LED():
    def __init__(self, ledPin):
        self.ledPin = ledPin
        GPIO.setup(ledPin, GPIO.OUT)

    def on(self):
        GPIO.output(self.ledPin, True)

    def off(self):
        GPIO.output(self.ledPin, False)

#read command line options
parser = argparse.ArgumentParser(description="PiAware Flight Light")
parser.add_argument("lat", type=float, help="The latitude of the receiver")
parser.add_argument("lon", type=float, help="The longitude of the receiver")
parser.add_argument("range", type=int, help="The range in km for how close an aircraft should be to turn on the led")
args = parser.parse_args()

#get the flight data
myflights = FlightData()

#set GPIO mode


    #create LED
    led = LED(LEDPIN)

    #loop forever
    while True:
        plane_in_range = False

        #loop through the aircraft and see if one is in range
        for aircraft in myflights.aircraft:
            if aircraft.validposition == 1:
                startpos = ((, 0, 0), (args.lon, 0, 0))
                endpos = ((, 0, 0), (aircraft.lon, 0, 0))
                distance = points2distance(startpos, endpos)
                if distance <= args.range:
                    plane_in_range = True

        #turn the led on / off
        if plane_in_range:

        #refresh the data

    #tidy up GPIO


  1. This comment has been removed by the author.

  2. Even though exists, I get lots of errors when I run:
    Any idea's?

    1. Hi Teddy,

      Im a bit confused - there isnt a file in this project called ""?

      What errors do you get when you try and run


    2. When the code is run, I get a whole list of:
      /usr/lib/python3.2/urllib/ errors.


Note: only a member of this blog may post a comment.