What's appen with my analog pin

Good day,

I am a bit frustreted when suddendly the sensors does not return a value, while it was working...

I ma using an Davis anenometer and I have been helped with this tutorial

Actually, I am trying to understand what happen with the direction.
Note: My board works with 3.3V instead of 5V. My board is based on a Zero and a ATSAMD21G18 .

My Aref is open
My analogReadResolution is 12 (0-4095)

analogReadResolution(12);
analogReference(AR_DEFAULT); // 3.3V (10-12)

Case 1:
Then when the vane is lined up along the length of the support bar (North) I should read at A0 something close to 0 or 4025
Case 2:
when the vane is lined at 90° fromthe length of the support bar (Eats) I should read at A0 something close to 1000
Case 3
when the vane is lined at 180° fromthe length of the support bar (South) I should read at A0 something close to 2000

Case 4
when the vane is lined at 275° fromthe length of the support bar (West) I should read at A0 something close to 3000

And so on.

My problem, I read at my analog pin
Case 1 : 12 or 2346
Case 2 : 27
Case 3: 34
Case 4: 56

I ma surprised it goes from 56 and then to 2346.

Now, as I am not powering the sensor with a 5V, th output can different, but it should be lenear, istn't (specilly from case 4 to 2346)?

The sensors can be broken? I will try with anotherone later in the day...

What's your opinion?

Additionally the wind speed is not working, not at all.

