Introduction: LED Wind Indicator
I have something with the weather. I always like to know how warm or cold it is, how much rain has fallen, how hard the wind blows and from what direction,... and so there are lots of sensors around our house to keep me up to date. These sensors give only a limited range of data, so I still need the internet to inform me about everything I want to know.
I am lucky because one of the national weather data collecting points is located in the village where I live. And all its data is to be found on the internet, together with the data of all other collecting points and predicions for the upcoming days in a very handy XML-file.
The only drawback is that you always need a computer to acces that data. So I decided to start buiding a device to display the data without a pc. This wind indicator is a testversion, displaying only the wind direction, its force and a prediction for the next day. It is connected to a pc via a USB to RS232 converter, but the future project should be able to work as a stand alone version.
Step 1: What Do You Need
- 31 LED's
- 10 x 150Ohm resistor
- 1 x 1K5 resistor
- 1 button
- 2 screwterminals
- 1 isp 10pins connector
- an atmega8
- a 100nF capacitor
- a USB to RS232 cable or something similar. ( I use the RX and TX pins of an xbee to USB connector)
- a programmer
- python 2.6
I made this project with smd components, but it can be build with thru hole parts. I also used a lot of copper thru hole links. These are completely optional, you can use a soldered wire to connect the 2 layers.
Step 2: The Circuit
The circuit for this project is very simple.
28 leds are arranged in two matrixes.
- One is a 4x4 matrix connected to Port B of the microcontroller. Those leds will point the direction on the compass card.
- One is a 3x4 matrix connected to Port C of the microcontroller. Those leds will display the force of the wind on the Beaufort scale.
- Two leds on PortD.3 and PortD.4 indicate indicate whether it is actual data or a forcast.
- One led on PortD.7 flashes when new data is received.
Don´t forget the 150Ohm resistors for the leds,
The button is connected to Pind.2 (the INT0 pin) with a 1K5 pullup resistor on one side and ground on the other side.
The ISP connector is added to the miso, mosi and sck pins Port B and with the reset pin.
RX and TX (PortD.0 and PortD.1) are connected with a screwterminal. This will enable us to add our RX an TX lines from the USB to RS232 cable.
Add a screwterminal for power and don't forget a 100nF capacitor between the lines.
Step 3: Programming the Microcontroller
The program itself works very simple:
It waits until it receives 4 pairs of bytes. The first byte tells the program what kind of data the second byte holds. Two pairs contain the present data and two pairs contain the forecast.
When the microcontroller has received the 4 pairs it will process the first 2 pairs and display the current data. If the button is pressed an interrupt occurs and the microcontroller will display the second set of data (aka the forcast) for 5 seconds.
Don't forget to change the fusebits so that Portc.6 is an IO pin instead of reset, but do it after the microcontroller is programmed because afterwards it won't be programmable anymore.
Step 4: Getting the Required Data to the Device.
A bit of Python:
It is actually the first time that I write a bit of code in Python. And I must say that I love to learn more of it because it's really great to use.
I added the code written in python 2.6 here and I am open to all comments or suggestions about it because it's also new to me.
The basis for the data is an XML-file that contains the weather data for the Netherlands. Python looks the wanted data up in the file and sents it to com 4 every 5 minutes.
###############################################################################################
import urllib
import serial
import time
from xml.etree.ElementTree import ElementTree
StationId = "6319"
speed = {"1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","10":"a","11":"b","12":"c"}
direction = {"N":"1","NNO":"2","NO":"3","ONO":"4","O":"5","OZO":"6","ZO":"7","ZZO":"8","Z":"9","ZZW":"a","ZW":"b","WZW":"c","W":"d","WNW":"e","NW":"f","NNW":"g"}
url = 'http://xml.buienradar.nl'
ser = serial.Serial(3)
while True:
print "nieuw"
root = ElementTree(file= urllib.urlopen(url))
iter = root.getiterator()
for element in iter:
if element.tag == "weerstation":
p = element.items()
for name, value in p:
if value == StationId:
for child in element:
if child.tag == "windsnelheidBF":
q = "1"
q = q + speed[child.text]
print q
ser.write(q)
if child.tag == "windrichting":
q = "2"
q = q + direction[child.text]
print q
ser.write(q)
if element.tag == "dag-plus1":
for child in element:
if child.tag == "windkracht":
q = "3"
q = q + speed[child.text]
print q
ser.write(q)
if child.tag == "windrichting":
q = "4"
q = q + direction[child.text]
print q
ser.write(q)
ser.close
time.sleep(30)
###############################################################################################