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!).
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.
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.
git clone https://github.com/martinohanlon/flightlight
Launch the flightlight program passing the latitude (lat) and longitude (lon) of your PiAware station (use www.whatsmygps.com to find your gps location) and the range that should be used to detect if an aircraft is overhead.
usage: flightlight.py [-h] lat lon range
e.g. using GPS coords of 52.4539, -1.7481 (Birmingham, UK Airport) with a range of 10km
sudo python3 flightlight.py 52.4539 -1.7481 10
import RPi.GPIO as GPIO
from flightdata import FlightData
from haversine import points2distance
from time import sleep
#pin of the LED to light
LEDPIN = 17
def __init__(self, ledPin):
self.ledPin = ledPin
#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
led = LED(LEDPIN)
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 = ((args.lat, 0, 0), (args.lon, 0, 0))
endpos = ((aircraft.lat, 0, 0), (aircraft.lon, 0, 0))
distance = points2distance(startpos, endpos)
if distance <= args.range:
plane_in_range = True
#turn the led on / off
#refresh the data
#tidy up GPIO