OC
OceanRemote
Low-code IoT platform
โ† Back to Course

Anemometer - Wind Speed Measurement

Anemometer - Wind Speed Measurement

๐Ÿ’จ Anemometer - Wind Speed Measurement for Safe Farming

๐Ÿ’จ What You'll Learn:

  • ๐Ÿ“ก Measure wind speed using a reed switch anemometer
  • โšก Calculate wind speed from pulse counts (km/h, mph, m/s)
  • ๐Ÿšจ Set up high wind alerts for spraying safety
  • ๐ŸŒพ Protect crops from wind damage and lodging

Wind speed affects pesticide spraying, crop lodging, evapotranspiration, and irrigation efficiency. An anemometer helps you make safer, smarter decisions - never spray pesticides in high wind, and protect young crops before storms arrive.

๐Ÿ”ง Types of Anemometers

  • ๐ŸŒช๏ธ Reed Switch Anemometer ($15-25): Most common for DIY. Magnet passes reed switch each rotation โ†’ electrical pulse. Works with ESP32 interrupts.
  • ๐Ÿ”„ Hall Effect Anemometer ($20-35): More durable, no moving contact. Better for long-term outdoor use. Higher accuracy.
  • ๐Ÿ“ก Ultrasonic Anemometer ($100-300): No moving parts, highest accuracy. Professional use. Expensive for most farms.
  • ๐Ÿ’จ Cup Anemometer ($10-20): Simple mechanical design. Affordable but less accurate at low speeds.
๐Ÿ’ก How Reed Switch Anemometer Works:

Each rotation of the wind cups = one electrical pulse. More pulses per second = higher wind speed. Calibration factor converts pulses per second to km/h.

Example: 10 pulses per second ร— 0.34 = 3.4 km/h wind speed.

๐Ÿ”Œ Anemometer Wiring Diagram

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                    REED SWITCH ANEMOMETER WIRING
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    Anemometer (3-wire)                ESP32 Dev Board
    โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•                โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    
    Red (VCC)            โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  3.3V
    Black (GND)          โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  GND
    Yellow (Signal)      โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  GPIO35 (interrupt capable)
    
    โš ๏ธ IMPORTANT: Use a pull-up resistor (10kฮฉ) between VCC and Signal
    if your anemometer doesn't have one built-in!
    
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”
    โ”‚     โ”‚
    โ”‚ 10kฮฉโ”‚
    โ”‚     โ”‚
    โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜
       โ”‚
    3.3Vโ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Anemometer Red
       โ”‚
       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Anemometer Yellow (with pull-up)
       โ”‚
    GND โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Anemometer Black

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                    ESP8266 ALTERNATIVE PINS
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    For ESP8266: Use D1 (GPIO5), D2 (GPIO4), D3 (GPIO0) or D5 (GPIO14)
    Avoid GPIO16 (D0) - wake pin only
    
    Recommended: GPIO5 (D1) - stable interrupt support

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
โš ๏ธ Anemometer Calibration - IMPORTANT!
  • โŒ Different anemometers have different pulse factors! The 0.34 factor is an example.
  • โœ… How to calibrate: Drive at known speed (e.g., 30 km/h car) while holding anemometer out window. Count pulses per second.
  • โœ… Formula: Wind Speed (km/h) = Pulses per second ร— (Known Speed รท Pulses)
  • โœ… Example: At 30 km/h you count 50 pulses/sec โ†’ Factor = 30 รท 50 = 0.6

๐Ÿ“Š Wind Speed Classification & Farm Actions

Wind Speed (km/h) Classification Farm Actions
0-5 km/h๐ŸŸข Calmโœ… Ideal for spraying. Normal irrigation.
5-15 km/h๐ŸŸข Light Breezeโœ… Safe for spraying (with coarse droplets).
15-25 km/h๐ŸŸก Moderateโš ๏ธ Spray with caution - drift risk. Increase irrigation for evaporation.
25-35 km/h๐ŸŸก Fresh BreezeโŒ DO NOT spray pesticides. Secure young plants.
35-50 km/h๐Ÿ”ด Strong Wind๐Ÿšจ Emergency: Support tall crops, delay irrigation (high evaporation).
> 50 km/h๐Ÿ”ด Storm/Gale๐Ÿšจ CRITICAL: Secure everything, stop field work, evacuate if necessary.
๐Ÿ’ก Why Wind Speed Matters for Spraying:
  • ๐ŸŒฌ๏ธ Wind > 15 km/h: Pesticide drift = chemical lands on non-target areas (neighbors, water sources)
  • ๐Ÿ’จ Wind > 25 km/h: 50-80% of pesticide can miss target = wasted money + environmental damage
  • โœ… Best spraying conditions: Early morning (5-8 AM) or evening (6-9 PM) when wind is calmest
  • ๐Ÿšซ Never spray when wind > 25 km/h: Illegal in many countries, dangerous to applicator, ineffective

๐Ÿ“– Complete Anemometer Code with Alerts

/*
 * Anemometer - Wind Speed Measurement with Alerts
 * Measures wind speed and provides safety recommendations
 * 
 * Components:
 * - Reed switch anemometer (or hall effect)
 * - ESP32 board
 * - 10kฮฉ pull-up resistor (if needed)
 */

#include <WiFi.h>
#include <HTTPClient.h>

// ========== PIN DEFINITIONS ==========
#define WIND_PIN 35          // GPIO35 (interrupt capable)

// ========== CALIBRATION FACTOR ==========
// Measure: Count pulses per second at known wind speed
// Factor = Wind Speed (km/h) รท Pulses per second
const float WIND_FACTOR = 0.34;   // Example: 0.34 km/h per pulse/sec

// ========== ALERT THRESHOLDS ==========
const float SPRAY_MAX_WIND = 15.0;     // Max safe wind for spraying (km/h)
const float HIGH_WIND_WARNING = 25.0;   // High wind warning (km/h)
const float STORM_WARNING = 50.0;       // Storm force wind (km/h)

// ========== GLOBAL VARIABLES ==========
volatile int pulseCount = 0;
float windSpeed = 0;
float maxWindSpeed = 0;
float minWindSpeed = 999;
float avgWindSpeed = 0;
unsigned long lastSecond = 0;
unsigned long lastLog = 0;
int totalPulses = 0;
int logCounter = 0;

// ========== INTERRUPT SERVICE ROUTINE ==========
void IRAM_ATTR pulseCounter() {
    pulseCount++;
}

// ========== CALCULATE WIND SPEED ==========
float calculateWindSpeed() {
    return pulseCount * WIND_FACTOR;
}

// ========== CHECK SPRAYING SAFETY ==========
bool isSafeToSpray() {
    if (windSpeed <= SPRAY_MAX_WIND) {
        return true;
    }
    return false;
}

String getSprayRecommendation() {
    if (windSpeed <= 5) {
        return "โœ… Perfect conditions. Safe to spray any pesticide.";
    } else if (windSpeed <= 10) {
        return "โœ… Good conditions. Use medium to coarse droplets.";
    } else if (windSpeed <= 15) {
        return "โš ๏ธ Caution. Use coarse droplets. Check drift direction.";
    } else if (windSpeed <= 25) {
        return "โŒ NOT recommended. High drift risk. Wait for calmer wind.";
    } else {
        return "๐Ÿšซ DO NOT SPRAY! Wind too high. Postpone spraying.";
    }
}

// ========== UPDATE STATISTICS ==========
void updateStatistics() {
    if (windSpeed > maxWindSpeed) maxWindSpeed = windSpeed;
    if (windSpeed < minWindSpeed) minWindSpeed = windSpeed;
    
    totalPulses += pulseCount;
    logCounter++;
    avgWindSpeed = (totalPulses * WIND_FACTOR) / logCounter;
}

// ========== DISPLAY WIND REPORT ==========
void displayWindReport() {
    Serial.println("\nโ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—");
    Serial.println("โ•‘                    ๐Ÿ’จ WIND SPEED REPORT                       โ•‘");
    Serial.println("โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•");
    
    Serial.println("\n๐Ÿ“Š CURRENT WIND:");
    Serial.printf("   ๐Ÿ’จ Speed: %.1f km/h\n", windSpeed);
    
    // Visual wind indicator
    int bars = (windSpeed / 10) + 1;
    if (bars > 10) bars = 10;
    Serial.print("   ๐Ÿ“Š [");
    for (int i = 0; i < 10; i++) {
        if (i < bars) Serial.print("โ–ˆ");
        else Serial.print("โ–‘");
    }
    Serial.println("]");
    
    Serial.println("\n๐Ÿ“ˆ STATISTICS (Last " + String(logCounter) + " readings):");
    Serial.printf("   ๐Ÿ”ผ Max: %.1f km/h\n", maxWindSpeed);
    Serial.printf("   ๐Ÿ”ฝ Min: %.1f km/h\n", minWindSpeed);
    Serial.printf("   ๐Ÿ“Š Avg: %.1f km/h\n", avgWindSpeed);
    
    Serial.println("\n๐ŸŽฏ SPRAYING RECOMMENDATION:");
    Serial.println("   " + getSprayRecommendation());
    
    if (windSpeed > HIGH_WIND_WARNING) {
        Serial.println("\nโš ๏ธ HIGH WIND WARNING:");
        Serial.println("   - Secure young plants and tall crops");
        Serial.println("   - Check irrigation system for wind drift");
        Serial.println("   - Postpone any outdoor burning");
    }
    
    if (windSpeed > STORM_WARNING) {
        Serial.println("\n๐Ÿšจ STORM WARNING:");
        Serial.println("   - Evacuate fields if necessary");
        Serial.println("   - Secure all equipment");
        Serial.println("   - Move livestock to shelter");
    }
    
    Serial.println("\nโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n");
}

// ========== SEND TO OCEANREMOTE ==========
void sendToOceanRemote() {
    if (WiFi.status() != WL_CONNECTED) return;
    
    HTTPClient http;
    http.begin("https://api.oceanremote.net/device/state");
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    String data = "token=YOUR_TOKEN";
    data += "&wind_speed=" + String(windSpeed);
    data += "&max_wind=" + String(maxWindSpeed);
    data += "&spray_safe=" + String(isSafeToSpray() ? "YES" : "NO");
    
    http.POST(data);
    http.end();
}

// ========== SETUP ==========
void setup() {
    Serial.begin(115200);
    
    // Configure wind sensor pin
    pinMode(WIND_PIN, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(WIND_PIN), pulseCounter, FALLING);
    
    Serial.println("========================================");
    Serial.println("๐Ÿ’จ ANEMOMETER WIND MONITOR v2.0");
    Serial.println("   Wind Speed Measurement System");
    Serial.println("========================================\n");
    
    Serial.printf("โš™๏ธ Calibration factor: %.2f km/h per pulse/sec\n", WIND_FACTOR);
    Serial.printf("โš ๏ธ Spray safe threshold: %.0f km/h\n\n", SPRAY_MAX_WIND);
}

// ========== LOOP ==========
void loop() {
    // Calculate wind speed every second
    if (millis() - lastSecond >= 1000) {
        windSpeed = calculateWindSpeed();
        updateStatistics();
        
        // Display every 10 seconds
        if (millis() - lastLog >= 10000) {
            displayWindReport();
            sendToOceanRemote();
            lastLog = millis();
        }
        
        // Reset pulse counter for next second
        pulseCount = 0;
        lastSecond = millis();
    }
    
    delay(10);
}
    
๐Ÿ“– Case Study - Anemometer Prevents Pesticide Disaster:

A large farm in South Africa installed an anemometer connected to their weather station:

  • ๐Ÿ’จ Morning wind: 8 km/h โ†’ Safe to spray
  • โš ๏ธ Alert triggered at 11 AM: Wind increased to 28 km/h
  • ๐Ÿšซ Action: Spraying crew stopped immediately
  • ๐Ÿ’ฐ Savings: Prevented $2,000 worth of pesticide drift onto neighboring farm
  • โš–๏ธ Avoided: Potential lawsuit and environmental fine

"The wind monitor saved us from a major mistake. We would have sprayed in dangerous conditions without it." - Farm Manager, South Africa

๐Ÿ’ก Anemometer Placement Tips:
  • ๐Ÿ“ Height: Mount at 2-3 meters above ground (crop canopy level + 1m)
  • ๐Ÿ“ Location: Open area, away from buildings, trees, and structures that block wind
  • ๐Ÿ“ Orientation: Ensure cups rotate freely (no obstructions, level mounting)
  • ๐Ÿ“ Maintenance: Clean moving parts every 6 months, check for debris
  • ๐Ÿ“ Lightning protection: Not recommended for storm monitoring - unplug during lightning
๐ŸŽฏ Key Takeaways:
  • โœ… Wind < 15 km/h: Safe for spraying pesticides
  • โœ… Wind 15-25 km/h: Spray with caution only (coarse droplets)
  • โœ… Wind > 25 km/h: DO NOT spray - high drift risk
  • โœ… Calibration factor: Unique to your anemometer - measure and set correctly
  • โœ… Interrupt pins: Use GPIO32-39 on ESP32 for reliable pulse counting
  • โœ… Always check wind before spraying: Prevents waste, environmental damage, legal issues
๐Ÿ’ก Key Takeaways:
  • Apply these concepts directly to your farm or project.
  • Take notes on important details for the quiz.
  • Use the button below to track your progress.