Bonjour, j'ai deux capteurs que j'ai acheté et je souhaite les brancher ensemble afin qu'ils mesurent tous les deux des valeurs:
capteur anémomètre :
https://www.lextronic.fr/temperature-meteo/19999-capteur-anenometre.html
(j'ai utilisé le branchement numéro 2)
capteur girouette:
https://www.gotronic.fr/art-capteur-girouette-25973.htm
[ Code]
#include <math.h>
#define WindSensorPin (2) // Location de la broche en D2
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // kilomètres par heure
void setup() {
Serial.begin(9600);
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
}
void loop() {
Rotations = 0; // Set Rotations count to 0 ready for calculations
sei(); // Enables interrupts
delay (5000); // attendre 5 secondes
cli(); // Disable interrupts
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) =( P * 0.75 ) * 1.61 (*1.61> conversion mph en km/h)(1 mile = 1.61km)
WindSpeed = (Rotations * 0.75) * 1.61 ;
int sensorValue = analogRead(A1);
Serial.println("Test Vitesse du vent");
Serial.println("Rotations\tkm/h");
Serial.println(" ");
Serial.print(Rotations); Serial.print("\t\t");
Serial.println(WindSpeed);
Serial.println(" ");
delay(5000);
Serial.println("Direction du vent");
Serial.println(sensorValue);
Serial.println(" ");
//float angle= 0.1569280069*sensorValue+96.9848608491; (équation trouvée par le tableur)
//Serial.println(angle);
}
// This is the function that the interrupt calls to increment the rotation count
void isr_rotation () {
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}
}[ /Code]
Le problème étant que lorsque j'utilise le moniteur de série, seul la girouette m'affiche les valeurs correctes relevée par celle-ci. J'ai aussi rajouté le programme de l'anémomètre juste au dessus, le moniteur série m'indique constamment 0, alors qu'il marchait très bien séparément.
Je souhaiterais comprendre mes erreurs/avoir des corrections.
Cordialement,