Lukas4186

Wetterstation

Feb 8th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.10 KB | None | 0 0
  1. //Empfänger:
  2. #include <Wire.h>
  3. #include <DS1307new.h>                  
  4.  
  5. #include <LiquidCrystal.h>
  6.  
  7. #include <SPI.h>
  8. #include <nRF24L01.h>
  9. #include <RF24.h>
  10.  
  11.  
  12. #define CE_PIN   9
  13. #define CSN_PIN 10
  14. const uint64_t pipe = 0xE8E8F0F0E1LL;
  15. RF24 radio(CE_PIN, CSN_PIN);
  16. int werte[2];
  17.  
  18. uint16_t startAddr = 0x0000;            
  19. uint16_t lastAddr;                      
  20. uint16_t TimeIsSet = 0xaa55;            
  21.  
  22. LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
  23.  
  24.  
  25. void setup()
  26. {
  27.   pinMode(2, INPUT);                    
  28.   digitalWrite(2, HIGH);                
  29.  
  30.   Serial.begin(9600);
  31.   lcd.begin(16, 2);
  32.  
  33.   void powerUpRx(void);
  34.   radio.begin();
  35.   radio.openReadingPipe(1,pipe);
  36.   radio.startListening();;
  37.  
  38.  
  39.   RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// Store startAddr in NV-RAM address 0x08
  40.  
  41. // Zum ändern der eingestellten Zeit folgende 2 Zeilen wieder "wirksam" machen
  42. //TimeIsSet = 0xffff;
  43. //RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));  
  44.  
  45.   RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
  46.   if (TimeIsSet != 0xaa55)
  47.   {
  48.     RTC.stopClock();
  49.     RTC.fillByYMD(2015,2,7);
  50.     RTC.fillByHMS(23,36,0);
  51.     RTC.setTime();
  52.     TimeIsSet = 0xaa55;
  53.     RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
  54.     RTC.startClock();
  55.   }
  56.   else
  57.   {
  58.     RTC.getTime();
  59.   }
  60.  
  61.   RTC.ctrl = 0x00;                      
  62.                                        
  63.   RTC.setCTRL();
  64.   Serial.println("DS1307 Testsketch");
  65.   Serial.println("Format is \"hh:mm:ss dd-mm-yyyy DDD\"");
  66.   uint8_t MESZ;
  67.   MESZ = RTC.isMEZSummerTime();
  68.   Serial.print("MEZ=0, MESZ=1 : ");
  69.   Serial.println(MESZ, DEC);    
  70.   Serial.println();
  71. }
  72.  
  73.  
  74. void loop()
  75. {
  76.   RTC.getTime();
  77.   {
  78.      lcd.clear();
  79.      lcd.setCursor(0, 0);
  80.      lcd.print(RTC.hour, DEC);
  81.      lcd.print(":");
  82.      lcd.print(RTC.minute, DEC);
  83.      lcd.print(":");
  84.      lcd.print(RTC.second, DEC);
  85.      lcd.setCursor(10, 0);
  86.      lcd.print(RTC.day, DEC);
  87.      lcd.print("-");
  88.      lcd.print(RTC.month, DEC);
  89.      lcd.print("-");
  90.      lcd.print(RTC.year - 2000, DEC);
  91.      
  92.   if ( radio.available() )
  93.   {
  94.     bool done = false;
  95.     while (!done)
  96.     {
  97.      done = radio.read( werte, sizeof(werte) );
  98.      lcd.setCursor(0, 1);
  99.      lcd.print("Lux=");
  100.      lcd.setCursor(4, 1);
  101.      lcd.print(werte[0]);
  102.      lcd.setCursor(11, 1);
  103.      lcd.print(werte[1]);
  104.      lcd.print("C");    
  105.    }
  106.   }
  107.       else
  108.       {
  109.       Serial.println("Kein Signal vorhanden");
  110.       lcd.setCursor(0, 1);
  111.       lcd.print("No Signal!");
  112.       }
  113.  }
  114.  
  115.   Serial.print(" seconds since 1.1.2000:");
  116.   Serial.print(RTC.time2000, DEC);
  117.   uint8_t MESZ = RTC.isMEZSummerTime();
  118.   Serial.print(" MEZ=0, MESZ=1 : ");
  119.   Serial.print(MESZ, DEC);  
  120.    
  121.   Serial.print(" - Address in NV-RAM is: ");
  122.   RTC.getRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
  123.   Serial.print(lastAddr, HEX);
  124.   lastAddr = lastAddr + 1;              
  125.   RTC.setRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
  126.   RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
  127.   if (TimeIsSet == 0xaa55)              
  128.   {
  129.     Serial.println(" - Clock was set!");
  130.   }
  131.   else
  132.   {
  133.     Serial.println(" - Clock was NOT set!");
  134.   }    
  135.   delay(1000);                          
  136. }
  137.  
  138. //Sender:
  139. #include <SPI.h>
  140. #include <nRF24L01.h>
  141. #include <RF24.h>
  142.  
  143. #include <Wire.h>
  144. #include <BH1750.h>
  145.  
  146. #define CE_PIN   9
  147. #define CSN_PIN 10
  148. const uint64_t pipe = 0xE8E8F0F0E1LL;
  149. RF24 radio(CE_PIN, CSN_PIN);
  150.  
  151. int sensorPin = 0;
  152.  
  153. BH1750 lightMeter;
  154.  
  155. int werte[2];
  156.  
  157. void setup(){
  158.   Serial.begin(9600);
  159.   lightMeter.begin();
  160.   void powerUpTx(void);
  161.   radio.begin();
  162.   radio.openWritingPipe(pipe);
  163. }
  164.  
  165.  
  166. void loop() {
  167.   uint16_t lux = lightMeter.readLightLevel();
  168.   int reading = analogRead(sensorPin);
  169.   float voltage = reading * 5.0;
  170.   voltage /= 1024.0;
  171.   float temperatureC = (voltage - 0.5) * 100;
  172.  
  173.   {
  174.   Serial.print("Temperatur = ");
  175.   Serial.print(temperatureC);
  176.   Serial.print("Light: ");
  177.   Serial.print(lux);
  178.   Serial.println(" lx");
  179.   }
  180.  
  181.   werte[0] = (lux);
  182.   werte[1] = (temperatureC);
  183.  
  184.   radio.write( werte, sizeof(werte)) ;
  185.  
  186. }
Advertisement
Add Comment
Please, Sign In to add comment