Advertisement
Guest User

Untitled

a guest
May 4th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /**
  2. * Temperature and humidity
  3. *
  4. * This example demonstrates the use of the Si7021 temperature and
  5. * humidity sensor. It measures the temperature and the humidity,
  6. * and prints them on the serial console every second.
  7. * Before use, the sensor must be powered using pin 7. The sensor
  8. * measurements are then read using the Sodaq_SHT2x library.
  9. */
  10. #include <Sodaq_SHT2x.h> // provides sensor protocol
  11. #include <Wire.h> // provides communication channel
  12.  
  13. #define powerPin 7 // sensor power controlled by pin 7
  14.  
  15. // runs once, when the sketch starts
  16. void setup()
  17. {
  18. // power sensors, control is inverted, on when low
  19. pinMode(powerPin, OUTPUT);
  20. digitalWrite(powerPin, LOW);
  21.  
  22. Wire.begin(); // init sensor communication channel
  23.  
  24. Serial.begin(9600); // init serial console for display
  25. }
  26.  
  27. // runs over and over again
  28. void loop()
  29. {
  30. // get and print temperature in degrees Celsius
  31. float temp = SHT2x.GetTemperature();
  32. Serial.print("\nTemperature (C): ");
  33. Serial.print(temp);
  34.  
  35. // get and print relative humidity in %
  36. float hum = SHT2x.GetHumidity();
  37. Serial.print("\tHumidity (%RH): ");
  38. Serial.print(hum);
  39.  
  40. delay(1000); // wait for 1 second
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement