{"id":163289,"date":"2025-01-02T17:01:25","date_gmt":"2025-01-02T17:01:25","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=163289"},"modified":"2025-01-02T17:40:25","modified_gmt":"2025-01-02T17:40:25","slug":"raspberry-pi-pico-anemometer-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-anemometer-arduino\/","title":{"rendered":"Raspberry Pi Pico with Anemometer: Measure Wind Speed (Arduino IDE)"},"content":{"rendered":"\n<p>Learn how to interface an anemometer to measure wind speed with the Raspberry Pi Pico. We&#8217;ll cover how to power and connect the sensor to the Pico, and write a simple code to get wind speed values in different units. The Raspberry Pi Pico board will be programmed using Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?resize=1024%2C576&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico with Wind Sensor - Arduino IDE\" class=\"wp-image-164398\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>New to the Raspberry Pi Pico?<\/strong> Check out our eBook: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-micropython-ebook\/\" title=\"\">Learn Raspberry Pi Pico with MicroPython<\/a>.<\/p>\n\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<p>Throughout this guide, we&#8217;ll cover the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#anemometer-intro\" title=\"\">Introducing the Anemometer<\/a>\n<ul class=\"wp-block-list\">\n<li><a href=\"#anemometer-details\" title=\"\">Anemometer Technical Details<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><a href=\"#anemometer-pinout\" title=\"\">Anemometer Pinout<\/a><\/li>\n\n\n\n<li><a href=\"#anemometer-wiring-rpico\" title=\"\">Connecting the Anemometer to the Raspberry Pi Pico<\/a><\/li>\n\n\n\n<li><a href=\"#rpi-pico-anemometer-micropython-code\" title=\"\">Raspberry Pi Pico with the Anemometer &#8211; Measure Wind MicroPython Speed Code<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Raspberry Pi Pico with Arduino ODE<\/h2>\n\n\n\n<p>You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven\u2019t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"anemometer-intro\">Introducing the Anemometer<\/h2>\n\n\n\n<p>An anemometer is a device that allows us to measure wind speed. It is commonly used in weather stations.<\/p>\n\n\n\n<p>Using this sensor is quite easy. It outputs an analog signal, whose voltage is proportional to the wind speed. We&#8217;re using an anemometer with three cups like the one in the picture below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Wind-Sensor-Anemometer.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Wind Sensor Anemometer\" class=\"wp-image-163185\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Wind-Sensor-Anemometer.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Wind-Sensor-Anemometer.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"anemometer-details\">Anemometer Technical Details<\/h3>\n\n\n\n<p>Depending on the manufacturer, the anemometer may have different characteristics. For example, these are the characteristics of the anemometer used in this guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Input voltage: 12-24V DC<\/li>\n\n\n\n<li>Output voltage: 0-5V<\/li>\n\n\n\n<li>Measurement range: 0-32.4m\/s<\/li>\n\n\n\n<li>Resolution: +\/- 0.3m\/s<\/li>\n<\/ul>\n\n\n\n<p>This means that when the analog signal is 0, the wind speed is 0. However, in my case, after powering the sensor and applying a <a href=\"#voltage-regulator\" title=\"\">voltage regular<\/a>, I noticed that when the anemometer was not moving, the output voltage was 0,033V and not 0V.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Measure-Voltage-Wind-Sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Measure Voltage from Wind Sensor with no wind\" class=\"wp-image-163260\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Measure-Voltage-Wind-Sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Measure-Voltage-Wind-Sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>So, I consider this to be the lowest value measured when the sensor is not moving. I recommend you do the same and figure out the minimum value read from the sensor using a multimeter.<\/p>\n\n\n\n<p>These details might be different depending on the manufacturer. So, you need to take that into account when converting the analog signal to wind speed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"anemometer-pinout\">Anemometer Pinout<\/h2>\n\n\n\n<p>The anemometer comes with three wires:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><span class=\"rnthl rntcblue\">Blue Wire<\/span><\/td><td>Signal<\/td><\/tr><tr><td><span class=\"rnthl rntcblack\">Black Wire<\/span><\/td><td>GND<\/td><\/tr><tr><td><span class=\"rnthl rntcbrown\">Brown Wire<\/span><\/td><td>Power<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/anemometer-pinout.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Anemometer, Wind Sensor Pinout\" class=\"wp-image-163187\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/anemometer-pinout.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/anemometer-pinout.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"-anemometer-wiring-rpico\">Connecting the Anemometer to the Raspberry Pi Pico<\/h2>\n\n\n\n<p>The anemometer requires an input voltage of at least 12V. So, you can&#8217;t power it directly from the Raspberry Pi Pico, you need an external power source.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/12VDC-Power-Adapter.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"12VDC Power Adapter\" class=\"wp-image-163182\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/12VDC-Power-Adapter.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/12VDC-Power-Adapter.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>We&#8217;re powering the sensor using a 12V power adapter and connecting it to the anemometer using a power jack. You can use any other suitable power source.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/DC-Power-Jack-Adapter.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"DC power jack adapter\" class=\"wp-image-163181\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/DC-Power-Jack-Adapter.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/DC-Power-Jack-Adapter.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"voltage-regulator\">Converting the Data Signal from 5V to 3.3V<\/h3>\n\n\n\n<p>In the case of my sensor, it operates in the range of 0 to 5V. However, the <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-analog-inputs-micropython\/\" title=\"\">Raspberry Pi Pico analog pins<\/a> can only read a maximum of 3.3V. So, we need to convert the 5V signal to a 3.3V signal. To do that, we can use a voltage divider.<\/p>\n\n\n\n<p><strong>Note:<\/strong> if you&#8217;re using an anemometer like the one from Adafruit, you don&#8217;t need to worry about this because the maximum output voltage is 2V.<\/p>\n\n\n\n<p>A voltage divider is a simple circuit that reduces&nbsp;a large voltage into a smaller one. Using 2&nbsp;resistors and an input voltage, we can create an output voltage that is a fraction of the input. Below you can see&nbsp;the formula that you need to use to calculate the resistors that you need in your circuit:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"349\" height=\"97\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-equation.png?resize=349%2C97&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"voltage divider formula\" class=\"wp-image-12438\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-equation.png?w=349&amp;quality=100&amp;strip=all&amp;ssl=1 349w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-equation.png?resize=300%2C83&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 349px) 100vw, 349px\" \/><\/figure><\/div>\n\n\n<p>If we use a 1k Ohm (R1) and a 2k Ohm (R2) resistor, we&#8217;ll get a maximum output of 3.3V, which is the maximum that the Raspberry Pi Pico can read.<\/p>\n\n\n\n<p>So, here\u2019s what the voltage divider circuit looks like (in which 5V is the maximum value of the sensor data pin):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"408\" height=\"151\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-circuit.png?resize=408%2C151&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"voltage divider 5V to 3.3V\" class=\"wp-image-12441\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-circuit.png?w=408&amp;quality=100&amp;strip=all&amp;ssl=1 408w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/voltage-divider-circuit.png?resize=300%2C111&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 408px) 100vw, 408px\" \/><\/figure><\/div>\n\n\n<p>You can use any other combination of resistors, but you need to take into account the maximum output voltage allowed by the combination of resistors used.<\/p>\n\n\n\n<p>Learn more here: <a href=\"https:\/\/randomnerdtutorials.com\/how-to-level-shift-5v-to-3-3v\/\" title=\"\">How to Level Shift 5V to 3.3V<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Wiring the Circuit: Raspberry Pi Pico with Anemometer<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-with-anemometer-circuit.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico with Anemometer Wind Sensor Circuit\" class=\"wp-image-163261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-with-anemometer-circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-with-anemometer-circuit.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Here&#8217;s a list of the parts you need for this tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi Pico<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/anemometer-wind-speed-sensor\/\" target=\"_blank\" rel=\"noreferrer noopener\">Anemometer Wind Speed Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/12v-2a-power-adaptor-dc-jack\/\" target=\"_blank\" rel=\"noopener\" title=\"\">12V DC Power Adapter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/dc-power-male-plug-jack-adapter-2-1mm\/\" target=\"_blank\" rel=\"noopener\" title=\"\">DC power jack adapter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">1k Ohm resistor and 2k Ohm resistor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Jumper wires<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/best-multimeters-under-50\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Multimeter<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can use the following diagram as a reference to wire the sensor to the board. Don&#8217;t forget to connect the GND pins together.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/RPi-Pico-wind-sensor-circuit.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"376\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/RPi-Pico-wind-sensor-circuit.png?resize=750%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico with Wind Sensor Anemometer Circuit Diagram\" class=\"wp-image-163258\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/RPi-Pico-wind-sensor-circuit.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/RPi-Pico-wind-sensor-circuit.png?resize=300%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p>We&#8217;re connecting the data pin to the Raspberry Pi Pico GPIO 26. Other pins you can use are GPIOs 27 and 28.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\">Recommended reading: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\" title=\"\">Raspberry Pi Pico and Pico W Pinout Guide: GPIOs Explained<\/a><\/p>\n\n\n\n<p>If you&#8217;re using an anemometer like the one from Adafruit that outputs a maximum of 2V, you can connect the output pin directly to the Raspberry Pi Pico analog pin (you don&#8217;t need the voltage divider).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span class=\"rnthl rntcblack\">Black Wire<\/span><\/td><td>12V power source (+)<\/td><\/tr><tr><td><span class=\"rnthl rntcblue\">Blue Wire<\/span><\/td><td>Connect to Pico analog pin (via voltage divider, if needed), we&#8217;re using <strong>GPIO 26<\/strong>.<\/td><\/tr><tr><td><span class=\"rnthl rntcbrown\">Brown Wire<\/span><\/td><td>GND of the Pico board and GND of the power source<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi Pico with Anemometer &#8211; Measure Wind Speed Arduino Code<\/h2>\n\n\n\n<p>The following code reads the analog signal from the anemometer and converts it into wind speed.<\/p>\n\n\n\n<p>You can upload the following code to your Raspberry Pi Pico. You may need to modify some of the variables depending on the parameters of your anemometer.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-anemometer-arduino\/\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n\/\/ Constants (Change the following variables if needed)\nconst int anemometerPin = 26;  \/\/ GPIO pin connected to anemometer (analog pin)\nconst float minVoltage = 0.033;  \/\/ Voltage corresponding to 0 m\/s\nconst float maxVoltage = 3.3;  \/\/ Voltage corresponding to 32.4 m\/s (max speed) (when using voltage divider)\nconst float maxWindSpeed = 32.4; \/\/ Maximum wind speed in m\/s\n\n\/\/ Conversion factors\nconst float mps_to_kmh = 3.6;   \/\/ 1 m\/s = 3.6 km\/h\nconst float mps_to_mph = 2.23694; \/\/ 1 m\/s = 2.23694 mph\n\nvoid setup() {\n  Serial.begin(115200);  \n}\n\nvoid loop() {\n  \/\/ Read analog value from anemometer (ADC value between 0-4095 on RPi Pico for 0-3.3V)\n  int adcValue = analogRead(anemometerPin);\n  Serial.print(adcValue);\n  \n  \/\/ Convert ADC value to voltage (by default, code sets 10-bit resolution: 0-1023 ADC range is 0-3.3V)\n  float voltage = (adcValue \/ 1023.00) * 3.3;\n  \n  \/\/ Ensure the voltage is within the anemometer operating range\n  if (voltage &lt; minVoltage) {\n    voltage = minVoltage;\n  } else if (voltage &gt; maxVoltage) {\n    voltage = maxVoltage;\n  }\n  \n  \/\/ Map the voltage to wind speed\n  float windSpeed_mps = ((voltage - minVoltage) \/ (maxVoltage - minVoltage)) * maxWindSpeed;\n\n  \/\/ Convert wind speed to km\/h and mph\n  float windSpeed_kmh = windSpeed_mps * mps_to_kmh;\n  float windSpeed_mph = windSpeed_mps * mps_to_mph;\n\n  \/\/ Print wind speed\n  Serial.print(&quot;Wind Speed: &quot;);\n  Serial.print(windSpeed_mps);\n  Serial.print(&quot; m\/s, &quot;);\n  Serial.print(windSpeed_kmh);\n  Serial.print(&quot; km\/h, &quot;);\n  Serial.print(windSpeed_mph);\n  Serial.println(&quot; mph&quot;);\n  \n  delay(1000); \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/Arduino\/Anemometer_Wind_Sensor.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How does the Code Work?<\/h3>\n\n\n\n<p>First, define the pin where you&#8217;re reading the sensor, the minimum and the maximum output voltage of the sensor, and the maximum wind speed.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Constants (Change the following variables if needed)\nconst int anemometerPin = 26;  \/\/ GPIO pin connected to anemometer (analog pin)\nconst float minVoltage = 0.033;  \/\/ Voltage corresponding to 0 m\/s\nconst float maxVoltage = 3.3;  \/\/ Voltage corresponding to 32.4 m\/s (max speed) (when using voltage divider)\nconst float maxWindSpeed = 32.4; \/\/ Maximum wind speed in m\/s<\/code><\/pre>\n\n\n\n<p>These are the parameters for our sensor. Yours might be different. When we&#8217;re using the voltage divider, the maximum voltage that the Raspberry Pi Pico will read is 3.3V, which will correspond to the maximum wind speed. When the sensor is not moving, it outputs a voltage of 0.033 (read on the voltage divider output), so we consider that the minimum value.<\/p>\n\n\n\n<p>Then, we have the conversion factors to convert the wind speed from m\/s to km\/h and mph.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Conversion factors\nconst float mps_to_kmh = 3.6;   \/\/ 1 m\/s = 3.6 km\/h\nconst float mps_to_mph = 2.23694; \/\/ 1 m\/s = 2.23694 mph<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, we initialize the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void setup() {\n  Serial.begin(115200);  \n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we get new readings from the sensor every second.<\/p>\n\n\n\n<p>First, we read the value on the ADC pin and convert it to a voltage value. By default, the code sets a 10-bit resolution for the analog signals, so the maximum value that the Pico can read on the analog pin is 1023 that corresponds to 3.3V. So, we can convert the value to a voltage using the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float voltage = (adcValue \/ 1023) * 3.3;<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclblue\">Related content: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-analog-inputs-arduino\/\">Raspberry Pi Pico: Read Analog Inputs (Arduino IDE)<\/a><\/p>\n\n\n\n<p>Then, we have the following condition to check if the values read are within the defined range.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (voltage &lt; minVoltage) {\n  voltage = minVoltage;\n} else if (voltage &gt; maxVoltage) {\n  voltage = maxVoltage;\n}<\/code><\/pre>\n\n\n\n<p>Next, we can easily map the obtained voltage to a wind speed value (alternatively, you can use the Arduino <span class=\"rnthl rntliteral\">map()<\/span> function).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float windSpeed_mps = ((voltage - minVoltage) \/ (maxVoltage - minVoltage)) * maxWindSpeed;<\/code><\/pre>\n\n\n\n<p>Then, we convert the values obtained to km\/h and mph.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Convert wind speed to km\/h and mph\nfloat windSpeed_kmh = windSpeed_mps * mps_to_kmh;\nfloat windSpeed_mph = windSpeed_mps * mps_to_mph;<\/code><\/pre>\n\n\n\n<p>Finally, we print the obtained results.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>  \/\/ Print wind speed\n  Serial.print(\"Wind Speed: \");\n  Serial.print(windSpeed_mps);\n  Serial.print(\" m\/s, \");\n  Serial.print(windSpeed_kmh);\n  Serial.print(\" km\/h, \");\n  Serial.print(windSpeed_mph);\n  Serial.println(\" mph\");\n  \n  delay(1000); \n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Upload the code to the Raspberry Pi Pico.<\/h2>\n\n\n\n<p>To upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.<\/p>\n\n\n\n<p>If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Bootloader mode\" class=\"wp-image-130903\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.<\/p>\n\n\n\n<p>Now, select your COM port in&nbsp;<strong>Tools&nbsp;<\/strong>&gt;&nbsp;<strong>Port<\/strong>. It may be the case that the COM port is grayed out. If that\u2019s the case, don\u2019t worry it will automatically find the port once you hit the upload button.<\/p>\n\n\n\n<p>Upload the code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n<p>If you don&#8217;t know how to upload code to the Raspberry Pi Pico using Arduino IDE, check this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\" title=\"\">Programming the Raspberry Pi Pico with Arduino IDE<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After uploading the code to the board, you can select the Serial Port at the top of the Arduino IDE and open the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n\n<p>You should get wind sensor data on the Serial Monitor every second.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Wind-Speed-Testing-Serial-Monitor.png?resize=663%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing Wind Sensor with Raspberry Pi Pico- Serial Monitor Demonstration\" class=\"wp-image-163292\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Wind-Speed-Testing-Serial-Monitor.png?w=663&amp;quality=100&amp;strip=all&amp;ssl=1 663w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Raspberry-Pi-Pico-Wind-Speed-Testing-Serial-Monitor.png?resize=300%2C131&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to interface an anemometer with the Raspberry Pi Pico programmed with Arduino IDE to get data about wind speed.<\/p>\n\n\n\n<p>We hope you\u2019ve found this tutorial useful. We have tutorials for other popular sensors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-ds18b20-arduino\/\">Raspberry Pi Pico:&nbsp;<strong>DS18B20 Temperature Sensor<\/strong>&nbsp;(Arduino IDE) \u2013 Single and Multiple<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-dht11-dht22-arduino\/\">Raspberry Pi Pico:&nbsp;<strong>DHT11\/DHT22 Temperature and Humidity Sensor<\/strong>&nbsp;(Arduino IDE)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-bme280-arduino\/\" title=\"\">Raspberry Pi Pico: <strong>BME280 Get Temperature, Humidity, and Pressure<\/strong> (Arduino IDE)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the Raspberry Pi Pico with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\" title=\"\">Free Raspberry Pi Pico Projects and Tutorials<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-micropython-ebook\/\" title=\"\">Learn Raspberry Pi Pico with MicroPython (eBook)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to interface an anemometer to measure wind speed with the Raspberry Pi Pico. We&#8217;ll cover how to power and connect the sensor to the Pico, and write a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico with Anemometer: Measure Wind Speed (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-anemometer-arduino\/#more-163289\" aria-label=\"Read more about Raspberry Pi Pico with Anemometer: Measure Wind Speed (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":164398,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,325],"tags":[],"class_list":["post-163289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-arduino-ide"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/Raspberry-Pi-Pico-Wind-Sensor-ArduinoIDE.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/163289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=163289"}],"version-history":[{"count":4,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/163289\/revisions"}],"predecessor-version":[{"id":165126,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/163289\/revisions\/165126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/164398"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=163289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=163289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=163289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}