Rotation data with reed contact to Blynk or Analog out

Hello all together,

I would like to use a small windmill with a reed contact, to check the wind at the ground, while Paragliding.

To get the rotation speed, I would like to transfer these data over Blynk to my mobile phone.

I already found a code for the speed, but I couldn't scale it to the analog output or a virtual Pin.

I thought, to go over the "map()" command, but couldn't make it.

To read the sensor, I use this code.

bool puls = update_Sensor();

//digitalWrite(pinLed, puls);

unsigned long var = pulse_pro_Zeit (puls, 1000); // zählt Pulse pro 1000ms

zeige_Drehzahl(var, 1000);

Would be happy to get some help here.

Best Greatings :wink:

Hi, scaling is done with multiplication or division. For example, if I want to scale the range 0-100 to the range 0-10, I divide by 10.

What is the range of data coming from the sensor, and what is the range that you need to scale it to?

Hi benja,

the code you posted is far from beeing a complete sketch that does compile.

So minimum information you have to provide is your complete code.
I have tinkered a little bit with Blynk. There are some tutorials on the blynk website. There should be some example code that shows a value in the Blynk-App.

You can use this as a starting point.
best regards Stefan

Hey,

thanks a lot, for that quick answers.

bellow is the complete code.

I would like to put the rotation between 0 and 200/second to the analog output.

Afterwards I´m able to use the Blynk app an code to put it online

I Just need the step, to scale the rotation.

const byte pinSensor = 7;
const byte pinLedgruen = 10;
const byte pinLedblau = 12;
const byte pinLedrot = 11;
int Variabel = 13;

void setup() {
Serial.begin(9600);
pinMode(pinSensor, INPUT);
pinMode(pinLedgruen, OUTPUT);
pinMode(pinLedblau, OUTPUT);
pinMode(pinLedrot, OUTPUT);
pinMode (Variabel, OUTPUT);
}

void loop()
{
bool puls = update_Sensor();

//digitalWrite(pinLed, puls);

unsigned long var = pulse_pro_Zeit (puls, 1000); // zählt Pulse pro 1000ms

zeige_Drehzahl(var, 1000); // zeigt Wert aller Sekunde
}

// ****** Funktionen ****** //
unsigned long pulse_pro_Zeit (bool puls, unsigned int zeit)
{
static unsigned long diff = 0;
static unsigned long count = 0;
static unsigned long last_count = 0;
static unsigned long last_ms = 0;
unsigned long ms = millis();

if (puls) count++;

if (ms - last_ms >= zeit) {
last_ms = ms;
diff = count - last_count;
last_count = count;
}

return diff;
}

bool update_Sensor()
{
bool state = false;
static bool oldRead = false;

bool read = digitalRead(pinSensor);

if (read && (!oldRead) ) {
state = true;
}
oldRead = read;

return state;
}

void zeige_Drehzahl (unsigned long var, unsigned int intervall)
{
static unsigned long last_ms = 0;
unsigned long ms = millis();

if (ms - last_ms >= intervall) {
last_ms = ms;
Serial.println(var);

if ( var <= 3 ){
digitalWrite (pinLedgruen, HIGH );
}
else {
digitalWrite (pinLedgruen, LOW );
}
if ((var >3)&&(var <=10)) {
digitalWrite (pinLedblau, HIGH );
}
else {
digitalWrite (pinLedblau, LOW );

if ((var >10)&&(var <=200)){
digitalWrite (pinLedrot, HIGH );
}
else {
digitalWrite (pinLedrot, LOW );
}
}
}
}