Bonjour à tous,
Je travaille sur un projet de potager connecté avec un arrosage automatique et la gestion d'une lampe de croissance calé sur le levé et couché du soleil (pas de lumiere du jour à l'endroit ou sera installé le potager).
Materiel :
- Arduino Uno
- Relais lumiere
- Relais pompe
- module RTC 1302
- bibliotheque Wire
- bibliotheque RTC lib
- bibliotheque ephemeris
allumage et extinction des relais ok mais je ne parviens pas à declencher le relais lumiere en me calant sur l'horaire de levé du soleil fourni par ephemeris.
Ma demarche est la suivante :
Si l'heure RTC est superieur ou egale à l'horaire "levé du soleil" alors allume le relais lumiere.
puis
Si l'heure RTC est superieur ou egale à l'heure "couché du soleil" alors eteint le relais lumiere.
novice dans le développement, je ne parviens pas à mettre tout ca en place... Si vous avez quelques pistes ou conseils, je suis preneur
Merci d'avance
#include <Wire.h> // bibliotheque Wire (RTC)
#include "RTClib.h" //bibliotheque module RTC
#include <Ephemeris.h> // bibliotheque ephemeris
RTC_DS1307 rtc;
int PinHumidite = 0; // capteur d'humidité.
int humid; // variable humidité
int pinRelais = 4; //variable pour le pin qui commande le relais
//debut ephemeris
void printDate(int day, int month, int year)
{
Serial.print(day);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
}
void printRiseAndSet(char *city, FLOAT latitude, FLOAT longitude, int UTCOffset, int day, int month, int year, char *ref)
{
Ephemeris::setLocationOnEarth(latitude, longitude);
Serial.print(city);
Serial.print(" (UTC");
if ( UTCOffset >= 0 )
{
Serial.print("+");
}
Serial.print(UTCOffset);
Serial.print(")");
Serial.println(":");
SolarSystemObject sun = Ephemeris::solarSystemObjectAtDateAndTime(Sun,
day, month, year,
0, 0, 0);
// Print sunrise and sunset if available according to location on Earth
if ( sun.riseAndSetState == RiseAndSetOk )
{
int hours, minutes;
FLOAT seconds;
// Convert floating hours to hours, minutes, seconds and display.
Ephemeris::floatingHoursToHoursMinutesSeconds(Ephemeris::floatingHoursWithUTCOffset(sun.rise, UTCOffset), &hours, &minutes, &seconds);
Serial.print(" Sunrise: ");
Serial.print(hours);
Serial.print("h");
Serial.print(minutes);
Serial.print("m");
Serial.print(seconds, 0);
Serial.println("s");
// Convert floating hours to hours, minutes, seconds and display.
Ephemeris::floatingHoursToHoursMinutesSeconds(Ephemeris::floatingHoursWithUTCOffset(sun.set, UTCOffset), &hours, &minutes, &seconds);
Serial.print(" Sunset: ");
Serial.print(hours);
Serial.print("h");
Serial.print(minutes);
Serial.print("m");
Serial.print(seconds, 0);
Serial.println("s");
}
else if ( sun.riseAndSetState == LocationOnEarthUnitialized )
{
Serial.println("You must set your location on Earth first.");
}
else if ( sun.riseAndSetState == ObjectAlwaysInSky )
{
Serial.println("Sun always in sky for your location.");
}
else if ( sun.riseAndSetState == ObjectNeverInSky )
{
Serial.println("Sun never in sky for your location.");
}
Serial.print(" Ref: ");
Serial.println(ref);
Serial.println();
}
//fin ephemeris
void setup() {
// debut mise en place du temps
while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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));
}
// fin mise en place du temps
// debut temps en test
DateTime now = rtc.now();
DateTime heureRTC;
uint8_t heureAlarme = 13;
uint8_t minuteAlarme = 54;
uint16_t jourAlarme = 21;
uint16_t moisAlarme = 3;
heureRTC = rtc.now();
if (heureRTC.hour() == heureAlarme && heureRTC.minute() == minuteAlarme && heureRTC.day() == jourAlarme && heureRTC.month() == moisAlarme) {
digitalWrite(13, HIGH);
Serial.print("fonctionne !!");
} else {
digitalWrite(13, HIGH);
}
Serial.println();
delay(1000);
// fin temps en test
//debut ephemeris
{
Serial.begin(9600);
int day = heureRTC.day(), month = heureRTC.month(), year = heureRTC.year();
Serial.print("SunRise/SunSet at ");
printDate(day, month, year);
Serial.println(":\n");
// CITY LATITUDE LONGITUDE TZ DATE REFERENCE
printRiseAndSet("Paris", 48.856614, 2.3522219, +1, day, month, year, "sunearthtools (10/2/2017): SunRise: 08:07:00 | SunSet: 18:03:19");
}
//fin ephemeris
pinMode(pinRelais, OUTPUT); //pin lampe en mode OUTPUT
Serial.begin(9600);
pinMode(PinHumidite, INPUT); // capteur
pinMode(2, OUTPUT); // relais
digitalWrite(2, LOW); // pompe off
}
void loop() {
// arrosage
humid = analogRead(PinHumidite); // lecture capteur humidité
Serial.println(humid); //affichage humidité
if (humid < 800) // si sol sec (eau : 860, air : 0, terre "à arroser" : 840 terre seche : 185 )
{
digitalWrite(2, HIGH); // allumage pompe
Serial.println("pompe arrosage on");
delay(1000); // arrosage 10 secondes
digitalWrite(2, LOW); // arret pompe
Serial.println("pompe off");
}
// allumage de la lampe
digitalWrite(pinRelais, HIGH); // on commande l'allumage
Serial.println("lumiere on");
delay(3000);
digitalWrite(pinRelais, LOW); // on commande l'extinction
Serial.println("lumiere off");
delay(1000);
Serial.println("pause");
delay(1000); // pause 10mns le temps que l'eau se diffuse autour du capteur
//delay(1000); // pause
}