Voltage divider calibration

Also current schematic. C3 didn't seem to make a difference.

Bob

#include <SPI.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const int SSPin = 10;
const int SCKPin = 13;
const int MISOPin = 12;
const int MOSIPin = 11;
const float Vref = 4.8;
const float Vdivide = .4038; //actual ratio of the resisters for voltage divider

byte commandMSB = B00000110; //for single input
//byte commandMSB = B00000100;  //for comparative


void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
  Serial.begin(9600);
  //pinMode(10,OUTPUT);              //ADC select ping
  //digitalWrite(10,HIGH);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  pinMode(MISOPin, INPUT);
  pinMode(SSPin, OUTPUT);
  pinMode(SCKPin, OUTPUT);
  pinMode(MOSIPin, OUTPUT);
  digitalWrite(SSPin, HIGH);
  //Serial.begin(19200);
  //Serial.print("starting...");

}


void loop()
{
  uint16_t adc = 0;
  uint16_t value =0;
  float v3 =0.0;
  float V1 = 0.0;
  float Vw = 0.0;
  float ws = 0.0;
  char tempf[5];
  char tempc[5];
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("ADC: ");
  adc = readADC(7);
  lcd.print(adc);
  lcd.print(" & ");
  V1 = (float(adc)/4095)* Vref;
  Serial.println(adc);
  lcd.print(V1);
  lcd.print("V");
  lcd.setCursor(0,1);
  Vw = V1/Vdivide;
  lcd.print("Wind Voltage: ");
  lcd.print(Vw);
  lcd.setCursor(0,2);
  ws = Vw * 6.711;
  lcd.print("Wind speed = ");
  lcd.print(ws);
  
  delay(1000);
}

uint16_t readADC(int channel)
{
  Serial.println("starting readADC");
  uint16_t output;
  uint16_t commandBytes = (uint16_t) (commandMSB<<7|channel<<5)<<1;
  //Select ADC
  digitalWrite(10,LOW);
  Serial.print("sending");
  Serial.println(commandBytes);
  SPI.transfer((commandBytes>>8) & 0xFF);
  Serial.println("sent command bytes");
  byte msb = SPI.transfer((byte)commandBytes & 0xff) & 0x0f;
  Serial.print("MSB = ");
  Serial.print(msb);
  byte lsb = SPI.transfer(0x00);
  Serial.print(" and LSB = ");
  Serial.println(lsb);

  //turn off ADC
  digitalWrite(10,HIGH);

  return ((uint16_t)msb <<8) | lsb;
}

This anemometer is from amazon and didn't have a lot of info. I did find these specs:
Current output impedance: ≤600Ω
Voltage output impedance: ≥1KΩ
Would either of those account for an inaccurate reading using a 78k (end to end, tap at 31.8k or so) voltage divider?
I used a variable test voltage on the ADC and it calculated the speed correctly. But when testing in the car, I was getting readings about 10 mph high, so I think either the anemomenter is bad or my voltage divider is out of wack with these specs.

Below are all the specs listed in case there is something else in there that may be causing the problems...
Specification:
Condition: 100% Brand New
Item Type: Wind Speed Sensor
Material: Aluminum Alloy
Color: Black
Height: Approx.12.4cm / 4.9inch
Measuring Range: 0 to 45 m/s
Accuracy: ±(0.3 + 0.03V)m/s
Resolution: 0.1m/s
Start Wind Speed: ≤0.5m/s
Power Supply: DC 12 - 24V
Output Form: 0 - 10V
Instrument Line Length: Standard: 2.5 meters
Load capacity:
Current output impedance: ≤600Ω
Voltage output impedance: ≥1KΩ
Working environment:
Temperature: -40℃- 50℃
Humidity: ≤100%RH
Protection level: IP45
Temperature: 80℃
Rated Voltage: 300V
Product Power Consumption: 50mW
Wind Speed Measurement Range: 0-30m/s
Wind Speed Measurement Accuracy: ±1m/s
Response Time: <5 seconds
Baud Rate:9600
Communication port: 0 - 10V
Power Supply: 12V-24V DC
Power Consumption: <1W
Operating temperature: -30-80℃
Working humidity environment:0-100% RH (15-95% RH)

