More good progress to report...
My goal now is to get the Teensy to read an analog voltage and write it to the screen.
When the Teensy reads an analog signal, it has 1024 incremental steps it can express a voltage in. A value of 0 would correspond to 0 volts and a value of 1024 would correspond to 5 volts.
I combined a couple of pieces of code I found on the web...
The first was the piece of code that prints to the screen
FOUND HERE and shown in the previous post
Code:
void setup() {
Serial.begin(38400);
}
void loop()
{
Serial.println("Hello World");
delay(1000);
}
The next piece of code was
FOUND HERE that would read a voltage from a potentiometer.
Code:
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(9600); // setup serial
}
void loop()
{
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}
I combined them to look like this:
Code:
int analogPin = 38; // initialize Teensy pin 38 for input of analog voltage
//
int val = 0; // variable to store the value read set to zero
void setup() {
Serial.begin(38400);
}
void loop() //BEGIN LOOP
{
val = analogRead(analogPin); // read the Teensy input pin 38
Serial.println(val); // print val to serial monitor
delay(1000); // delay 1 second before repeating loop
} // END LOOP
My Teensy setup looked like this...
Here's a close up...
And when I compiled and ran code, this is what I got.
The voltage is just stray voltage, and when I got my hand close, the reading increased.
Next I hooked up the CO2 sensor's power and ground to the proto board, and ran the analog out wire from the sensor to the analog in pin on the Teensy.
So I ran the code and this is what I got...
There was a delay of several seconds after I exhaled, until the values rose on the serial monitor.
I have made no attempt to relate the values I am seeing to CO2 ppm.
But so far, it is a go!
Best,
-AC