Last active
October 10, 2022 21:37
-
-
Save zoracon/26b597ad40e025d440cda6225ba7c5fe to your computer and use it in GitHub Desktop.
SCD30 with Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic demo for readings from Adafruit SCD30 | |
#include <Adafruit_SCD30.h> | |
#include <LiquidCrystal.h> | |
// Create an LCD object. Parameters: (RS, E, D4, D5, D6, D7): | |
//* Arduino example code for DHT11, DHT22/AM2302 and DHT21/AM2301 temperature and humidity sensors. More info: www.makerguides.com */ | |
LiquidCrystal lcd = LiquidCrystal(3, 4, 5, 6, 7, 8); | |
Adafruit_SCD30 scd30; | |
void setup(void) { | |
Serial.begin(115200); | |
// Specify the LCD's number of columns and rows. Change to (20, 4) for a 20x4 LCD: | |
lcd.begin(16, 2); | |
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens | |
Serial.println("Adafruit SCD30 test!"); | |
// Try to initialize! | |
if (!scd30.begin()) { | |
Serial.println("Failed to find SCD30 chip"); | |
while (1) { delay(10); } | |
} | |
Serial.println("SCD30 Found!"); | |
// if (!scd30.setMeasurementInterval(10)){ | |
// Serial.println("Failed to set measurement interval"); | |
// while(1){ delay(10);} | |
// } | |
Serial.print("Measurement Interval: "); | |
Serial.print(scd30.getMeasurementInterval()); | |
Serial.println(" seconds"); | |
} | |
void loop() { | |
if (scd30.dataReady()){ | |
Serial.println("Data available!"); | |
if (!scd30.read()){ Serial.println("Error reading sensor data"); return; } | |
Serial.print("Temperature: "); | |
Serial.print(scd30.temperature); | |
Serial.println(" degrees C"); | |
Serial.print("Relative Humidity: "); | |
Serial.print(scd30.relative_humidity); | |
Serial.println(" %"); | |
Serial.print("CO2: "); | |
Serial.print(scd30.CO2, 3); | |
Serial.println(" ppm"); | |
Serial.println(""); | |
// Read the humidity in %: | |
float h = scd30.relative_humidity; | |
// Read the C02 | |
float c = scd30.CO2; | |
lcd.setCursor(2, 0); | |
lcd.print("H:"); | |
lcd.print(h); | |
lcd.print(" % "); | |
lcd.setCursor(2, 1); | |
lcd.print("CO2:"); | |
lcd.print(c); | |
lcd.print("ppm"); | |
} else { | |
Serial.println("No data"); | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment