Présentation du Baromètre

Le Matériel

Comprend:

  1. Sonde BME-280 (Pression,Température et Humidité)
  2. Sonde DHT-22 (Température et Humidité)
  3. Sonde étanche DS18B20 (Température)
  4. Carte Seeduino Lotus

Le Script
barometre.ino
#include <Wire.h>
#include "Arduino.h"
#include <OneWire.h>
#include "DHT.h"
#include "Seeed_BME280.h"
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#define DHTPIN A0             // Connexion de DHT22 au pin A0
#define DHTTYPE DHT22         // DHT 22 (AM2302)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BME280 bme280;
DHT dht(DHTPIN, DHTTYPE);
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
int DS18S20_Pin = 4;
OneWire ds(DS18S20_Pin);
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Timers
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
unsigned long CurrentMillis  = 0;     // Millisseconde courante
unsigned long NextMillis  = 0;        // Millisseconde courante
const float altitude = 75;
#define INTERVAL 30000 ;              // envoi toutes les 30 secondes
/* =========================================================================================== */
#define NOM "Barometre"
#define Version "1.025"
int BAUD = 9600;
char modele[] = "Seeduino Lotus";
char buffer[80];
/* =========================================================================================== */
void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(BAUD);
  if (!bme280.init())
  {
    Serial.println("Device error!");
  }
  else
  {
    sprintf (buffer, "#! %s Version: %s\t\t| %s - %i Bauds", NOM, Version, modele, BAUD );
    Serial.println(buffer);
  }
  dht.begin();
  NextMillis = 0;
  delay(1000);
}
 
void loop()
{
  float PA = bme280.getPressure()  / 100.0f ;
  float Tmp = bme280.getTemperature();
  float Hum = bme280.getHumidity();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  CurrentMillis = millis() ;
  if (CurrentMillis > NextMillis)
  {
    float tmp1 = getTemp();
    digitalWrite(LED_BUILTIN, LOW);
    //get and print temperatures
    Serial.print(" TmpDS = ");
    Serial.print(tmp1);
    Serial.print(" | TmpBME = ");
    Serial.print(Tmp);
    Serial.print(" | TmpDHT22 = ");
    Serial.print(t);
    Serial.print(" | HumBME = ");
    Serial.print(Hum);
    Serial.print(" | HumDHT22 = ");
    Serial.print(h);
    //get and print atmospheric pressure data
    Serial.print(" | PA = ");
    Serial.print(PA);
    float PR = PA +  (altitude / 8.3);
    Serial.print(" | PR = ");
    Serial.print(PR);
    Serial.println(" |");
    NextMillis = CurrentMillis + INTERVAL ;
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
  }
}
 
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
    Serial.println("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;
 
}
meteoduino/barometre.txt · Dernière modification: 14/07/2017 14:44 par michel
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5