|
| 1 | +/* |
| 2 | + Reading CO2, humidity and temperature from the SCD30 |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: May 22nd, 2018 |
| 6 | + License: MIT. See license file for more information but you can |
| 7 | + basically do whatever you want with this code. |
| 8 | +
|
| 9 | + Feel like supporting open source hardware? |
| 10 | + Buy a board from SparkFun! https://www.sparkfun.com/products/15112 |
| 11 | +
|
| 12 | + This example turns off the auto-calibrate function during .begin() |
| 13 | +
|
| 14 | + Hardware Connections: |
| 15 | + Attach RedBoard to computer using a USB cable. |
| 16 | + Connect SCD30 to RedBoard using Qwiic cable. |
| 17 | + Open Serial Monitor at 115200 baud. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include <Wire.h> |
| 21 | + |
| 22 | +#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30 |
| 23 | +SCD30 airSensor; |
| 24 | + |
| 25 | +void setup() |
| 26 | +{ |
| 27 | + Serial.begin(115200); |
| 28 | + Serial.println("SCD30 Example"); |
| 29 | + Wire.begin(); |
| 30 | + |
| 31 | + //Start sensor using the Wire port, but disable the auto-calibration |
| 32 | + if (airSensor.begin(Wire, false) == false) |
| 33 | + { |
| 34 | + Serial.println("Air sensor not detected. Please check wiring. Freezing..."); |
| 35 | + while (1) |
| 36 | + ; |
| 37 | + } |
| 38 | + |
| 39 | + //The SCD30 has data ready every two seconds |
| 40 | +} |
| 41 | + |
| 42 | +void loop() |
| 43 | +{ |
| 44 | + if (airSensor.dataAvailable()) |
| 45 | + { |
| 46 | + Serial.print("co2(ppm):"); |
| 47 | + Serial.print(airSensor.getCO2()); |
| 48 | + |
| 49 | + Serial.print(" temp(C):"); |
| 50 | + Serial.print(airSensor.getTemperature(), 1); |
| 51 | + |
| 52 | + Serial.print(" humidity(%):"); |
| 53 | + Serial.print(airSensor.getHumidity(), 1); |
| 54 | + |
| 55 | + Serial.println(); |
| 56 | + } |
| 57 | + else |
| 58 | + Serial.println("Waiting for new data"); |
| 59 | + |
| 60 | + delay(500); |
| 61 | +} |
0 commit comments