Outils pour utilisateurs

Outils du site


wiki:projet:bnair:jourdfbdnal_de_bord

Programation

Capteur de particules

Lecture des valeurs du capteur de particules

#include <OneWire.h>
    //Temperature chip i/o
OneWire ds(Thermometer);

void setup(){
    //initialise the pin
serial.begin(9600);

    //thermometer
byte Thermometer = 2;
pinMode(Thermometer, INPUT);
float ThermometerValue = 0;
float ThermometerValueEnable = 22.0;
float ThermometerValueDesable = 20.0;

    //NOX sensor
byte NOXSensor = A1;
pinMode(NOXSensor, INPUT);
int NOXSensorValue = 0;
int NOXSensorValueSumm = 0;
float NOXSensorValueAverage = 0;
float NOXSensorValueTreshold = 400;

    //COV sensor
byte COVSensor = A2;
pinMode(COVSensor, INPUT);
int COVSensorValue = 0;
int COVSensorValueSumm = 0;
float COVSensorValueAverage =0;
float COVSensorValueTreshold = 400;

/*
PM sensor
PMSensorValue
PMSensorValueSumm
PMSensorValueAverage
PMSensorValueTreshold
  */

    //peletier
byte Peletier = 13;
pinMode(Peletier, OUTPUT);
boolean PeletierStatus = 0;

    //Bottom Fan
byte BotFan = 12;
pinMode(BotFan, OUTPUT);
boolean BotFanStatus = 0;

    //Top Fan
byte TopFan = 10;
pinMode(TopFan, OUTPUT);
boolean TopFanStatus = 0;

    // brumisateur
byte Atomizer = 11;
pinMode(Atomizer, OUTPUT);
boolean AtomizerStatus = 0;

int SensorTimer = 0;

int ThermometherTimer = 0;

int AtomizerTimer = 0;
int AtomizerTimeOn = 900000;// 15 minutes
int AtomizerTimeOff = 1800000;// 30 minutes

byte CompteurValue = 0;

}

void loop(){

//Record every second COVSensor, NOXSensor, PMSensor. Do the summ over 1 minute.
if (SensorTimer-millis()>= 1000) {
    COVSensorValue = analogRead(COVSensor);
    NOXSensorValue = analogRead(NOXSensor);
    //Ici je mettrais la reception du PMSensor
    if (CompteurValue <= 60){
        COVSensorValueSumm += COVSensorValue;
        NOXSensorValueSumm += NOXSensorValue;
        //Ici PMSensorValueSumm
        if (CompteurValue>= 60){
            COVSensorValueAverage = COVSensorValueSumm / CompteurValue;
            NOXSensorValueAverage = NOXSensorValueSumm / CompteurValue;
            // ici je mettrais la valeur PMSensorValueAverage
            CompteurValue = 0;
            }
        else {
            CompteurValue++
            }
        }
    SensorTimer = millis();
    // test line
    serial.print('NOX Value is' + NOXSensorValueAverage);
    serial.print('COV Value is' + COVSensorValueAverage);
    }

//Check the temperature every two minutes
if (ThermometherTimer-millis()>= 120000){
    ThermometerValue = getTemp();
    ThermometherTimer = millis()
    }

//Activate or deactivate the peletier depending on water's temperature
if (ThermometerValue>= ThermometerValueEnable && PeletierStatus == 0){
    digitalWrite(Peletier,1);
    PeletierStatus = 1;
    }
if (ThermometerValue <= ThermometerValueDesable && PeletierStatus == 1){
    digitalWrite(Peletier,0);
    PeletierStatus = 0;
    }

/*
//Activate or deactivate the BotFan depending on sensor value and peletier activation
if ((PeletierStatus == 1 || COVSensorValueAverage>= COVSensorValueTreshold || NOXSensorValueAverage>= NOXSensorValueTreshold || TopFanStatus == 1) && BotFanStatus== 0){
    digitalWrite(BotFan,1);
    BotFanStatus = 1;
    }
if ((PeletierStatus == 0 && COVSensorValueAverage <COVSensorValueTreshold && NOXSensorValueAverage <NOXSensorValueTreshold && TopFanStatus == 0 && BotFanStatus == 1){
    digitalWrite(BotFan,0);
    BotFanStatus = 0;
    }
  */

//Yet to be done, triger the TopFan depending on PM sensor value
/*if (PMSensorValueAverage>= PMSensorValueTreshold && TopFanStatus == 0){
    digitalWrite(TopFan,1);
    TopFanStatus = 1;
    }
if (PMSensorValueAverage <PMSensorValueTreshold && TopFanStatus == 1){
    digitalWrite(TopFan,0);
    TopFanStatus = 0;
    }
  */

//Activate or deactivate atomizer
if (AtomizerStatus == 0 && AtomizerTimer-millis() == AtomizerTimeOff){
    digitalWrite(Atomizer,1);
    AtomizerStatus == 1;
    AtomizerTimer = millis();
    }
if (AtomizerStatus == 1 && AtomizerTimer-millis() == AtomizerTimeOn){
    digitalWrite(Atomizer,0);
    AtomizerStatus == 0;
    AtomizerTimer = millis();
    }

}

//Not our code, function to get temperature
float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);
  ds.write(0xBE); // Read Scratchpad

  for (int i = 0; i <9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }

  ds.reset_search();

  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB <<8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;

  return TemperatureSum;

}

Source

wiki/projet/bnair/jourdfbdnal_de_bord.txt · Dernière modification: 2020/10/05 16:39 (modification externe)