parrst:
Also current schematic. C3 didn't seem to make a difference.

Well you can drive to the store, wearing your seatbelt. See? It made no difference. :slight_smile: By the way, where did you connect it physically? Close to the Vcc/ground pins I hope?

Since the anemometer is only accurate to +/- 1.0m/s, it's pretty safe to say that an external ADC is extreme overkill.

aarg:
Well you can drive to the store, wearing your seatbelt. See? It made no difference. :slight_smile: By the way, where did you connect it physically? Close to the Vcc/ground pins I hope?

Since the anemometer is only accurate to +/- 1.0m/s, it's pretty safe to say that an external ADC is extreme overkill.

I get it, I get it 12 bits is overkill, I had it and may need it for other parts I plan to add to the circuit. Yes I put the cap close the the VCC and ground pins. The issue has never been about the accuracy of the ADC, it was originally if the length of wire would affect the voltage divider. And now the question is does my voltage divider full resistance effect the reading of the anemometer. I know my ADC is giving correct voltage on the bench and the program is converting correctly, but I am still getting about 10 MPH over based on driving speed. So either the anemometer is giving too high a voltage or there is a mis-match that is making the ADC read incorrectly.
Or I trash this one and get a pulse anemometer and start over.
Bob

If the sketch, with 10volt on the voltage divider, gives you 45m/sec (100mph) on the display, then the sketch ok.
If it's different with the sensor and a car, then you're measuring method is wrong (airflow around the car), or the sensor needs calibrating, or the sketch must account for a different output signal.

ws = Vw * 6.711; // where did you get that from
Leo..

parrst:
I get it, I get it 12 bits is overkill, I had it and may need it for other parts I plan to add to the circuit. Yes I put the cap close the the VCC and ground pins. The issue has never been about the accuracy of the ADC, it was originally if the length of wire would affect the voltage divider. And now the question is does my voltage divider full resistance effect the reading of the anemometer. I know my ADC is giving correct voltage on the bench and the program is converting correctly, but I am still getting about 10 MPH over based on driving speed. So either the anemometer is giving too high a voltage or there is a mis-match that is making the ADC read incorrectly.
Or I trash this one and get a pulse anemometer and start over.
Bob

Can You post a picture how the rigging was done during Your test? The airflow, turbulance around the car and the rigging is likely not easy to know. Think about the phenomena when You drive close behind a large truck. Even at a distance of, let's say 50 - 75 feet, You get "help" from the truck, and the truck pays extra fuel for "pulling" You!
Having some knowledge about aerodynamics I can easily think of reasons for a slight error.

Wawa:
If the sketch, with 10volt on the voltage divider, gives you 45m/sec (100mph) on the display, then the sketch ok.
If it's different with the sensor and a car, then you're measuring method is wrong (airflow around the car), or the sensor needs calibrating, or the sketch must account for a different output signal.

ws = Vw * 6.711; // where did you get that from
Leo..

Okay, I may see a point of error. The instructions say the out put is 0 - 10V for 0 - 30mps. These specs obviously say 0 - 45mps.
Vw, is the calculated voltage from the anemometer times 3 (to get meters per second) then times 2.2369 to convert to miles per hour.
I will try the math with 10V being 45 meters per second and see if the circuit reported speed is closer to the driving speed... May be a few days till the wind is low enough though.
Bob

Railroader:
Can You post a picture how the rigging was done during Your test? The airflow, turbulance around the car and the rigging is likely not easy to know. Think about the phenomena when You drive close behind a large truck. Even at a distance of, let's say 50 - 75 feet, You get "help" from the truck, and the truck pays extra fuel for "pulling" You!
Having some knowledge about aerodynamics I can easily think of reasons for a slight error.

Did not mount. Will evnetually be mounted on the roof of the house, so was just heal out the window. I don't expect 100% accuracy but if I am reading withing a few mph, I will consider it close enough. 10+ mph was way too far off.
Bob