Advertisement
Guest User

Untitled

a guest
Oct 5th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.99 KB | None | 0 0
  1. // telecommande aquarium led centre ( 5592323 )
  2. // telecommande lumiere meuble tv ( on/off 1601921 ) gradateur (+ 1601924) (- 1601922 )
  3. // telecommande lumiere lit ( on/off 12612369 ) gradateur (+ 12612372) (- 12612370 )
  4. // telecommande desodirisant couloir ( on/off 1864065 ) gradateur (+ 1864068) (- 1864066 )
  5. //prise 1 on Received 4277585 / 24bit Protocol: 1
  6. //prize 1 off Received 4277588 / 24bit Protocol: 1
  7. //prize 2 on Received 4280657 / 24bit Protocol: 1
  8. //prize 2 off Received 4280660 / 24bit Protocol: 1
  9. //prise 3 on Received 4281425 / 24bit Protocol: 1
  10. //prize 3 off Received 4281428 / 24bit Protocol: 1
  11. //prise 4 on Received 4281617 / 24bit Protocol: 1
  12. //prize 4 off Received 4281620 / 24bit Protocol: 1
  13.  
  14. /*
  15. Arduino Masterbalby Controller
  16. sonde temps ds18B20 pin 13 = Température Sensor
  17. Analog Pin 0 = Température Sensor
  18. Digital Pin 6 = // la pin de connexion de mon emmeteur 433 mhz
  19. Digital Pin 12 = LCD
  20. Digital Pin 9 = LCD
  21. Digital Pin 5 = LCD
  22. Digital Pin 3 = LCD
  23. Digital Pin 2 = LCD
  24. Digital Pin 6 = 433 mhz
  25.  
  26. Digital Pin 10 = OutputLED1 //days
  27. Digital Pin 11 = OutputLED2 //moon
  28.  
  29. Branchement du module RTC DS1307
  30. - DS1307 -> Arduino
  31. - SDA -> Pin A4
  32. - SCL -> Pin A5
  33. - GND -> GND
  34. - VCC+ -> +5V
  35. */
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <Wire.h>
  40. #include <RTClib.h>
  41. #include <Time.h>
  42. #include <LiquidCrystal.h>
  43. #include <WProgram.h>
  44. #include <DS1307.h>
  45. #include <RCSwitch.h>
  46. #include <OneWire.h> // Inclusion de la librairie OneWire
  47. RCSwitch mySwitch = RCSwitch();
  48. RTC_DS1307 RTC;
  49.  
  50. //temperature ds18B20
  51. #define DS18B20 0x28 // Adresse 1-Wire du DS18B20
  52. #define BROCHE_ONEWIRE 13 // Broche utilisée pour le bus 1-Wire
  53.  
  54. OneWire ds(BROCHE_ONEWIRE); // Création de l'objet OneWire ds
  55.  
  56. // Fonction récupérant la température depuis le DS18B20
  57. // Retourne true si tout va bien, ou false en cas d'erreur
  58. boolean getTemperature(float *temp1){
  59. byte data[9], addr[8];
  60. // data : Données lues depuis le scratchpad
  61. // addr : adresse du module 1-Wire détecté
  62.  
  63. if (!ds.search(addr)) { // Recherche un module 1-Wire
  64. ds.reset_search(); // Réinitialise la recherche de module
  65. return false; // Retourne une erreur
  66. }
  67.  
  68. if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l'adresse a été correctement reçue
  69. return false; // Si le message est corrompu on retourne une erreur
  70.  
  71. if (addr[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
  72. return false; // Si ce n'est pas le cas on retourne une erreur
  73.  
  74. ds.reset(); // On reset le bus 1-Wire
  75. ds.select(addr); // On sélectionne le DS18B20
  76.  
  77. ds.write(0x44, 1); // On lance une prise de mesure de température
  78. delay(8); // Et on attend la fin de la mesure
  79.  
  80. ds.reset(); // On reset le bus 1-Wire
  81. ds.select(addr); // On sélectionne le DS18B20
  82. ds.write(0xBE); // On envoie une demande de lecture du scratchpad
  83.  
  84. for (byte i = 0; i < 9; i++) // On lit le scratchpad
  85. data[i] = ds.read(); // Et on stock les octets reçus
  86.  
  87. // Calcul de la température en degré Celsius
  88. *temp1 = ((data[1] << 8) | data[0]) * 0.0625;
  89.  
  90. // Pas d'erreur
  91. return true;
  92. }
  93.  
  94. //Définition de structure
  95.  
  96. struct Heure{
  97. int h;
  98. int m;
  99. };
  100.  
  101.  
  102. int minut;
  103. //int heure;
  104. int seconde;
  105. int date;
  106. int mois;
  107. int annee;
  108. int temps_perso = 0;
  109. int sensorPin = 0;
  110. int relais_pompe = 8;
  111. int OutputLED1 = 10;//allume rampe led 1 progressivement en fonction de l heure
  112. int OutputLED2 = 11;//allume rampe led 1 progressivement en fonction de l heure
  113. int heater_on_temp = 24; //allume chauffage à cette température
  114. int heater_off_temp = 26; //éteint le chauffage à cette température
  115.  
  116.  
  117.  
  118.  
  119. boolean isCode1Emitted= false;
  120. Heure heure_pompe_on={7,30};
  121. Heure heure_pompe_off={21,30};
  122.  
  123. Heure heure_emission_on={7,30};
  124. Heure heure_emission_off ={21,30};
  125.  
  126. Heure heure_OutputLED1_on={7,30};
  127. Heure heure_OutputLED1_off={21,30};
  128. unsigned int temps_allumage=10;//temps d'allumage pour le fading en minutes
  129.  
  130. Heure heure_OutputLED2_on={21,59};
  131. Heure heure_OutputLED2_off={7,30};
  132.  
  133. Heure heure={0,0};//contient l'heure actuelle
  134.  
  135.  
  136.  
  137.  
  138. LiquidCrystal lcd(12, 2, 5, 4, 3, 9);
  139.  
  140. void setup() {
  141.  
  142.  
  143. Serial.begin(9600);
  144. mySwitch.enableTransmit(6); // la pin de connexion de mon émetteur
  145. mySwitch.setProtocol(1); // le protocol (cf screenshot ci dessus, que je mets donc à 1)
  146. mySwitch.setRepeatTransmit(4); // nombre de répétitions du signal histoire d'être sur que la prise recevra le signal
  147. lcd.begin(16, 2);
  148. lcd.print("MasterBalby 2.1");
  149. lcd.setCursor(0, 1) ;
  150. lcd.print("Gestion Aqua");
  151. delay(1700);
  152. lcd.clear();
  153. lcd.print(" initialisation");
  154. delay(1700);
  155. lcd.clear();
  156. Wire.begin();
  157. RTC.begin();
  158. pinMode(OutputLED1, OUTPUT); // digital pin pour OutputLED1 en sortie
  159. pinMode(OutputLED2, OUTPUT); // digital pin pour OutputLED2 en sortie
  160. pinMode(relais_pompe, OUTPUT);
  161. digitalWrite(relais_pompe, LOW);
  162. // pinMode(moon_light_1, OUTPUT);
  163. // digitalWrite(moon_light_1, LOW);
  164. Serial.println("Start program");
  165. lcd.print("Start program");
  166. delay(2700);
  167. lcd.clear();
  168.  
  169.  
  170. //Récupérer l heure du DS1307 ********************************************************************
  171. if (! RTC.isrunning())
  172. {
  173. Serial.println("RTC is NOT running!");
  174. // following line sets the RTC to the date & time this sketch was compiled
  175. //RTC.adjust(DateTime(__DATE__, __TIME__));
  176. }
  177. }
  178. void displayTime(DateTime dateTime)
  179. {
  180. lcd.setCursor(0, 1);
  181. if (dateTime.hour() < 10) // Si les heure sont inférieur à 10
  182. {
  183. lcd.print ("0");
  184. }
  185. lcd.print(dateTime.hour(), DEC);
  186. lcd.print(':');
  187. if (dateTime.minute() <10) // Si les minute sont inférieurl à 10
  188. {
  189. lcd.print ("0");
  190. }
  191. lcd.print(dateTime.minute(), DEC);
  192. lcd.print(':');
  193. if (dateTime.second() < 10) // Si les second sont inférieurl à 10
  194. {
  195. lcd.print ("0");
  196. }
  197. lcd.print(dateTime.second(), DEC);
  198. lcd.print(' ');
  199. temps_perso = dateTime.hour()*60 + dateTime.minute(); // Mise à jour de temps_perso
  200. heure.h=dateTime.hour();//mise à jour de l'heure
  201. heure.m=dateTime.minute();
  202.  
  203. }
  204.  
  205.  
  206. //Affichage température DS18B20***************************************************************************
  207.  
  208. void displayTemperature1(int temp1)
  209. {
  210. lcd.setCursor(8, 0);
  211. lcd.print("Temp:");
  212. lcd.print(temp1);
  213. lcd.println("C");
  214. lcd.print(' ');
  215. delay(20);
  216. }
  217.  
  218. void Afficher_statut(){
  219. Serial.print("Time= ");
  220. Serial.print(heure.h);
  221. Serial.print("H");
  222. if(heure.m<10)
  223. {
  224. Serial.print(0);
  225. }
  226. Serial.print(heure.m);
  227. Serial.print(" isCode1Emitted= ");
  228. Serial.println(isCode1Emitted);
  229. }
  230.  
  231. void programmer_moon(){
  232. boolean allumage_necessaire(false);
  233.  
  234. allumage_necessaire |= heure.h>=heure_pompe_on.h && heure.m>=heure_pompe_on.m;
  235. allumage_necessaire &= heure.h<=heure_pompe_off.h && heure.m<=heure_pompe_off.m;
  236.  
  237. digitalWrite(relais_pompe, !allumage_necessaire);
  238. }
  239.  
  240.  
  241. //Calcule la valeur à envoyer à une led pour l'allumer en fading
  242. unsigned int allumage_progressif(unsigned int h_on,unsigned int m_on, unsigned int h_off,unsigned int m_off, unsigned long const& temps_allumage){
  243. unsigned int consigne = 0;//contient la valeur à envoyer à la PWM
  244.  
  245. //contient le nombre de secondes écoulées depuis minuit, c'est à dire l'heure actuelle en secondes
  246. unsigned long t(heure.h);
  247. t*=3600;
  248. t+=heure.m*60+RTC.now().second();
  249. Serial.print("Heure actuelle= ");
  250. Serial.print(t);
  251. //contient l'heure de démarrage de la led1 en secondes
  252. unsigned long t_on=h_on;
  253. t_on*=3600;
  254. t_on+=m_on*60;
  255. Serial.print(" t_on= ");
  256. Serial.print(t_on);
  257. //contient l'heure d'extinction de la led1 en secondes
  258. unsigned long t_off=h_off;
  259. t_off*=3600;
  260. t_off+=m_off*60;
  261. Serial.print(" t_off= ");
  262. Serial.print(t_off);
  263. if (t>=t_on && t<=t_off)
  264. {
  265. if (t<(t_on+temps_allumage*60)){
  266. consigne = int(((t-t_on)*255)/(temps_allumage*60));//on gère l'allumage en linéaire
  267. }
  268. else if (t<(t_off-temps_allumage*60)){
  269. consigne= 255;
  270. }
  271. else {
  272. float p = float(t-(t_off-temps_allumage*60))/float(temps_allumage*60);
  273. Serial.print(" p= ");
  274. Serial.print(p);
  275. consigne=int((1-p)*255.0);
  276. }
  277. }
  278. Serial.print(" Consigne= ");
  279. Serial.println(consigne);
  280. return consigne;
  281. }
  282.  
  283. void loop() {
  284. //Afficher_statut();
  285.  
  286.  
  287. //Affichage temps*****************************************************************************
  288. displayTime(RTC.now());
  289.  
  290. //Affichage température***********************************************************************
  291. // displayTemperature(temp);
  292.  
  293. //Affichage température ds18B20***********************************************************************
  294. float temp1;
  295.  
  296. // Lit la température ambiante à ~1Hz
  297. if(getTemperature(&temp1))
  298. {
  299. displayTemperature1(temp1);
  300. }
  301. //programation relais**************************************************************************
  302.  
  303. programmer_moon();
  304.  
  305.  
  306. //programation emission on led central **************************************************************************
  307. //Serial.print("emission_on : ") ;
  308. //Serial.println(emission_on);
  309. if((heure.h==heure_emission_on.h) && (heure.m==heure_emission_on.m) && !isCode1Emitted)
  310. {
  311. Serial.print("On entre dans le premier if emission et isCode1Emitted = ");
  312. Serial.println(isCode1Emitted);
  313. mySwitch.send(4277585, 24); // on allume la pompe en envoyant le bon signal lu via l'emeteur
  314. delay(20);
  315. mySwitch.send(5592323, 24); // on allume les led en envoyant le bon signal lu via l'emeteur
  316. isCode1Emitted= true;//
  317. Serial.print("On sort du premier if et isCode1Emitted = ");
  318. Serial.println(isCode1Emitted);
  319.  
  320. }
  321.  
  322. //programation emission off led central **************************************************************************
  323.  
  324. if((heure.h==heure_emission_off.h) && (heure.m ==heure_emission_off.m) && isCode1Emitted)
  325. {
  326. Serial.print("On entre dans le deuxième if emission et isCode1Emitted = ");
  327. Serial.println(isCode1Emitted);
  328. mySwitch.send(5592323, 24); // on allume les led en envoyant le bon signal lu via l'emeteur
  329. delay(20);
  330. mySwitch.send(4277588, 24); // on eteint la pompe en envoyant le bon signal lu via l'emeteur
  331. isCode1Emitted= false;
  332. Serial.print("On sort du deuxième if et isCode1Emitted = ");
  333. Serial.println(isCode1Emitted);
  334. }
  335.  
  336.  
  337.  
  338. //****************Day Lights**********************************************************************************
  339.  
  340. analogWrite(OutputLED1,allumage_progressif(heure_OutputLED1_on.h,heure_OutputLED1_on.m,heure_OutputLED1_off.h,heure_OutputLED1_off.m,temps_allumage));//
  341.  
  342.  
  343. //****************Moon Lights**********************************************************************************
  344.  
  345. analogWrite(OutputLED2,allumage_progressif(heure_OutputLED2_on.h,heure_OutputLED2_on.m,heure_OutputLED2_off.h,heure_OutputLED2_off.m,temps_allumage));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement