I got this weather station and I am trying to get the data of the station to a website with this ESP32 as an school project. But the weather station isn't original as it is on the hyperlink, it got modified by an former student. So the cable coming from the anemometer and the wind direction indicator got cut of, so the four cable inside (GND, 3.3V, wind speed data, wind direction data) could fit in the ESP32. First I try to get the anemometer running. I got the Signal from the anemometer to the serial monitor with this code, which works fine:
int windSpeed = A0;
int outputValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
outputValue = analogRead(windSpeed);
Serial.println(outputValue);
if(outputValue > 0) {
Serial.println("high");
}
}
So the next thing I wanted to do was to was calculating the wind speed. I found this code in the internet and adjusted it so it would fit to my ESP32.
const int RecordTime = 3; //Define Measuring Time (Seconds)
const int SensorPin = A0; //Define Interrupt Pin (2 or 3 @ Arduino Uno)
int InterruptCounter;
float WindSpeed;
void setup()
{
Serial.begin(9600);
}
void loop() {
meassure();
Serial.print("Wind Speed: ");
Serial.print(WindSpeed); //Speed in km/h
Serial.print(" km/h - ");
Serial.print(WindSpeed / 3.6); //Speed in m/s
Serial.println(" m/s");
}
void meassure() {
InterruptCounter = 0;
attachInterrupt(digitalPinToInterrupt(SensorPin), countup, RISING);
delay(1000 * RecordTime);
detachInterrupt(digitalPinToInterrupt(SensorPin));
WindSpeed = (float)InterruptCounter / (float)RecordTime * 2.4;
}
void countup() {
InterruptCounter++;
}
I can upload this code to the ESP32 and it prints the massages in the serial monitor, but it doesn`t get the interrupt.
What´s wrong?
Edit: Thank you, now I get the wind speed in the seriell monitor, but unfortunately it doesn't sends many signals. But RISING
in attachInterrupt(digitalPinToInterrupt(SensorPin), countup, RISING);
should´ve solve this should´nt it?
Edit no. 2:
@PMF This is written in the manual (The manual is german but I will continue to write in english so it may help other people): Das Windrad ist mit einem Magnetschalter gekoppelt, der bei einer Umdrehung zwei Impulse abgibt. Das Datenblatt besagt, dass die Impulsfrequenz in Hz mit dem Faktor 0,33 multipliziert werden muss, um die Windgeschwindigkeit in m/s zu erhalten. Die Rotationsfrequenz ergibt sich aus der Zeitdifferenz zwischen zwei Impulsen in Sekunden, multipliziert mit dem Faktor 2 (der Sensor liefert bei einer Umdrehung zwei Impulse). Die Rotationsfrequenz ist dann der Kehrwert der Zeitdifferenz. Wenn dieser Wert mit dem Faktor 0,66 multipliziert wird, ist das Ergebnis die Windgeschwindigkeit in m/s. Die Windgeschwindigkeit in km/h lässt sich berechnen, indem die Windgeschwindigkeit in m/s mit dem Faktor 3,6 multipliziert wird. Mit anderen Worten: Eine Umdrehung des Windrads pro Sekunde ist gleichbedeutend mit der Windgeschwindigkeit 2,4 km/h. (1 rotation = 2.4 kph)
So if I am right the code should also be right, but the interrupt counter seems to just go up while there is an interrupt, even if I put the anemometer on the table in a certain position it just counts up as you can see in the following screenshot of the seriell monitor while the anemometer is just laying on the table: