Last active
December 24, 2019 08:27
-
-
Save ma2shita/ca0f2a7875714dbf5ce4580b64481506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* Measurement CO2 by S-300L-3V for Arduino UNO R3 */ | |
/* Output >> | |
Ready | |
862 | |
866 | |
871 | |
875 | |
877 | |
*/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial SerialUART(6, 7); // RX, TX | |
/* by S-300L: http://doc.switch-science.com/datasheets/ELT/User+Guide+for+U-ART+command+for+Low-Power+ver160719+cdg.pdf */ | |
uint16_t CO2ppm() { | |
while (!SerialUART.available()); /* wait max 3 seconds by spec (TODO: Timeout) */ | |
String buf = SerialUART.readStringUntil('\n'); /* separete char by spec */ | |
int pos = buf.lastIndexOf(" ppm"); /* Avoiding garbage in buffer */ | |
String v = buf.substring(pos - 6, pos); | |
return v.toInt(); | |
} | |
void setup() { | |
Serial.begin(115200); | |
SerialUART.begin(38400); | |
Serial.println("Ready"); | |
} | |
void loop() { | |
uint16_t ppm = CO2ppm(); | |
Serial.println(ppm); | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment