As an Amazon Associate, Akermin earns from qualifying purchases. Product links on this page are affiliate links.
Check the sensor’s output type first. The common two-wire cup anemometer from hobby weather stations is a reed switch: connect one wire to an interrupt pin such as D2 and the other to GND, enable the internal pull-up, count pulses over a fixed time, and multiply by the sensor’s factor, often 2.4 km/h for one pulse per second. Three-wire sensors with a voltage output connect to an analog input through a divider if their output can exceed 5 V, and need their own supply of the voltage stated on the label. 4-20 mA sensors need a precision resistor to turn current into voltage, and RS485 sensors need a MAX485-type transceiver module.
Identify your anemometer’s output
Anemometers measure wind with spinning cups, a propeller, or ultrasonic transducers, and each sensor turns that into an electrical signal in one of four common ways. The label, datasheet or the number of wires usually tells you which.
| Output type | Typical wires | Arduino connection | Conversion |
|---|---|---|---|
| Pulse (reed switch or Hall sensor) | 2, or 3 for Hall types | Digital interrupt pin plus GND, with pull-up | Pulses per second times the datasheet factor |
| Analog voltage | 3 (supply, ground, signal) | Analog pin; divider if output exceeds 5 V | Linear map from voltage range to speed range |
| 4-20 mA current loop | 2 or 3 | Precision resistor to GND, read across it | 4 mA = minimum, 20 mA = maximum speed |
| RS485 Modbus | 4 (supply, ground, A, B) | RS485 to TTL module on serial pins | Read a register; value scaled per datasheet |
Ultrasonic anemometers, covered in our ultrasonic anemometer guide, almost always use RS485, RS232 or SDI-12 rather than pulses. Handheld meters with an app, like the BTMETER BT-100APP, send data over Bluetooth to a phone and are not meant to be wired to a microcontroller at all.
Wiring and coding a pulse anemometer
The two-wire cup anemometer sold with many hobby weather kits contains a magnet on the rotating shaft and a reed switch that closes once or more per revolution. The datasheet for the widely used weather meter kit design states that one switch closure per second equals 2.4 km/h, about 1.49 mph. Your sensor may differ, so check.
- Connect one anemometer wire to digital pin 2 on an Uno or Nano, which supports external interrupts. Connect the other wire to GND. Polarity does not matter for a plain reed switch.
- In setup, set the pin with pinMode(2, INPUT_PULLUP). The pin now reads HIGH and falls LOW each time the switch closes.
- Attach an interrupt: attachInterrupt(digitalPinToInterrupt(2), countPulse, FALLING). In the countPulse function, increment a volatile counter.
- Add debounce. Reed switches bounce, giving several false edges per closure. In countPulse, ignore any edge that arrives within a few milliseconds of the last one, using millis() or micros().
- In the main loop, every 3 to 5 seconds, copy and reset the counter with interrupts briefly disabled, divide by the elapsed seconds, and multiply by the factor. Twelve pulses in 5 seconds is 2.4 pulses per second, so 2.4 x 2.4 = 5.76 km/h.
- Print or log the value. For gusts, keep the highest 3 second value; for average wind, average over a minute or more.
If the cable is longer than a few metres, add an external pull-up of a few kilohms to 5 V and a small capacitor across the input to keep noise out. Hall-effect anemometers need a supply wire as well, and their output is often open collector, which also needs a pull-up.
Analog, 4-20 mA and RS485 sensors
Analog voltage. These sensors usually need a supply higher than 5 V, commonly 7 to 24 V, and output a voltage proportional to wind speed. A popular hobby type outputs 0.4 V at zero wind rising to 2.0 V at its maximum. Power it from its own supply, tie that supply’s ground to Arduino GND, and connect the signal to A0. Convert the analogRead value to volts with value x 5.0 / 1023, then map the sensor’s voltage range linearly onto its speed range. If the datasheet says 0 to 5 V, read directly; if it says 0 to 10 V, use a resistor divider such as two equal resistors to halve it before the pin.
4-20 mA. Put the sensor in series with its supply and a 250 ohm precision resistor to ground. The voltage across the resistor runs from 1 V at 4 mA to 5 V at 20 mA, which A0 can read. Speed = (current – 4) / 16 x full scale. A reading below about 3.8 mA usually means a broken wire or failed sensor, which is the advantage of a live zero.
RS485 Modbus. Use an RS485 to TTL module. Connect A and B to the sensor, DI and RO to serial pins, and the driver enable pins to a digital pin that switches between sending and receiving. A Modbus library then requests the wind speed register at the sensor’s address and baud rate from its datasheet, and the returned integer is often a scaled value, such as wind speed times 10, so check the scaling in the datasheet.
Checking your readings are real
- Zero check. With the cups held still, the pulse sketch must print 0 and the analog sensor must read its zero voltage. Anything else is noise, bounce or a wrong offset.
- Rotation check. Turn the cups by hand one revolution at a time and watch the counter. Count how many pulses per revolution your sensor gives; some give two.
- Reference comparison. On a steady breezy day, hold a calibrated handheld anemometer at the same height near the sensor and compare averages over a minute or two. Gusty wind makes instant readings disagree, so compare averages.
- Fan test. A steady fan gives a repeatable airflow for checking consistency, though not absolute accuracy.
Expect cup anemometers to stall below a starting threshold, often around 1 m/s or less, and to over-read slightly in gusty conditions because cups speed up faster than they slow down. Those are characteristics of the instrument; what an anemometer measures and vane versus hot wire anemometers explain why different designs suit different jobs.
Mounting and electrical safety
Mount the sensor clear of buildings and trees; the usual meteorological reference height is 10 m above open ground, which most home installs cannot reach, so expect lower readings near the roofline. Keep the Arduino and any power supply in a weatherproof box, with cable glands and a drip loop on the cable. A tall metal mast is a lightning path; ground it properly and do not run the sensor cable into the house without surge protection. Use only low-voltage DC supplies. Never connect a sensor directly to mains, and if a sensor requires a mains-powered supply, use a sealed, certified adapter rather than building one.
Wire one input and test by hand
Look up your sensor’s output type and conversion factor, wire it to the matching Arduino input, and spin the cups slowly by hand while watching the serial monitor. Once one revolution produces the expected pulse count and still cups read zero, you can mount it outside and trust the numbers it logs.
Frequently Asked Questions
Which Arduino pin should I use for an anemometer?
For a pulse sensor, use a pin that supports external interrupts, such as D2 or D3 on an Uno or Nano. Analog and 4-20 mA sensors use an analog pin such as A0, and RS485 sensors use serial pins through a transceiver module.
Why does my anemometer read wind when the cups are not moving?
On a pulse sensor, a floating input or electrical noise on a long cable is counting false edges. Enable the pull-up, add debounce in code, and consider an external pull-up resistor and small capacitor.
Can I power a 12 V anemometer from the Arduino?
Not from the 5 V pin. Use a separate 12 V supply for the sensor, connect its ground to Arduino ground, and make sure the signal voltage reaching the Arduino pin never exceeds 5 V, or 3.3 V on 3.3 V boards.
How do I convert pulses to wind speed without a datasheet?
Compare the pulse rate with a calibrated handheld anemometer in steady wind at several speeds and fit a straight line. The slope of that line is your conversion factor.
Does an ESP32 work the same way?
Yes, the logic is the same, but ESP32 pins are 3.3 V only. Use a pull-up to 3.3 V, and scale any analog or current-loop voltage to stay under 3.3 V.