Accurate Wireless Weather Vane
by jbike in Circuits > Arduino
24632 Views, 219 Favorites, 0 Comments
Accurate Wireless Weather Vane
This wireless weather vane has some unique features- wind direction with a simple, economical, and accurate absolute encoder. Some consumer weather stations Comparison have a limited wind direction resolution of 22.5 degrees, updated every 14 seconds. This weather station's wind direction has a resolution of one tenth degree, updated once a second. The Bluetooth LE module, a HM-10, allows sleeping between display readings to save power.
A New Type of Wind Vane
I wanted to construct a wind direction indicator that is more accurate than consumer grade equipment, but is also cheaper than a professional quality wind vane. The goal was to make it using an relatively cheap ($6) sensor, and send the wind direction data via Bluetooth to a display station. Bluetooth enables a faster update rate than consumer grade wind vanes. Another goal was to make the sensor solar rechargeable. Materials had to be easily available and low cost, yet be able to resist rain and exposure to the elements.
The Bluetooth interface and Display are virtually identical to my previous Instructable, Wireless digital scale, except for the programming.
Gather Materials
2 ea. (8 spare) Miniature deep groove ball bearing 625ZZ 5*16*5 mm ball bearings
1 ea. (14 spare) Wood dowels 3/16" x 11-7/8" dowels
1 ea. N48 Neodymium Magnet Dia 1/4"x1/2" Diametrically Magnetized diametrically magnetized magnet
1 ea. 3/4" Copper pipe cap, hardware store
1ea. 1/2" Copper pipe coupler, hardware store
1 ea. 6" x 1/2"Copper pipe, hardware store
1 ea. 12" x 3/4" Copper pipe, hardware store
1 ea. 3/4" to 1/2" Copper pipe reducer, hardware store
1 ea. Hall type absolute position encoder, SPI, SOIC-8, MLX90316KDC-BDG-100-RE encoder
1 ea. ATmega328 ATmega328P-PU
1 ea. socket DIP-28 socket
1 ea. 16 Mhz crystal oscillator oscillator
2 ea. 20pf capacitors cap
2 ea. HM-10 Bluetooth Low Energy module, configured as master, HM-10 serial
1 ea. HM-10 Bluetooth Low Energy module, with carrier board and voltage regulator, HM-10 w/carrier *
1 ea. 2 cell AA battery holder battery holder
1 ea. pin Adapter adapter
1 ea. USBasp Programmer USBasp programmer
1 ea free Aduino IDE Arduino IDE
1 ea. 2 x 16 LCD, I2C interface LCD
1 ea. Arduino Pro Mini 8 Mhz 3.3v 8Mhz Pro Mini ATmega328
1 ea. USB to TTL serial adapter FTDI adapter
1 ea. USB battery bank battery bank
10 ea. momentary tactile button (9 spare) buttons
1 ea. clear soap dish enclosure for display, from Daiso.
1 ea. rectangular plastic organizer enclosure for remote, from Dasio.
Notes: * check if board has HMSoft firmware. Otherwise flashing may be required to support I/O and connection functions. See this Instructable, and especially the comments.
Assorted: wires, small perfboard, 3 2N2222 transistors, IRF9540 Mosfet, resistors, and diodes.
Testing the MLX90316 Sensor
Since this is the first time I have used the MLX90316 magnetic rotary encoder sensor, I needed to find out how sensitive it is in order to build the wind vane housing and mount the magnet the correct distance away from the sensor. I thought if the strong magnet saturates the sensor, it is unlikely to work- but found that distance made little difference from direct contact to about 1/2" away. I also checked out some valuable resources which I used, see this German lab experiment. It is important to get the correct version of the MLX90316, they have an analog version, a proprietary protocol version, and a SPI version. Since the existing Arduino code for this sensor used an older version of the Arduino IDE, I needed to add #include (right after the comment section) to the MLX90316.h file. Also, the sketch uses the Metro.h library, see Metro timed events. Note that MOSI and MISO share the same data wire, unlike normal SPI.
Use a Arduino Uno with test.ino to test the sensor. The sensor requires 5 volts and ground; Digital pin 13 connects to SCK, Digital pin 12 (MISO) not connected, Digital pin 11 to MOSI, and Digital pin 10 to SS.
Downloads
Programming the HM-10 Modules
The HM-10 modules come configured as slave units, and no auto sleep. They need to connect immediately, master to slave, without a password or other negotiation. To program them, use the FTDI 232 adapter (set to 3.3 volts). You connect pins 3.3v, Gnd, Rx to Tx and Tx to Rx; it will be helpful to have a female header to stick on the FTDI pins, then solder small flexible wires to the female header pins, and from there solder the wires to the HM-10. See the circuit diagram for the HM-10 Manual , the mode led on pin 24, the reset wiring on pin 23, and the connection of grounds to pins 13,14, 21, and 22 needs to be accomplished- it takes a fine tipped soldering iron and a steady hand (plus a 3rd hand accessory to hold the board) . You will need some sort of terminal program, the best is Realterm because it allows you to send AT modem commands to change the configuration. See this excellent instructable to familiarize yourself on the steps required Programming the HM-10 .
/////////////////////////////////////////////////////////////////////////////////////////////////
Program the slave as:
MODE 2, data and AT commands in same data stream. send AT+MODE2
PWRM 0, auto sleep mode, send AT+PWRM0
ROLE 0, slave/remote/peripheral unit, send AT+ROLE0
PCTL 1, power output, max. send AT+PCTL1
FLOW 0, flow control not used. send AT+FLOW0
ADDR ?, you need to find the MAC address for this device, write it down. Used to set CONN in master. send AT+ADDR?
CONN XXYYZZ etc., set the slave to connect to master's MAC address. send AT+CON22C22FF22DA2 [whatever the master MAC address is]
BAUD 0, default baud rate 9600 baud (as fast as the ATtiny85 can send) send AT+BAUD0
POWE 2, 0 dBm transmit power, send AT+POWE2
TYPE 0, make sure no passcode is used, send AT+TYPE0
VERS ?, version. My version was v540. send AT+VERS?
///////////////////////////////////////////////////////////////////////////////////////////////////////
Program the master as:
MODE 2, data and AT commands in same data stream. send AT+MODE2
PWRM 1, no sleep mode (master has external soft latch power down), send AT+PWRM1
ROLE 1, master/central unit, send AT+ROLE1
PCTL 1, power output, max. send AT+PCTL1
FLOW 0, flow control not used. send AT+FLOW0
ADDR ?, you need to find the MAC address for this device, write it down. Used to set CONN in slave. send AT+ADDR?
CONN XXYYZZ etc., set the master to connect to slave's MAC address. send AT+CON22C22FF22DA2 [whatever the slave MAC address is]*
BAUD 0, default baud rate 9600 baud (as fast as the ATtiny85 can send) send AT+BAUD0
POWE 2, default 0 dBm transmit power, send AT+POWE2
TYPE 0, make sure no passcode is used, send AT+TYPE0
VERS ?, version. My version was v540. send AT+VERS?
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Note: in V540, the units no longer link automatically on power on. Instead, the sketch sends CONN XXYYZZ etc. each time the Display starts up.
Other interesting AT commands:
TEMP ? send AT+TEMP? to get the temperature
RSSI ? received signal strength send AT+RSSI?
BATT ? battery voltage (has A/D converter!), send AT+BATT?
PIO4, PIO7 etc. set or clear output pins (not used here, but could be handy). The Atmega328P is awakened from sleep via any serial data sent from the HM-10 Tx line via 10 K resistor to INT0 hardware interrupt pin. Could have used the PIO pins to do the same like I used to power up and down the ATtiny85 in the previous project, but thought this would be a less complicated way to do it.
Mechanical / Electrical Details of the Weather Gathering Remote Unit
Electrical
The weather unit uses an Atmega 328p and 16 Mhz crystal on a piece of perfboard programmed with the usbasp programmer (although you could remove the chip and program it with an Arduino Uno). The MLX90316 sends direction data to the 328p, where it is converted to TTL serial data and sent by the HM-10 Bluetooth Low Energy module to the display unit.
If you use usbasp, be sure to have the 3.3v/5v jumper in the 5v position or the upload will fail. Also, on a raw 328p, you need to burn bootloader on the tools tab first. When loading the sketch with usbasp, first select the pro mini board with 328p chip on the Tools tab, with usbasp selected as programmer, then go to the sketch tab to upload via programmer (not via the normal button).
The sensor is mounted on an adapter board from Proto-Advantage , which just barely fit into a short stub of 3/4" copper pipe. Use thick super glue to secure the corners of the adapter inside the pipe. You may leave the copper section with the sensor not secured to the pipe tee so you can rotate it to give a north reading when installed with the wind vane pointed north. Add some foil duct tape to weather proof and secure the sensor section to the other pipe sections.
Mechanical
The weather vane rotates on 2 inexpensive ball bearings. The grease and seals of the bearing need to be removed for less friction. With jeweler's screwdriver, pry the metal shields out, then spray with wd-40 to remove the grease. Find a super light oil to lubricate the bearings. The wood dowel is the axle that the magnet is glued to on one end. The dowel fits into the top pipe cap, fitting into a brass tube soldered through the pipe cap. The dowel is further secured to the brass tube via a nut and screw drilled through both. The vane is epoxied to the brass tube.
Make the vane as light as possible. Balance the vane about the brass tube connection, and be sure there is more area to the fin than the pointer counterbalance weight. See the images of Weather Field No. 1 art installation (Santa Monica, CA) to get an idea of optimum construction.
Assembling the Display and Programming It
The Display is just a modified version of my previous instructable Wireless Digital Scale .
Hot glue the Arduino Pro Mini to a bit of Popsicle stick, and hot glue the Popsicle stick to the lcd so as to keep the Pro Mini above the tabs on the lcd display. Build the Softlatch on/off circuit on a piece of perfboard according to the circuit diagram- credit to Ardweeny and wire it to Ground and Raw input of the Pro Mini, and control lines to pins 5 and 6 of the Pro Mini. Wire the on/off button lead and ground to an case mounted button. Hot glue the Softlatch circuit to the lcd.
Since the power supply needed to power the lcd with 5 volts, but the HM-10 needs 3.3 volts, a Pro Mini with an onboard 3.3 volt regulator was chosen. That simplified logic level interfacing between the Pro Mini and HM-10, and even to the I2C backpack (5V I2C components can be connected to the SDA and SCL lines of the 3.3V Pro Mini I2C-bus), while still giving the lcd 5 volts for a normal display. A common USB battery bank was chosen to provide the 5 volts because it was easily rechargeable via USB, fit well in the project box (soap dish), and came in a pleasing color to show through the clear soap dish case. Because lengthwise space is limited in the soap dish, a USB connector was cut down and wires soldered to the cut down connector (outer 2 pins) and extended to the Softlatch circuit board power input.
Carefully drill 4 holes for mounting the lcd in the soap dish lid, and attach lcd to lid with 4 ea. 1/2" long miniature screws and matching nuts. Drill holes for the on/off pushbutton, and hold in place temporarily with earthquake putty. Apply epoxy sparingly to top and bottom of toggle and allow to cure. Wire according to circuit diagram.
Program the Pro Mini with the sketch using the FTDI adapter plugged into the female programming header.
Position the HM-10 so the built in Antenna faces towards the front of the case, clear of metal or wiring, and in such a position that the HM-10 mode led can be seen. Secure with hot glue to the lcd.
Downloads
Testing and Results
The absolute encoding sensor was better than I imagined it would be. It has great accuracy, and is low in cost ($6). Only a few years ago, it was impossible to find an absolute encoder with reasonable accuracy for less than $100. It was possible to make an optical encoder, but that was a complex task of arranging IR emitters and detectors, making an optical encoder disk, then sandwiching the parts into a reasonable size housing.
The Display works great, and the HM-10 Bluetooth link is robust. In my house, the Display can turn on the remote sensor from the kitchen. Interestingly, the Display unit can not turn on the sensor from other rooms, though once connected, the connection remains solid in other rooms. This may be due to the advertising behavior of the HM-10 in sleep mode- there is a AT command for changing this parameter, but I haven't tried changing it yet.
My next step is to add a small solar panel to recharge the 3 AA Ni-Mh batteries in the remote. Without recharging, I expect the life of the batteries to be about 2 weeks of intermittent use, which is about half the life of the 2 AA alkaline batteries used for my previous project, the wireless hummingbird scale. The reason for the expected shorter life is the much greater current draw in operation (about 70mA), though the sleep current consumption is about the same.