// Mesure des gaz

#include <Wire.h>
#include <dht.h>
#include <FileIO.h>

#define led 13
#define DHT11PIN 8
#define pwmPin 7
dht1wire DHT(DHT11PIN, dht::DHT11);

String data ="";

void setup()
{
// Initialize the Bridge and the Serial
Bridge.begin();
delay(2000);

Serial.begin(9600);


FileSystem.begin();
delay(2000);
pinMode(led,OUTPUT);

pinMode(pwmPin, INPUT);

}

void loop()
{
//float pinA0 = analogRead(A0)*24.44+400;
//int co2= pinA0;

float pinA3 = analogRead(A3);
int co= pinA3;
data = co;

unsigned long th = pulseIn(pwmPin, HIGH, 3000000); // use microseconds
unsigned long tl = pulseIn(pwmPin, LOW, 3000000);
//tpwm = th + tl; // actual pulse width
//Serial.println("PWM-time: ");
//Serial.println(th);
//Serial.println(tl);

//Serial.println(" us");

unsigned long co3 = 5000*(th-2000)/(th+tl-4000);
//Serial.println(co3);
data += ",";
data += co3;


//Serial.println(co2);
//Serial.println(co);
//analogWrite(A3, HIGH);
// delay(50); // Getting an analog read apparently takes 100uSec
//pinA3 = analogRead(A3);
//Serial.println(pinA3);


unsigned long b = micros();

dht::ReadStatus chk = DHT.read();
unsigned long e = micros();

Serial.print(F("\nRead sensor: "));
switch (chk)
{
case dht::OK:
Serial.print(F("OK, took "));
Serial.print (e - b); Serial.println(F(" usec"));
break;
case dht::ERROR_CHECKSUM:
Serial.println(F("Checksum error"));
break;
case dht::ERROR_TIMEOUT:
Serial.println(F("Timeout error"));
break;
case dht::ERROR_CONNECT:
Serial.println(F("Connect error"));
break;
case dht::ERROR_ACK_L:
Serial.println(F("AckL error"));
break;
case dht::ERROR_ACK_H:
Serial.println(F("AckH error"));
break;
default:
Serial.println(F("Unknown error"));
break;
}

//Serial.print(F("Humidity (%): "));
int humi = DHT.getHumidity();
//Serial.println(humi);

//Serial.print(F("Temperature (°C): "));
int temp = DHT.getTemperature();
data += ",";
data += humi/10;
data += ",";
data += temp/10;

//Serial.println(temp);

//Serial.print(F("Dew Point (°C): "));
//Serial.println(DHT.dewPoint());

Serial.println(data);

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// The FileSystem card is mounted at the following "/mnt/FileSystema1"
File dataFile = FileSystem.open("/mnt/sd/data.txt", FILE_APPEND);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(data);
dataFile.close();

// print to the serial port too:

digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);

}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}



delay(15000);
data="";
}

En poursuivant votre navigation sur mon site, vous acceptez l’utilisation des Cookies et autres traceurs  pour réaliser des statistiques de visites et enregistrer sur votre machine vos activités pédagogiques. En savoir plus.