Question in using an Linear Hall Sensor to make an Anemometer

Hello Everyone.

I'm trying to use a linear hall sensor to measure wind speed. I've tried everything else I can't integrate the hall sensor in the code. The sensor is already measuring correctly because I made the test code and the sensor records the decrease in the value of the Arduino analog reading. The sensor is is in one of the 3 blades of the Anemometer. I'm using the Wemos D1 R1 card.
This is a project for the university.

Thanks in advance for all your help.

//function used to define the pins used
int hallSensor_pin = A0;
int hallSensorValue = analogRead(hallSensor_pin);
//int hallSensorStatus[10];

//int addcount(int);

// --- Const---
const float pi = 3.14159265359;     //PI number
int period = 5000;               //Measurement time (milliseconds)
int delaytime = 2000;            //Interval between samples (milliseconds)
int radius = 155;                //Anemometer radius (mm)

// --- Global ---
unsigned int Sample  = 0;        //Stores the number of samples
unsigned int counter = 0;        //counter for the sensor
unsigned int RPM = 0;            //rpm
float speedwind = 0;             //Wind speed (m/s)
float windspeed = 0;             //Wind speed (km/h)

void setup()
{
  pinMode(A0, INPUT);      
  digitalWrite(A0, HIGH);    
  Serial.begin(19200);       
} //end setup

void loop()
{
  Serial.println("");
  Serial.print("VALOR HALLSENSOR:");
  Serial.println(hallSensorValue);
  Sample++;
  Serial.print(Sample);
  Serial.print(": Start reading...");
  windvelocity();
  Serial.println("   done.");
  Serial.print("Counter: ");
  Serial.print(counter);
  Serial.print(";  RPM: ");
  RPMcalc();
  Serial.print(RPM);
  Serial.print(";  Wind speed: ");

  //*****************************************************************
  //print m/s
  WindSpeed();
  Serial.print(windspeed);
  Serial.print(" [m/s] ");

  //*****************************************************************
  //print km/h
  SpeedWind();
  Serial.print(speedwind);
  Serial.print(" [km/h] ");
  Serial.println();

  delay(delaytime);                       
} //end setup

//Function to measure wind speed
void windvelocity()
{
  speedwind = 0;
  windspeed = 0;

  //counter = 0;
  //attachInterrupt(A0, addCount, RISING);
  addCount();
/*
  unsigned long millis();
  long startTime = millis();
  while (millis() < startTime + period) {}
  */
}

//Calculate revolutions per minute (RPM)
void RPMcalc()
{
  RPM = ((counter) * 60) / (period / 1000);
}

//Calculates wind speed in m/s
void WindSpeed()
{
  windspeed = ((4 * pi * radius * RPM) / 60) / 1000;
} //end WindSpeed

//Calculates wind speed in km/h
void SpeedWind()
{
  speedwind = (((4 * pi * radius * RPM) / 60) / 1000) * 3.6; 
} //end SpeedWind

void addCount()
{
  if (hallSensorValue <= 900)
  {
    counter++;
  }
}

/*
//Increment counter
void addcount() {
  counter++;
}
*/
  pinMode(A0, INPUT);     
  digitalWrite(A0, HIGH);

Doubt that it (enabling pull up) will work on a WeMos.

The analogue pin on that board probably has a 220k/100k voltage divider to ground,
to change the analogue input range of the ESP8266 module from about 0-1volt to 0-3.2volt.

Post a link to that hall sensor.
Leo..

Ok, here is some info...

Ebay Link
Sensor Datasheet

thx

1 Like

The datasheet tells me that this is a 5volt ratiometric sensor.
Don't see how you can interface that the easy way with a 3.3volt logic processor with absolute A/D.
I would first get this hall sensor working with a 5volt Arduino Uno.
Leo..

Hello

I need too use this board because I also use it for other important things in the project I'm working on. I honestly don't know much about C programming. What happens at this moment is that when the magnet passes the sensor the value of the analog reading goes down. Then I wanted to find a way that when the value goes below a stipulated value, the counter increases. That's the problem.
The sensor reading is undoubtedly working. The programming part is missing for the analog reading values to increase the counter.

Thx

Code is a mess, and I don't know where to start.
I think you should have used a 3.3volt supply hall sensor with digital output, and interrupts to advance a counter.

If you want to use this analogue sensor, then first make it's output digital.
Remove the two useless lines I posted before from the sketch.
Then try something like this

 // declare a threshold value on top of the sketch
int threshold = 500; // change value to suit

hallSensorValue = analogRead(hallSensor_pin);
// print that, to see it's value, so you can set a sensible threshold
if (hallSensorValue < threshold) counter++; // +1 to counter if sensor value drops below threshold

Note that this sensor needs a 5volt supply (4.5volt minimum).
And it's output not only depends on the magnet, but also on supply voltage.
Leo..

For counting revolutions use a hall-switch, not a linear sensor!

The sensor is is in one of the 3 blades of the Anemometer.

Really? How twisted do the wires get??

Or are you trying to sense the earth's field from a rotating wireless sensor node?

Normally you'd stick a small magnet on the shaft and a hall switch mounted next to it.

You realize those sensors are likely to be counterfeit? I'd certainly recommend buying parts like this from genuine electronic stockists only.

Okay, sorry for taking so long to answer, but I will respond to what I can at this moment.

What happens as I already described is that the analog reading value goes down when the magnet passes close to the sensor, as shown in the photo I attached. The choice of the sensor was not mine, my teacher told me to use that one.

MarkT, I did not explain correctly the way the sensor is placed, I apologize...

Here are pictures of my project:
My DIY Anemometer Photo

Here what I did was to create a code that when the value of the analog reading goes down the led would turn off:
Test of the sensor

I'll send you more updates.
Thank you

Hello
Here do I put this code? In what part of the sketch?

Wawa:
hallSensorValue = analogRead(hallSensor_pin);
// print that, to see it's value, so you can set a sensible threshold
if (hallSensorValue < threshold) counter++; // +1 to counter if sensor value drops below threshold.

I have delete that two lines that weren't doing nothing.

Thx
Gabriel

Very unfortunate siting of the sensor. The magnet will pass the sensor in a fraction of a millisecond.

Place the magnet on the shaft so its moving much slower and you'll have many milliseconds for a detection,
which is within the capabilities of analogRead().

With a hall-switch rather than a linear sensor you could simply have setup an interrupt routine to count
and/or time the rotations.

With analog you'll have to use some smarts to recognise each peak in the reading unambiguously.

Hello

I already realized that some of my choices were not the most correct, also because I had never done anything like this.

MarkT:
Very unfortunate siting of the sensor. The magnet will pass the sensor in a fraction of a millisecond.

Even so, I think there has to be a way to put this to work and activate the counter, because I already managed to do this with a led and the speed of the wind was quite fast. I used a hairdryer at full speed and the led registered all passages. This is just a project does not need to withstand storms xD

Here is a example vid:
Activation of the led with each pass of the sensor

Thx for the help
Gabriel

Doing analogRead() calls on a quickly passing sensor doesn't make much sense. Besides, the code from #5 needs state change detection - count when it falls below 500, not when it is below 500.

It should be quite straightforward to turn this hall sensor signal into a digital one using a comparator. That also solves the 5V/3.3V problem as comparators usually have open collector outputs. The output of the comparator can go to a digital pin and a FALLING interrupt can do the counting (so don't use GPIO16).

Okay, how could I use a comparator?
When referring to GPI016, what are you referring to?
I'm new to this, sorry if I'm asking the obvious.

Thank you
Gabriel

pureezop:
Okay, how could I use a comparator?

Some example circuits here.

When referring to GPI016, what are you referring to?

Get to know your hardware. The pin mapping of the WeMOS you have to look up yourself.

Thanks for the idea of using a comparator, I was researching it and seems that is exactly what I was looking for. Converts the analog signal to digital (0-1), and makes it 10x easier.
In my researched I noticed that to make a comparator I need some hardware. Am I right?
I have an IC 74HC595 that came with an arduino kit. Is it possible to use it to make a comparator?

I just don't understand was you say "so don't use GPIO16"... I'm using A0(analog port), and not an GPI(digital port).

Thx for help
Gabriel

Look at the Uno schematic, it use LM358 as a comparator in a couple of places. Just need a trim pot, or two resistors, to set the level.

74HC595 is a shift register not a comparator.
I suppose if you attempted to shift a level that was <0.9V it would shift in a 0 and above 3V it would shift in a 1, from >=9V to <3V (approximate range) the level could be either. Similar to as if you tried to read that level with a digital pin.

GPIO16 on the ESP8266 (see the link that I gave you already) doesn't have interrupts available. The A0 neither. The GPIO pins are mapped to the various D pins on your WeMOS in a way that's impossible to remember.

All you need for a comparator is a chip like the LM339, LM239, LM139:

What I don't understand is why are you using a HALL sensor with an analog output? Using a comparator you are going to take an analog signal and at some level derive a 1 or 0. Why not just start with a HALL effect sensor with a digital output? You get some wind cups and use a hall sensor (actually several hall sensors) to generate pulses and count the pulses.

You can just remove the BLDC motor from an old DVD Player use the wind cups to spin it and count the pulses from the installed HALL sensors. To calibrate it place it on the roof of a vehicle and have someone drive at fixed speeds on a day with no wind. Note the pulse counts at different speeds.

As to a comparator? Just a comparator IC and a few additional pieces of hardware. Mostly resistors.

Ron

Hello,

CrossRoads:
74HC595 is a shift register not a comparator.

Ok, so I have to buy a new IC...

Ron_Blain:
All you need for a comparator is a chip like the LM339, LM239, LM139:

So if I buy one of these ICs that you mentioned I can easily get it working, am I right?

These are the ones my teacher said to use, so this Hall sensor is what I'm trying to use. But if I have to, I can change without a problem, as long as it's cheap and not too big, I don't see the problem. Which one do you recommend and what other material would I need to buy?

The idea of changing the way the project is built, I will not do it because at this moment I don't have much time right now because of the project delivery date and what I have built now was all built to be tough with hot glue, metal and plastic and now I didn't want to change it. Thanks for the idea of the car to measure wind speed, I will definitely try that.

Thanks for all the help
Gabriel

It is probably easier and cheaper to swap out the hall effect sensor for a hall effect switch. Then the additinoal hardware is not needed.