Bonjour
J'aurai besoin d'aide pour fusionner 2 codes.
je suis débutant ses mon premiers Arduino je souhaite l'utiliser pour des capteurs pour l'hydroponie PH EC T° etc.
Là où je bloque ses pour le PH le code seul fonctionne mais dès que je veux l'ajouter à l'autre code la valeur indiquer n'est pas la bonne .
Mon niveau est zero pour faire du code ses pour ça que je demande votre aide.
code fonctionnel sans code PH
//
- DHT 2302
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
// Date and time DS3231 RTC
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
//ec meter
#include <OneWire.h>
#include <DallasTemperature.h>
//************************* User Defined Variables ********************************************************//
int R1= 1000;
int Ra=25; //Resistance of powering Pins
int ECPin= A0;
int ECGround=A1;
int ECPower =A4;
//*********** Converting to ppm [Learn to use EC it is much better**************//
float PPMconversion=0.5;
//*************Compensating for temperature ************************************//
float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring
//********************** Cell Constant For Ec Measurements *********************//
float K=13.23;
//************ Temp Probe Related *********************************************//
#define ONE_WIRE_BUS 10 // Data wire For Temp Probe is plugged into pin 10 on the Arduino
const int TempProbePossitive =8; //Temp Probe power connected to pin 9
const int TempProbeNegative=9; //Temp Probe Negative connected to pin 8
OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
float Temperature=10;
float EC=0;
float EC25 =0;
int ppm =0;
float raw= 0;
float Vin= 5;
float Vdrop= 0;
float Rc= 0;
float buffer=0;
void setup()
{
// - DHT 2302
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor"));
delay(10);
// Date and time DS3231 RTC
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
delay(500); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
delay(10);
}
//ec meter
Serial.begin(9600);
pinMode(TempProbeNegative , OUTPUT); //seting ground pin as output for tmp probe
digitalWrite(TempProbeNegative , LOW); //Seting it to ground so it can sink current
pinMode(TempProbePossitive , OUTPUT); //ditto but for positive
digitalWrite(TempProbePossitive , HIGH);
pinMode(ECPin,INPUT);
pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
pinMode(ECGround,OUTPUT);//setting pin for sinking current
digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly
delay(100);// gives sensor time to settle
sensors.begin();
delay(100);
//** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
// Consule Read-Me for Why, or just accept it as true
R1=(R1+Ra);// Taking into acount Powering Pin Resitance
Serial.println("Arduino EC-PPM measurments");
}
void loop(void)
{
// Date and time DS3231 RTC
DateTime now = rtc.now();
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(500);
// - DHT 2302
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature Ext: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity Ext: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
delay(500);
}
{
//ec meter
GetEC(); //Calls Code to Go into GetEC() Loop [Below Main Loop] dont call this more that 1/5 hhz [once every five seconds] or you will polarise the water
PrintReadings(); // Cals Print routine [below main loop]
delay(5000);
}
}
void GetEC()
{
sensors.requestTemperatures(); // Send the command to get temperatures
Temperature=sensors.getTempCByIndex(0); //Stores Value in Variable
//************Estimates Resistance of Liquid ****************//
digitalWrite(ECPower,HIGH);
raw= analogRead(ECPin);
raw= analogRead(ECPin);// This is not a mistake, First reading will be low beause if charged a capacitor
digitalWrite(ECPower,LOW);
//***************** Converts to EC **************************//
Vdrop= (Vin*raw) / 1024.0;
Rc = (Vdrop*R1) / (Vin-Vdrop);
Rc = Rc-Ra; //acounting for Digital Pin Resitance
EC = 1000/ (Rc*K);
//*************Compensating For Temperaure********************//
EC25 = EC / (1+ TemperatureCoef*(Temperature-25.0));
ppm=(EC25)*(PPMconversion*1000);
}
//***This Loop Is called From Main Loop- Prints to serial usefull info ***//
void PrintReadings()
{
Serial.print("Rc: ");
Serial.print(Rc);
Serial.print(" EC: ");
Serial.print(EC25);
Serial.print(" Simens ");
Serial.print(ppm);
Serial.print(" ppm ");
Serial.print(Temperature);
Serial.println(" *C ");
};