Hi there, I am using this sensor with a Seeeduino Xiao and expansion board but am struggling to convert the information provided in the datasheets (application notes) into code, I am new to coding so any information to put me in the right direction is greatly appreciated. Cheers
Currently, I am just trying to use an interrupt to make a 4HZ squarewave at 50% duty cycle, to test this I am using an LED with it terminated to pin 10 and gnd. As I've said before I am new to coding and I am not too sure the best way to do interrupts so this is what I have got so far but as you can see it is not producing a square wave when it is "ON"
There is no reason to use an interrupt, as doing so usually causes more problems than it solves. You have already broken at least one rule: variables shared with interrupt routines (e.g. isSensor1On) must be declared volatile.
Why do you need a 4 Hz squarewave? The loop function can do this effortlessly. Here are two ways of doing so.
That flow chart is simply one person's suggestion for how to proceed. No interrupt is required.
With most microcontrollers, a timer can be configured to automatically generate 4 Hz on certain I/O pins, without any need for the processor to be involved.
But in this case, you don't even need a separate timer. I've already showed you how to generate the 4 Hz in loop() (using the millisecond timer), with plenty of CPU time left over to do all the rest of the things in that flow chart.
To elaborate:
void loop() {
if (millis()-timer >= 125) { //this if clause takes a couple of microseconds to execute
digitalWrite(10,ledstate); //4 Hz lamp blink
ledstate = !ledstate;
timer=millis();
}
// here, do all the rest of the decision making and computing
}
That doesn't have a socket for the linked sensor or any circuitry to support it. So there must be another board you use to connect the sensor to the MCU.
Thank you this works, Now how would I go about taking readings from the IR lamps at 125ms intervals. they are analog waves and it specifies to take reading when it is at max and min.
If you just have the naked detector, you will need an appropriate socket or connectors (as mentioned above) and some support electronics.
The Arduino cannot directly drive the lamp, and it cannot accurately measure the small voltages (25 mV) at the signal output. So, you need a lamp driver and signal amplifier.
Also, the signal is not simply related to the CO2 concentration, and that will require some computing. The corrections require that you know the temperature as well.
What is your plan for all of that?
There are several documents in this link, explaining all of the above in detail. Please study them carefully: Application notes
I have been reading the application notes and in "Infrared Sensor Application Note 4
Design of Electronics for Infrared Gas Sensors" states that it can be generated by a microprocessor with a crystal reference, and the seeeduino xiao has a 32,768Hz crystal installed so I thought that I could use this to drive the IR lamps. If not can you explain how this should be done as I have no idea, and yes I plan to use a MOSFET or op-amp to amplify the signals, and i also will be using an external thermocouple as my temperature reference. I am new to electronics and I still have a lot of reading to do as I am trying to understand how to make this sensor work for a project.
You will need two non-inverting operational amplifiers, rail to rail output (very important) with gain of about 20 to bring up both the reference and the sensor output voltages to measurable levels, that is, somewhat less than 5V maximum.