Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Temperature and humidity
- *
- * This example demonstrates the use of the Si7021 temperature and
- * humidity sensor. It measures the temperature and the humidity,
- * and prints them on the serial console every second.
- * Before use, the sensor must be powered using pin 7. The sensor
- * measurements are then read using the Sodaq_SHT2x library.
- */
- #include <Sodaq_SHT2x.h> // provides sensor protocol
- #include <Wire.h> // provides communication channel
- #define powerPin 7 // sensor power controlled by pin 7
- // runs once, when the sketch starts
- void setup()
- {
- // power sensors, control is inverted, on when low
- pinMode(powerPin, OUTPUT);
- digitalWrite(powerPin, LOW);
- Wire.begin(); // init sensor communication channel
- Serial.begin(9600); // init serial console for display
- }
- // runs over and over again
- void loop()
- {
- // get and print temperature in degrees Celsius
- float temp = SHT2x.GetTemperature();
- Serial.print("\nTemperature (C): ");
- Serial.print(temp);
- // get and print relative humidity in %
- float hum = SHT2x.GetHumidity();
- Serial.print("\tHumidity (%RH): ");
- Serial.print(hum);
- delay(1000); // wait for 1 second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement