Skip to content

Instantly share code, notes, and snippets.

Created Apr 11, 2018
What would you like to do?
Barebones sketch to read an analog voltage between 0 and 100mV.
An internal reference voltage of 1.1v is used to scale the digital conversion.
The maximum output of the HCHO sensor (100mV) is converted to a value of 103.
This value of 103 should equal a reading of 1000ppb HCHO.
int analogPin = 3; // Tip of output HCHO sensor jack connected to analog pin 3
// Ring of HCHO sensor connector connected to GND
int voltRaw = 0; // variable to store the sensor value read
int ppbHCHO = 0; // variable to store a result
void setup()
analogReference(INTERNAL); // Set analog reference to 1.1 volts
Serial.begin(9600); // setup serial
void loop()
voltRaw = analogRead(analogPin); // read the input pin
ppbHCHO = voltRaw*10; // scale the result between 0 and 1023
Serial.print("Value between 0 and 103: "); // Print to serial monitor
Serial.println(voltRaw); // this is the conversion of the analog voltage to a digital number
Serial.print("Value between 0 and 1023");
Serial.println(ppbHCHO); // This might approximate ppb
delay(3000); // take a reading and print to the serial monitor every 3 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment