Wind Speed Sensor - Voltage 0V to 5V ESPHome

Hi All,

i got a wind speed sensor PR-3000-FSJT-V05 that outputs voltages from 0V to 5V, reading maximal 30m/s

I want to use ESPHome on a ES32. To use the AD port (limited to 3V3, i will use a voltage divider).

But i’m not finding out how to declare it in ESPHome, mapping 0 - 3.3 to 0 to 30

 int sensorValue = analogRead(A0);
  float outvoltage = sensorValue * (3.3 / 1023.0);
  Serial.print("outvoltage = ");
  int Level = 6 * outvoltage;//The level of wind speed is proportional to the output voltage.
  Serial.print("wind speed is ");
  Serial.println(" level now");

Anyone able to help me out?

Take a look at batt_voltage_filtered and the sensor it copies. You should be able to use filters for the various processing steps, especially calibrate linear, multiply and lambda. You should be able to do it all in yaml (maybe with a few lambda’s) rather than a custom component.

If it’s a strictly linear mapping and you don’t expect any weirdness (aberrant values that need filtering out) then I think the filter stuff is overkill and prone to skewing results (it’s still not clear to me how much state even the linear conversion holds/why it needs to). You can use esphome::remap in a lambda (an example from a different kind of sensor) as an alternative that isn’t that popular

e.g. something like esphome::remap(x, 0.0f, 3.3f, 0.0f, 30.0f) but the code above it in my example that rejects bad values is important too. Actually looking at your code you’re converting from the 12bit adc (0-4095) to voltages and then to a real-world value. So skip the voltages and use esphome::remap(x, 0.0f, 4095.0f, 0.0f, 30.0f)?

@bwooce thank you.

digging, i found that the best will be use a ina3221, which will give me the reading from 0 to 5 without the need of voltage dividers and so on, simplifying the circuit., and so i can read the wind direction too.

In this case, can i esphome::remap(x, 0.0, 4095, 0.0, 30.0)?

and how to debug it, like printing the results on screen, like arduino ide does :slight_smile: :

Nice work, just make sure you type 4095.0 (to make it a float) or you’ll get an obscure error message as all the values have to be the same type (float in this case). This is a low-level function without niceties that filters have.

# Logging level
 level: VERBOSE

in the yaml should help with the debugging, if you connect to the logs remotely via HA/esphome plugin or locally on the usb port.


thx for the hint. Will try and will let you know.

i did try the remap, but return error.

  - platform: ina3221
    address: 0x40
      shunt_resistance: 0.1 ohm
        name: "INA3221 Channel 1 Current"
        name: "INA3221 Channel 1 Power"
        name: "INA3221 Channel 1 Bus Voltage"
        id: wind_speed_voltage
        remap(x, 0.0, 4095, 0.0, 30.0)
        name: "INA3221 Channel 1 Shunt Voltage"

How shall i use it?

Do a Google search for ESP boards 5v Tolerant. I think you will find it’s quite capable of handling the full 5V without any voltage dividing. Here is one example:

@lexridge , thx, but not a solution. i want to learn and understand better :wink:

1 Like

The digital inputs are quite tolerant, but the built-in adc units definitely aren’t; even that linked article says so (and the spec sheet for the esp’s is quite emphatic).

1 Like

Yeah, use filters or use this:

    lambda: |-
        ESP_LOGI("","Lambda incoming value=%f - data array size is %d",x,data.size());
        if (isnan(x)) {  // add other values of x that are not valid you want to exclude
          return NAN; 
        return esphome::remap(x, 0.0f, 4095f, 0.0f, 30.0f); 

thank you. i will try and let you know. Worked.