A schematic of how you have connected everything together might help, and also please post the full code of your sketch (don't forget to use the code tags: the little "< / >" button when you type a post).

based on the description of the anemometer, it needs to be powered with 5V. this suggests the level needs to be translated to read the analog output with a 3.3V processor. possibly just a voltage divider.

Sounds like a broken wire or bad connection to me. If you disconnect the Arduino, is the resistance between any two of the three wind direction pins greater than 20K Ohms? That would indicate a break.

1 Like

Apparently the problem come from my board. I tried with another one and I got some better result. I will not debug my board for now because something worry me about the Wind direction measure

The code is here and the schema here

I am oberserving the analog input. My analogReadResolution is now to 10.

The doc say, the wind direction read at A0 is from 0 to 1023.

0 and 1023 is noth.
I supposed the south is around 512.

When I move the van to 180°, then to the south, the read, at A0, 787 whch is West.
When I move the 90° (Est), I read 612
When I move the van close to 10°, I read 200 which is EST.

That's sound not good, isn't? If I move the van to 180°, I should read around 512.
What should be the reason?

Then I wonder, if I should forget that exemple and calibrate the noth,est,south,west following what I read at A0.

if the anemometer it powered by 5V, South is half, 2.5V.

2.5V read by a 3.3V ADC is 75% of 1024 or 775

you could try translating the voltage using a pot so that your ADC sees 3.3V when the anemometer is outputting 5V

Yes, but as I power the anemometer with 3.3V, when I move the van to 180°, A0 should not read 2.5V, but 1.25V, no?

if South is 50%, then 1.65V.

can you check the anemometer output with a voltmeter?

It's a good idea, I will do it tomorrow. It's 1am at my place :slight_smile: Thank. I keep posted

The schematic shows a 5V supply. Are you using 5v with your 3.3V Arduino?

The schematic shows a 909k Ohm pull-up on the Wind Direction signal line. That would mean that the output is not quite linear. According to my calculations, the error is worst about 240°, and is only 3.3 steps out of 1024.

Thanks for your reply.
That's interesting.
(I have not measure the voltage yet at the wire when the van is at 180°)

The schematic shows a 5V supply. Are you using 5v with your 3.3V Arduino?
No I don't. I power it with 3.3V from my board.

That would mean that the output is not quite linear
I wonder if the code here is reliable. I wonder if I would better write down the value at A0, when the van is at 0°, 45°, 90°,135°, etc, and use a switch(); case, or a if,

or using this


void getHeading(int direction) {
if(direction < 22)
Serial.println("N");
else if (direction < 67)
Serial.println("NE");
else if (direction < 112)
Serial.println("E");
else if (direction < 157)
Serial.println("SE");
else if (direction < 212)
Serial.println("S");
else if (direction < 247)
Serial.println("SW");
else if (direction < 292)
Serial.println("W");
else if (direction < 337)
Serial.println("NW");
else
Serial.println("N");
}

with the value measured at A0.
I am just a bit woried if another Davis Anemomter will return the same value at thr analog output. It should but... (adely, I have another anemometer, but not with the same connector and it is on the field. Then I can not compare yet)

Can we agree that it will work with 3.3V just fine ?
It is very unlikely that there is some electronics inside the anemometer. So it is just resistors and a contact (it might be a reed switch).

I don't like to wires going directly into pins of the Arduino board. Perhaps some protection resistors in series (in the signal path) is safer. For example 4k7, something between 1k and 10k.

The first thing I'd do, as it's already been suggested, would be to test whether the voltages are coming out as expected with a multimeter. To assess whether your conversion algorithm is sound, put a potentiometer in lieu of the anemometer (keep in mind that a pot's knob only rotates ¾ of a turn).

Hello there,

I am sorry for late reply, but I was busy with some other topics.
Now I juste measure the voltage a the van direction, and that clear.

Noth : 3.2V or 78mV
Est: 1.73V
South: 2.5V (end not 1.6V)
Oest: 2.7V

So that anemometer is not lenar.
I think, at the end, I have to calibrate it with the analog value I measure when I move the van.

N: 1023/0
N/E: 276
E: 561
E/S: 668
S: 775
S/W: 833
W: 871
W/N: 924
I quickly note the above value by moving the van

Thta's mean that the code here is not realiable and I should adapt it following the measure I found by moving the van from N/E/S/W

And as it look to be not linear, this


Direction = map(analogInput, 0, 4095 , 0, 360);

can not be used

Or is the anemometer defect?

Instead of doing the what it should be why not try the what it is?

I have a wind vane that uses a resistor to generate a value that is sent to a A:D converter and I use 3.3V.

I pointed my wind vane north, using a compensated compass, noted the analog reading; got north.

I pointed my wind vane east, using a compensated compass, noted the analog reading; got east.

I pointed my wind vane south, using a compensated compass, noted the analog reading; got south.

I pointed my wind vane west, using a compensated compass, noted the analog reading; got west.

Then I worked out the range of analog values vs what I call north, south, east, and west.

Here are values I got for the directions I measured using the Sparkfunny thing.

void fWindDirection( void *pvParameters )
// read the wind direction sensor, return heading in degrees
{
  float adcValue = 0.0f;
  uint64_t TimePastKalman  = esp_timer_get_time();
  SimpleKalmanFilter KF_ADC( 1.0f, 1.0f, .01f );
  float high = 0.0f;
  float low = 2000.0f;
  float ADscale = 3.3f / 4096.0f;
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 100; //delay for mS
  int count = 0;
  String windDirection;
  windDirection.reserve(20);
  String MQTTinfo = "";
  MQTTinfo.reserve( 150 );
  while ( !MQTTclient.connected() )
  {
    vTaskDelay( 250 );
  }
  for (;;)
  {
    windDirection = "";
    adcValue = float( adc1_get_raw(ADC1_CHANNEL_6) ); //take a raw ADC reading
    KF_ADC.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
    adcValue = KF_ADC.updateEstimate( adcValue ); // apply simple Kalman filter
    TimePastKalman = esp_timer_get_time(); // time of update complete
    adcValue = adcValue * ADscale;
    if ( (adcValue >= 0.0f) & (adcValue <= .25f )  )
    {
      // log_i( " n" );
      windDirection.concat( "N" );
    }
    if ( (adcValue > .25f) & (adcValue <= .6f ) )
    {
      //  log_i( " e" );
      windDirection.concat( "E" );
    }
    if ( (adcValue > 2.0f) & ( adcValue < 3.3f) )
    {
      //   log_i( " s" );
      windDirection.concat( "S");
    }
    if ( (adcValue >= 1.7f) & (adcValue < 2.0f ) )
    {
      // log_i( " w" );
      windDirection.concat( "W" );
    }
    if ( count >= 30 )
    {
      MQTTinfo.concat( String(kph, 2) );
      MQTTinfo.concat( ",");
      MQTTinfo.concat( windDirection );
      MQTTinfo.concat( ",");
      MQTTinfo.concat( String(rain, 2) );
      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY );
      MQTTclient.publish( topicWSWDRF, MQTTinfo.c_str() );
      xSemaphoreGive( sema_MQTT_KeepAlive );
      count = 0;
    }
    count++;
    MQTTinfo = "";
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
  }
  vTaskDelete ( NULL );
}

I finally do as the following.

I created an array


int WDdirection10[18] {
  // analgo, direction (the wind come from)
  0,    0,    // N
  270,  45,  // NE
  561,  90,  // E
  642,  135,  // ES
  743,  180,  // S
  814,  225,  // SW
  870,  270,  // W
  920,  315,  // WN
  987, 360, // N
};

I use the following to know the direction the wind is coming from

  if (analogInput <= WDdirection10[0]) {     // Minimum value
    windDirection = WDdirection10[0 + 1];
  }
  if (analogInput >= WDdirection10[18]) {     // Maximum value
    windDirection = WDdirection10[18 + 1];
  }
  for (int i = 0; i < 18; i = i + 2) {
    if ((analogInput >= WDdirection10[i]) && (analogInput <= WDdirection10[i + 2]))
    {
      windDirection = WDdirection10[i + 1] - ((WDdirection10[i + 1] - WDdirection10[i + 3]) * ((analogInput - WDdirection10[i]) / (WDdirection10[i + 2] - WDdirection10[i])));
      Serial.print("\t"); Serial.println(windDirection);
      break;
    }
  }

It works fine. But as I have not write this code, is there some think I do not understand.

IF we consider, the van return 280, the following

windDirection = WDdirection10[i + 1] - ((WDdirection10[i + 1] - WDdirection10[i + 3]) * ((analogInput - WDdirection10[i]) / (WDdirection10[i + 2] - WDdirection10[i])));

will be egal to
45 - ((45 - 90) * ((280 - 270) / (561 - 270)));
my calculatir display the result of -1.546

but this


Serial.print("\t"); Serial.println(windDirection);

print 45

If I move my vane,, it print 45,90,135,180, etc

I do not rememer what does

windDirection = WDdirection10[i + 1] - ((WDdirection10[i + 1] - WDdirection10[i + 3]) * ((analogInput - WDdirection10[i]) / (WDdirection10[i + 2] - WDdirection10[i])));

I though, it was used to adjust the direction between 45 and 90, for exempe 55, if the vane is just after 270

Your calculator works with floating point, but the Arduino is doing integer math. You're dividing 10 by 291, giving zero.

Which wind direction do you want? Relative or actual.

Create an array of actual values read from the A:D converter when the thing is pointed in the desired direction.

For instance. Point the wind vane north, what id the readout for the A:D converter? That's your north reading.

Now turn the wind vane south, take AD readings, that's your A:D reading for south.

Use real world values instead of values you thing they should be.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.