Bonjour, je suis actuellement en terminal STI2D et mon groupe a pour projet un store automatisé qui a 2 mode, un mode manuel et un mode automatique. Le mode manuel est très basique et ne me pose pas de problème. Le mode automatique par contre me pose un réel souci. Il fonctionne avec 3 capteurs, le capteur de température MCP9808 , le capteur de lumière TSL2561 et l'anémomètre LEXCA003.
Voici mon code:
//les différentes bibliotheque utilise
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include "Adafruit_MCP9808.h"
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
//config des boutton et relais
const int buttonPin = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 6;
const int relais = 4;
const int relais2 = 5;
int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int relaisS = 0;
int relaisS2 = 0;
// configuration des fonction pour les capteurs
float temp;
float lum;
int compt = 0;
const byte interruptPin = 2;
volatile byte state = LOW;
unsigned long previousMillis = 0;
const long interval = 10000;
int vitesse = 0;
// configuration des donnes pour le capteur de lumiere
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
void configureSensor(void)
{
/* You can also manually set the gain or enable auto-gain support */
// tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */
// tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */
tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
/* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
/* Update these values depending on what you've set above! */
Serial.println("------------------------------------");
Serial.print ("Gain: "); Serial.println("Auto");
Serial.print ("Timing: "); Serial.println("13 ms");
Serial.println("------------------------------------");
}
void setup() {
// relais et bout
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(relais, INPUT);
pinMode(relais2, INPUT);
Serial.begin(9600);
//capteur temprerature confing
Serial.println("MCP9808 demo");
if (!tempsensor.begin()) {
Serial.println("Couldn't find MCP9808!");
while (1);
}
//capteur lum config
Serial.println("Light Sensor Test"); Serial.println("");
if (!tsl.begin())
{
Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
while (1);
}
configureSensor();
displaySensorDetails();
Serial.println("");
//capteur vent config
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), compteur, CHANGE);
}
void loop() {
buttonState3 = digitalRead(buttonPin3);
//marche auto
//boolean condition = Acq_lum <100;
if (buttonState3 == HIGH) {
Acq_temp();
Acq_lum();
Acq_vent();
if (Acq_lum <100) {
digitalWrite (relaisS2, LOW);
digitalWrite (relaisS, HIGH);
}
if (Acq_temp >= 25 && Acq_vent < 60 && Acq_lum > 70) {
digitalWrite (relaisS, HIGH);
digitalWrite (relaisS2, LOW);
}
if (Acq_temp >= 25 && Acq_vent > 60 && Acq_lum < 70) {
digitalWrite (relaisS, LOW);
digitalWrite (relaisS2, HIGH);
}
if (Acq_temp >= 25 && Acq_vent < 60 && Acq_lum < 70) {
digitalWrite (relaisS, LOW);
digitalWrite (relaisS2, LOW);
}
}
//marche manuel
else {
Acq_temp();
Acq_lum();
Acq_vent();
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if (buttonPin == HIGH && buttonPin2 == LOW); {
digitalWrite (relaisS, HIGH);
}
if (buttonPin == LOW && buttonPin2 == HIGH); {
digitalWrite (relaisS2, HIGH);
}
if (buttonPin == LOW && buttonPin2 == LOW); {
digitalWrite (relaisS, LOW);
digitalWrite (relaisS2, LOW);
}
}
}
// acisition de la temperature
void Acq_temp() {
tempsensor.shutdown_wake(0); // Don't remove this line! required before reading temp
// Read and print out the temperature, then convert to *F
float temp = tempsensor.readTempC();
float f = temp * 9.0 / 5.0 + 32;
Serial.print("Temp: "); Serial.print(temp); Serial.print("*C\t");
Serial.print(f); Serial.println("*F");
delay(250);
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
delay(2000);
}
// acisition de la lumiere
void Acq_lum() {
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
if (event.light)
{
Serial.print(event.light); Serial.println(" lux");
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor overload");
}
delay(250);
}
// acisition du vent
void Acq_vent() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
Serial.print("vitesse du vent est de ");
Serial.println(compt * 6 / 60);
Serial.print("m/s");
compt = 0;
}
else {
Serial.println(" vent: en cours d'acquisition");
}
}
void compteur() {
compt = compt + 1;
}
Le problème ce passe dans le void loop(), après avoir mesuré les valeurs des différents capteurs ( pour la marche automatique ), je n'arrive pas a faire fonctionner correctement les "if", mes relais ne s'active pas même quand les conditions sont remplies. Je pensais utiliser des "boolean condition", mais cela ne fonctionne toujours pas
.
Si quelqu'un pouvait me débloquer dans mon projet, je lui serait entraiment reconnaissant
.