AbstractBeliefs

Untitled

Feb 19th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #define ONE_WIRE_BUS 2  // 1-wire pin
  4. #include <DHT.h>
  5. #define DHTPIN 3     // DHT pin
  6. #define DHTTYPE DHT22   // DHT 11/22?
  7.  
  8. DHT dht(DHTPIN, DHTTYPE);
  9. OneWire oneWire(ONE_WIRE_BUS);
  10.  
  11. // Pass our oneWire reference to Dallas Temperature.
  12. DallasTemperature sensors(&oneWire);
  13. int anturit = sensors.getDeviceCount();
  14.  
  15. // LDR
  16. const int ldrPin = A0;
  17. int ldr = 0;
  18.  
  19.  
  20. // SETUP ---------------------------------------------
  21. void setup() {                                
  22.     dht.begin(); // DHT
  23.     sensors.begin();  //1-wire
  24.     Serial.begin(9600);
  25.     delay(1000);
  26. }                                            
  27. //SETUP -----------------------------------------------
  28.  
  29.  
  30. void loop() {
  31.     // While theres no 'r'equest, do nothing
  32.     while (Serial.read() != 'r'){}
  33.    
  34.     // Theres been a request, so lets take readings
  35.     ldr = analogRead(ldrPin);
  36.  
  37.     int h = dht.readHumidity();
  38.     int t = dht.readTemperature();
  39.  
  40.  
  41.     // call sensors.requestTemperatures() to issue a global temperature
  42.     // request to all devices on the bus
  43.     sensors.requestTemperatures(); // Send the command to get temperatures
  44.     delay(750);
  45.     float anturi1 = sensors.getTempCByIndex(0);
  46.     float anturi2 = sensors.getTempCByIndex(1);
  47.  
  48.     // and send them back
  49.     Serial.print(anturi1);
  50.     Serial.print("\n");
  51.     Serial.print(anturi2);
  52.     Serial.print("\n");
  53.     Serial.print(ldr);
  54.     Serial.print("\n");
  55.    
  56.     //dht
  57.     Serial.print(h);
  58.     Serial.print("\n");
  59.     Serial.print(t);
  60.     Serial.print("\n");
  61.    
  62.     // We're done, write 255.
  63.     Serial.write(255);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment