Arduino CO2 Sensor Controls PWM Fans in HRV
2 Attachment(s)
(* The title of this thread should have been "Arduino CO2 Sensor Controls PWM Fans in HRV, not "PCM" Fans. My bad. *)
EDIT (2014-06-09): For those who may doubt the need for a HRV, or a CO2 controlled HRV, here is some interesting reading. Thanks to BBP. A new EcoRenovator from Ireland, cerberus, tipped me off to some inexpensive CO2 sensors. In the past, CO2 sensors had been pretty expensive, but the attractive price (about $10) got me started. Thanks, cerberus! * * * My project idea is that HRVs are used to provide fresh air and at the same time minimize home heat loss. The heat loss from the outgoing air can be reduced, but never reduced to zero. A 'smart' HRV would sense the level of CO2 and when the level of CO2 reached a predetermined allowable level, it would run the fans. If the CO2 level was higher, it would run the fans at a higher speed, if the CO2 was lower, it would run the fans at a lower speed, and if the CO2 was acceptably low, the fans would not run at all. EDIT: My thinking has changed on this part of the project. I'm now considering using the varying voltage from pin 4 of the CO2 sensor as an input to one of the Analog in pins on the Arduino... and controling the Arduino's PWM pin with that. I found some examples of that HERE and HERE. This would increase the overall efficiency because the HRV heat loss would only be incurred when required. So far, petty simple. This project will use an Arduino to read a CO2 Sensor (Telair 6004) and then use the CO2 readings as input to control PWM fans in the HRV. Here is a photo of one of the CO2 monotoring boards, measuring about 2" x 2" in all it's twinkling, gold-toned beauty: http://ecorenovator.org/forum/attach...1&d=1359489148 Wow! $10 CO2 Sensor, pretty cute! An here is a diagram of the 12 pins that seen at the bottom of the photo above... And some documents:
So the Telaire 6004 is capable of either analog output (pretty good) or digital output (pretty accurate). But so far as I have been able to determine, the digital output is not so easy to implement. I was able to locate the following code to read the analog output pin (pin 4) on the Telaire 6004 and to blink an LED that is connected to Arduino digital output (pin 13). Code:
/* * * * Since I am barely able to make an Arduino blink it's little light (which is the most basic exercise in the Arduino House of Chops), I can use help. So, I'm open to any ideas from any of you Arduino dudes & dudettes on this project. I ain't proud. Best, -AC |
AC,
Using CO2 as a trigger for an HRV (or ERV) will not work as a reliable index of home air "staleness". Here is why . . . The average adult at rest gives off about 200 ml of pure CO2 per minute. Let's think of an really airtight house with four people in it after 7 days. Assume a house of 1200 ft2 and a height of 8 ft (volume of 9600 ft3 or 270 meters3). Four people at the end of one week give off 8,600 L of pure CO2 (8.1 meter3). The increase in CO2 at the end of one week in a literally airtight house with four people is 0.03% (8.1/270)- an almost vanishing small number to trigger with. A FAR better option is to place the HRV (or ERV) air intakes in the bathrooms running at about 10-20 CFM. When either the bathroom light or shower light goes on, then the blower speed goes up 2-3 times (with a "hang" timer to keep the higher fan on for 5-10 minutes post use). I used this exact scheme in a home I built over 20 years ago and had indoor winter humidities between 30-35% and summer between 45-50% (no higher). No steam covered windows in bathrooms, always fresh in the home and no mildew in walls. I looked at CO2, did the calculations and am wondering why commercial units use it. People "believe" CO2 will build up, but in even a super tight home (one air change per day), the use of CO2 as a trigger doesn't cut it. Thoughts? Steve |
I think stevehull has a point here.
Maybe the problem is not the CO2 after all, but the stale air by its self. What makes the inside air uncomfortable is a mix of (ok, CO2), humidity, odors, smoke (for smokers and cooks), ecc, and that's not easy to detect by electronic sensors. I guess the best method is to try down and find the minimum acceptable air change for each environment. |
Quote:
Quote:
Here are ASHRE & OSHA specs:
I also previously came across some studies of German shool children that indicated a much elevated level of performance when levels of CO2 were reduced well below ASHRE standards. I just did a search for that information I had found previously, and am not able to locate it... However, I did find this: Quote:
My design parameters are:
I'm sure I'll be tinkering with that. Quote:
The CO2 monitor is the first part of the project, after I get that going I will integrate a DH22 (AKA: RHT03) into the controller to monitor humidity. Quote:
Doesn’t cut it? Steve, right now I live in a house that I am radically insulating & sealing. I actually have first hand experience with what it is like to not have sufficient fresh air. I don’t need to imagine what it would be like... I am there right now. It is unpleasant, I am not just dreaming up a new project. Steve, your research would be more interesting if it actually had a bearing on what I am now experiencing. Do you have any experience with circuit design or software? -AC |
AC,
I can guarantee that CO2 is not building up. Rather, "stale air" is out gassing of construction components, the infamous body odor, cooking smells, but by far the humidity is the dominant issue. Our respiratory control system is such that even tiny increases in the ppm of CO2 (2-3 ppm) will cause us to increase ventilation rate. It is almost impossible to withstand an environment with 1000 ppm of CO2. Let's see what your house has in it. One way to test this is to hook up the CO2 sensor and record a week's data. All houses have air leakage. I believe the very best that I know of had one complete air exchange every 48 hours. I suspect your tight house has an exchange every 30 hours or so (very, very tight construction). I have a lot of experience with CO2 monitoring and can help you with hooking up the analog output of the CO2 sensor to the A/D port. Biu while you are there, hook up a relative humidity detector as well. Most homes do very well by using a constant 10-20 CFM HRV (or ERV) exchange volume all day long. The reason to kick it up is shower/bathroom use. I used a DPDT wall switch to both control the 120 V light above the shower and to increase the air CFM to 50-60 CFM with a 555 timer "one shot" to keep the HRV fan on for an additional 15 minutes after the light went off. The wall switch just to the bathroom turned also turned on the HRV fan to high for only 5 minutes. Measure your CO2 and humidity - let's see what the house has in it now. Steve |
1 Attachment(s)
Quote:
In your first post, you said that: "The average adult at rest gives off about 200 ml of pure CO2 per minute." ...and the rest of your calculations flowed from that number. That may be a safe way to design living systems where you live, but where I live, I and most of the people I know are not content to spend their lives 'at rest'. So, along this line, I happened across this useful chart... And also, I looked at your ventilation rates and I calculate that your recommended rates would result in a 100% air change in 144 minutes @ 10 CFM and 72 minutes @20 CFM in my conditioned space. I'll happily supply CO2 info when I get my circuit working, which is what I'm currently seeking help on. Best, -AC |
Hi AC,
I think maybe Steve and you are talking past each other. I didn't quite realize until a few days ago what all the fuss was about HRVs. When I read an update of your thread recently about your insulation project on your house I got a real ah ha moment. From everything I've read in that thread it sounds like the air quality problems you observe that neccessitates an HRV comes from excessive moisture tightness, not air tightness. I'm no expert but I'm very good with logic and my logic tells me that one can have near perfect air tightness and still have vapor permeability. This is the ideal. You want your home to have vapor permeability so you don't have mold problems while still making your home as airtight as possible. The opposite, perfect vapor tightness ALWAYS comes with perfect airtightness. Like I've said, I've been wrong before and may be now, but I think you are confusing the airtightness of your house as causing the air quality problems, when it is really your vapor tightness that is causing it. There are many very good articles on the internet at both Green Building Advisor and at Building Science that explains the difference in the two concepts. I think it may also explain why a more radical solution, such as an HRV may be a good solution for you. It in fact may be the best solution for the situation you have. But in situations where the home is airtight while being vapor permeable then I agree with Steve that a simple venting plan is often sufficient. |
Actually, Maybe an ERV would be more appropriate than an HRV because my understanding is that an ERV handles humidity as well as air and temperature exchanges. It seems like the situation AC is working with is a humid house.
Actually I'm a little confused about this. ERV's are usually used in humid climates but this isn't strictly the case in Portland, OR. Maybe someone else knows more about this, such as whether ERV's handle humidity in just one direction or both directions. If they can handle it in both directions depending on the direction of vapor drive, then an ERV seem more appropriate for AC's house, rather than an HRV. |
HRV vs. ERV
|
Well, that answers that. It seems to imply the humidity filtering only occurs in one direction - outside to inside. Too bad.
|
Well, I just noticed that they got the colors of the arid southwest and the pacific zone mixed up. And for the pacific zone, after the correction, they say an ERV is optional. So maybe that's the way to go for your particular situation. :)
It still would depend on the humidity filtering being bidirectional, which I don't know about. |
Quote:
If you have a HRV, the water stays on the side of the barrier on which it condenses, and exits, usually through a tube to be disposed. If you have an ERV, the barrier is permeable, and the water crosses through the barrier and evaporates into the air in the lower-to-higher temperature gradient. I was very careful with my language to avoid words like "inside" and "outside" so that the description would be valid when read for heating as well as air conditioning. * * * So, if you wanted to ventilate AND save heat in a bathroom/shower, you would NOT use a ERV, as that would send the water vapor back into the loo. So in that case the proper choice would be a HRV. -AC |
AC and gang,
Good information on ERV vs HRV graphics. First off, homes rarely have any CO2 buildup as the inherent ventilation of a home is far more than a school, office or other work space. This is because the ratio of surface area to living space is so large in a home. Very, very tight homes still have an air turnover (with no HRV/ERV) of about 1 air change per day so CO2 is very rarely a problem in homes. With regard to "rest" recall that 6-8 hours is sleep (even less CO2 output than rest) and that few really do large workouts in the home. But we do have dishwashers, showers, and latent vapor coming off our lungs which all contributes to significant water vapor loads. All that said, I also assume that a home has properly vented hot water heaters. furnaces, etc (if using propane/nat gas). On the issue of ERVs moving water vapor. Yes, they are bidirectional if there is a large dew point difference between the inside and the ambient outside. Air and water vapor permiance are important concepts. In very cold climates, the issue of water vapor permiance into walls can become very problematic. If sufficient water vapor goes into walls, there is the infamous critical freezing point in the middle of the insulation. If the insulation can become frozen and then water soaked (cellulose), then it turns to mush. In northern climates, I far prefer to have a 6 ml poly sheet on every wall, just underneath the drywall, walls ceilings and lapped like you are building a boat. I also prefer to put a closed cell foam layer on the cold side of the wall and a water non-permiant insulation inbetween. Yes, foam is great (expensive), but fiberglass batting (R18-R20) is very acceptable if well done (properly fitted into cavity). Obviously ANY air infiltration around electrical boxes must be sealed. The poly sheeting prevents water vapor going into walls and freezing there. Older homes are a real pain as studs are not 16 OC and custom cutting fiberglass batts becomes very tough. Over stuffing in nooks/crannies is easy to do and almost destroys the insulation value. In southern states, the opposite is true with the vapor barrier on the outside of the home as dew points are almost always higher there. The use of ERV's can help a LOT with water movement as in the winter it will increase relative humidity in a home and then decrease it in summer (to a lesser extent). HRV's don't move any water except that which may condense out on the cold side of the HRV. But all that said, I still have a dehumidifier that kicks in here (central Oklahoma) on humid May days when there is not a large heat load, but showers, dishwasher, etc all add a lot of water vapor to the house. I do encourage all to have a home humidity meter and to never allow it to go over 60%. I prefer to have it never go above 55%. In the winter, high humidity (in no wall vapor barrier) will accumulate in the ways "sogging" the insulation and in the summer it will contribute to mold build up in same. AC, just get some "raw data" from the CO2 sensor ($10 is worth playing with!) and if you need help, feel free to call. Great discussion! Steve |
Quote:
This is NOT a discussion thread. My purpose in starting this thread is to build a CO2 (& ultimately humidity) sensing controller for an HRV. The operative word is "build". I tried to make that clear in my first post when I wrote: Quote:
And in response, I have written 480 words as to why I am going to proceed. Writing this has been a waste of my time, just as your writing of your 1117 words was a waste of your time... and worse yet it has discouraged interest in this project. There are quite a few Arduino-savvy members of EcoRenovator, and not a single one has posted to this thread. I attribute this to your "Great discussion!" I wish you would start another thread, a discussion thread, about why using CO2 monitors is futile, and leave this project thread alone. You can even request that your posts to this thread be moved to to your 'CO2 monitoring is futile' discussion thread. I'm pretty sure the administrators would do this for you. Sincerely, -AC |
AC,
I apologize. Been down the road you are going (sensing CO2) many years ago and was trying to give you some factual information on sensing variables. Again, sorry about the misunderstanding and I look forward to your HRV and CO2 build results. Steve |
Graph of Telaire 6004 in action...
1 Attachment(s)
On a site that uses sensors such as the Telaire 6004 in monitoring buildings, I came across this chart of the device in action...
I would presume that the room had a lower, continuous ventilation rate, and that the 'bump' is the result of a conference. It seems tantalizingly possible that from the rate of CO2 decline at the end of the meeting, that the continuous ventilation rate could be calculated. Either room size or number of people would likely be needed. I also learned today that current Oregon code calls for CO2 monitors on each level of new construction. Hmmmmmmm.......... -AC |
I see that, relatively speaking, the CEO in green is blowing a lot of gas. Yup.
|
Quote:
This explains a lot! -AC |
Borrowed a Friends CO2 Tracker...
1 Attachment(s)
I borrowed a friend's CO2 tracker and got a nice readout of room parameters.
This is with one window opened about 3/4". I think I'm on the right track. Best -AC |
The Record Of The Day In CO2...
1 Attachment(s)
I did a rough log of today's CO2 data just to see what it looked like.
Y axis is CO2 in Parts Per Million (ppm) X axis is time 24 hours per day (are you paying attention Piwoslaw?) So, there's a steady increase from the time I wake up until about 10:00 when I went to do some errands. I returned at about 13:30 and logged CO2. Around 17:00, another reading, then I took some soup to the neighbor, and stayed for a short visit and took a reading when I returned. Shortly after that at around 19:30, a friend dropped by and we chatted for a few hours, at the end of which I took the final reading. After he left, I opened two windows, to flush out the CO2... never did that before! It's amazing... the record of the day in CO2. Best, -AC |
Not sure what sensor you were using for the plot, but I'd be careful to make sure you're not tracking something else like temperature or humidity with the sensor. Reading through the minimal spec sheet with it, it claims to need 14 days to calibrate the ABC system--I would assume uncalibrated from All Electronics by default. This also assumes that the unit sees 400ppm at least 3 times per day for calibration.
Specified accuracy is after re-zeroing process or 14 days of continuous operation with ABC Logic. As far as building the system, I'd try to find out the necessary protocal to interface with it over a SPI bus. You have one per arduino chip (assuming not a mega) but can select which device you want to interface with via a cs pin if you're also wanting to drive say an lcd. |
3 Attachment(s)
Quote:
I think that one thing that makes the reading seem anomalous is that my house is small, only about 700 sq. ft. and I'm mostly living in and only conditioning a part (25%) of that area. So the respiration of one person makes a big difference, to say nothing of more than one person... which is why I want to build this HRV. Quote:
Do you know how to do this? Here is some guy who was able to reverse engineer the digital interface to the sensor. He was going to build an Arduino library for this particular sensor, but he says that his computer crashed and he lost his work. Homemade Arduino based Indoor Air Quality CO2 PPM, Temperature, Humidity Monitor - YouTube ...bummer. I don't have a logic analyzer or any experience in using one, even if I did have one. Pin 4 of the CO2 sensor is analog out, 0 volts to 4 volts, with 0v. = 0 ppm and 4v. = 2000 ppm, linear. I thought I'd run that into an A-to-D in on the Arduino. So, I think I can figure my way through this approach. I do think that the digital approach is more accurate, but I don't have the savvy or the pre-made Arduino library to make it happen. I already got a couple of fans that are low current, quiet, permanent magnet ECM fans. They should do the job nicely. They are 12 V and only draw 650 ma each. Seems to me that it will be pretty straight forward to use the data from the Arduino's A-to-D and use it to control the duty cycle of a PWM going through a transistor to the fans. I'll have to do some experimenting when it's all together to adjust the rate. This might even be a job for PID. So, I know a bit about Arduino programming, actually a very little bit. If you have any suggestions, I'd like to hear. Oh, and here's the HRV core I got: And I even kind of have plans for the box: So right now, I'm in the CO2 controller design stage of the project. I tried to buy a controller from the company in Ireland that makes these things, but their controller only works on 220v 50Hz. Best, -AC |
Quote:
Why, if you were in the house all night do you start out at ~440ppm yet end the day at 1050ppm? Why is the rate increase different between data point 2-3 and 5-6 vs 3-5 and 6-9? Why the drastic drop while you're gone until 1330, but not the same slope of drop when you go to the neighbor with soup? And finally, why when there are two people in the house is the slope of increase less than between data points 2-3 and 5-6 but the same as when you got back at 1300 until 1930? Here are a few hypothesizes that come to mind: 1) You're measuring CO2, but CO2 in your house isn't driven by human sources. Instead it is driven by construction materials still curing. I know this plagued Biosphere II for a number of years with curing concrete (if my memory serves me). 2) You're sensor is temperature dependent. Its optical in nature and either the LED or more likely the sensing cell is temperature dependent. You've ruled out humidity it sounds like, but I would have guessed temperature is more likely to dominate anyway. Could also be some other factor that is affecting the sensor (supply voltage, saturation, location, etc). Need more data points... Its not too hard to hook up a SD card to an arduino (SPI interface) and have it log every ~5 min. Either buy a SD shield or OSH Park ~ Welcome (from dorkbotpdx)has a nice cheap PCB service 'local' to us. Quote:
I don't know why you'd look at a PID unless you're trying to track a target value. A bang-bang controller should work for this type of scenario and be much easier to implement. The logic would be, if > y1 then fan speed = high; if < y0 then fan speed = low, else fan speed = medium. Or you could implement a proportional controller if you want it a little more continuous in fan speed variation, but leave out the integral and derivative part of the controller. I would guess, as stevehull pointed out and I've observed in my house, that humidity will be a greater issue than CO2. So even with a CO2 sensor feed on the controller, you'll also want a humidity sensor feed as well. I'd worry more about the logic of the two combined sensors than trying to accurately track one value. If the house and sensors don't dampen the system enough, it'd be pretty easy to program some basic dampening logic into the fan controller. |
Quote:
I am only conditioning one room. As I said previously, it is not a large room. The kitchen is not heated and not conditioned and not subject to CO2 monitoring. The bathroom is not heated and not conditioned and not subject to CO2 monitoring. The room I sleep in is not heated and not conditioned and not subject to CO2 monitoring. The big drop was because I left my house to run some errands. There was no one home to generate CO2. The CO2 started climbing higher when I returned... The smaller drop was when I went next door to visit a neighbor. CO2 climbed much higher when a friend dropped by. I was pretty sure that I had explained all that before. Quote:
Quote:
Quote:
Quote:
Nope, it's been 67 degrees all the time... dead on. Quote:
Quote:
Have you ever measured the CO2 of the space you live in, by any chance? -AC |
worldtrekker,
AC has a good sensor and it doesn't respond to humidity and temperature as do many CO2 sensors. All that said, we need to look at the total volume sampled (VERY small) inside a home that is not room to room ventilated as is in more typical (larger volume) houses. In this very specific scenario, you can have the CO2 values he has measured in the specific room he is in. AC in in a very unusual house (700 ft2) and we need to keep that in mind. I really like the Linear LTC1041 8 pin chip for doing exactly as you say. Proportional control for an HRV (or ERV) is clearly overkill. In keeping with ACs request that we focus on controlling the HRV, I would look at the following: http://cds.linear.com/docs/en/datasheet/1041fa.pdf VERY easy to hook up and only uA of current to drive it. I also like the ability to sense every few minutes to further reduce current. The inherent hysteresis eliminates the on off on "chatter" than a simple bang bang switch has. The 1041 is also cheap! Steve |
Steve
Thanks for the chip idea, but... Quote:
About four years ago, I graduated from an on/off gas central forced air heating system to proportional controlled (AKA: inverter technology) mini split heat pump, and the civility and comfort of a proportional system is so unquestioningly superior that I'm just not interested in going back. Those mini splits really have set a higher bar, not only in comfort but also in economy. It's just amazing how many tiny transistors you can cram into a tiny space nowadays... and what you can do with them. I already have an Arduino clone (Teensy) that I plan to use, and if I understand it correctly, it can function in the same way as the IC you suggested. It also has analog-to-digital built in and PCM built in, and the capacity to handle another sensor (humidity) or two. Quote:
Just to help guide your thinking, the HRV core that I have is identical to the one used in THIS UNIT. In fact I bought mine from a former US affiliate that still had one left in stock. The favorable economic operation of this unit, and the size of the house that it is meant to service is very attractive to me, because it approximates the size of my own house. I realize that my house is on the small size... but I do plan to expand the conditioned area, but not to the whole 700 sq. ft. So here is a description of the controller that the Irish engineers came up with... hopefully, a similar controller can be developed. I mean, they can't be that much smarter than us, can they? Quote:
Best, -AC |
8 Attachment(s)
I have decided to go with the Teensy++ 2.0 because:
So, the Teensy comes just as in the photo above. Wires can be soldered right to the board, for experimenting, but there is much more flexibility if header pins or sockets are added to the board, which will then fit perfectly into an experimenter's bread board. I have already tried an actual bread board to align the pins and I melted the plastic (sigh). Here is a row of header pins. These can be purchased from any electronics supply house, sometimes even Radio Shack. It's necessary to use just a little bit of care when soldering the pins, else they won't line up perfectly with the bread board. If you use a piece of experimenter's perf board, to align the pins, they will be in good shape. Here's the Teensy with the header pins perfectly soldered to their thru-holes. I just happen to have a microscope lying about, so I examined my soldering job. Upon inspection, they're not all so good... The flaws don't look so very bad, but they are indicative of insufficient heat and bad flow. Could cause hard-to-find problems down the road. A couple of touches with the soldering iron, and re-inspection, and I'm ready for the next step. [NOTE: if you'd prefer to avoid soldering on the pins, the Teensy is also available with pins already soldered on] The next step is to go to the Arduino Download Page and download the latest stable (no betas for me, thank you) IDE (AKA: Integrated Development Environment). For me that would be the one for Windows... The Arduino IDE is about 91 Mega Bytes, so depending on your bandwidth, it could take a while... This gets installed before the Teensy programs. It doesn't seem to spread itself out all over your computer like other programs, so wherre you install it is wherre it will run from. Remember where it is installed, because you'll need to find this folder again when the Teensyduino add-on files get installed. Also required is the Teensyduino, which is an add-on to the Arduino IDE. So I download the Teensyduino add-on... again, in my case, it is for Windows. ...this file is about 22 Mega Bytes, so it'll take a while, also. Install this after the Arduino IDE has been installed. You'll need to install them in the same folder that contains your Arduino IDE. Next to get is the Teensy loader, which gives you a convenient way to load and try different programs. ... this one is pretty small and is quick to download. It just runs from it's location... no formal install. Last, is a small file, LED Blink, Both Slow & Fast that actually contains two hex files, "blink_fast.hex" and "blink_slow.hext" that are test files that you can load and run to verify that your Teensy & the Integrated Development Environment is all working as it should be. So that concludes acquiring and setting up the Development Environment for not only regular Arduino du jour but also the nifty thrifty Teensy. Now the programming begins, and this is the part I may need some help on. Best, -AC |
Most Excellent Arduino Tutorial...
So I'm trying to get my Arduino chops together, and have been looking at many various tutorials.
THIS ONE that I came across is the best, most detailed, most thorough I have found. -AC |
Great mini-tutorial. This should get me rolling on some of my deferred projects. Just needed a bit of a kick-start.
|
Quote:
We all need a kick-start from time to time. BTW, the guy that developed the Teensy (PJ) goes to the bi-weekly DorkbotPDX meetings, and there you will find a happy, supportive community of accomplished tech-heads, including PJ. And also, since it is Portland, a variety of great micro-brews. Best, -AC |
Project Progress...
2 Attachment(s)
I was successfully able to run the Teensy "Blink Both" hex examples.
I was also able to make the Arduino "Blink" example run. I tried different pins, changing code for each different pin, to get the feel of that. So, I want to be able to get the Teensy to be able to print information out from the Serial Monitor. I found a dead simple Teensy example on the Teensy site that is called "Tutorial 3: Serial Monitor & Input" So from that page I cut the code... Code:
void setup() { But compiling and running running the code did not result in my being able to see the Teensy output anything... So after trying everything I could think of, even burning a candle to the saints (which did calm my nerves), but nothing more. So, out of despiration, I posted a message to the Teensy Forum and quicker than I could say, "this thing will never work", I had an answer... Turns out that I needed to change a default on the Serial menu... ... and once that was done, the Teensy was more than happy to talk to me. Road block removed... progress continues. Best, -AC_Hacker |
Teensy Reads Voltage on Analog pin...
5 Attachment(s)
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() { Code:
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 Code:
int analogPin = 38; // initialize Teensy pin 38 for input of analog voltage 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 |
AC,
A quick calibration can be the CO2 content of your breath at the end of expiration ~ 7%. |
Exploring Pulse Width Modulation (AKA: PWM)
1 Attachment(s)
To make the Teensy control the speed of a fan, I will use the built-in PWM feature of the Teensy/Arduino.
The PWM pin can send out a stream of pulses, hi = 5V, lo = 0V. The duty cycle of the PWM, the percent of time the voltage is high, can be changed in 256 steps (0 to 255) from 0% to 100%, respectively. NOTE: My Analog read pin can read in steps of 1024, so I will need to divide my analog read values by 4 before I direct them to the PWM output. So I located the simplest Arduino program I could find and stripped out everything I didn't need. I ended up with this endless loop PWM program: Code:
//PWM test; PWM Value = 0 to 255 LED comes on full bright. Next I changed the 255 value to 128 and re-ran. LED came on less bright. Ditto 64 (dimmer) Ditto 32 (dimmer) Ditto 16 (etc.) . . . Ditto 0 (LED off) Everything worked as I had expected! On to the next test. Best, -AC |
Video of CO2 Controller for HRV!
1 Attachment(s)
More progress to report...
Trying to send analog voltage from Telair to Teensy PWM pin. Scaled the 1024 step analog read to 256 step PWM write. Code:
int CO2_Read = 38; // initialize pin 38 for input of analog voltage Then I was really interested in using setup to actually power a fan, to get some idea if this was actually feasible. I knew that the output from the Teensy pins was pretty puny, but trying to attach ANYTHING more than an LED led to disappointment. So I learned about various Power MOSFET transistors, as the solution. I discovered that the choices of MOSFETS that can directly interface with Teensy is fairly limited, because most MOSFETs need at least a 10v pulse to turn on the transistor, but the Teensy only has 5 volts. I did find out that these will work:
I also found out that you can build a single transistor amplifier to kick the 5 volt output up to 10 volt(+) levels, which I did until the real thing arrives. I also discovered that the single transistor amp inverts the signal, so I wrote a line of code that inverted the pulse, and I'm in business. Code:
int CO2_Read = 38; // initialize pin 38 for analog voltage in HRV controlled by CO2 - YouTube Many thanks to the very helpful dorks at DorkbotPDX, you guys helped me a bunch! Best, -AC_Hacker |
This is GREAT news and you have done well by hacking a control transistor to drive an output pulse.
Digital controls have incredible precision, but the analog world often is much faster. Chips like I suggested have built in hysteresis - but still need drivers like the one you just showed. VERY nice to have the audio (aka card on bicycle wheel) to audibly demonstrate the CO2 control. Keep going :thumbup: Steve |
Quote:
Don't forget to explain everything clearly and include lots of photos. Starting a project thread is very easy, just PRESS HERE and you're on your way... Best, -AC |
Code Sanitization & Refinements & the Right Power FET
2 Attachment(s)
As I'm learning more about programming the Teensy, I am also developing a keener appreciation for clear code.
So I have rewritten the sketch from my last post to do pretty much the same thing as before, but to be a bit cleaner. Code:
int CO2_ReadPin = 38; // initialize pin 38 for analog voltage in I am also realizing that there are some refinements that are needed:
Stalled Fan Prevention The stalled fan issue comes about when the CO2 level is so low that the resulting duty cycle of the pulse stream is too low to overcome the 'magnetic friction' of the fans, and although the fans are receiving pulses of power, the pulses are insufficient to initiate motion, thus energy is expended, but no work is being done... not good economy. I anticipate that the stalled fan characteristic will be different for different fans but they will each have their individual stall points. I wrote a simple program that counted down and printed duty cycle values to the serial monitor, while it sent pulses to the fan of incrementally decreasing duty cycles. I watched the fan gradually slow down until it came to a stop. The fan stops when the duty cycle reaches 28%, which corresponds to a pulse width value of 73. I then altered the program so that it counted up, with the fan initially being in a stopped state. The fan starts when the duty cycle reaches 36%, which corresponds to a pulse width value of 92. The amount of air that was moved by a 36% duty cycle is pretty low, so I decided that I need to make my fan turn-on and turn-off points a bit higher than 36%, which corresponds to a PWM value of 92 (out of 256). Pulse Width Modulation Noise The fans I am using are extremely quiet, but the the pulses that are sent to the fan are within the range of hearing... so even when the fan is changing speed, the high-pitched whine of the pulse stream remains the same. I played too much rock & roll in the previous decades, and I can't hear the problem at all. My girlfriend however, has very good hearing and is quite uncomfortable with the high-pitched whine of the fan. The fans will be inside a box, which should reduce the sound, but I think the problem can be entirely eliminated by increasing the frequency to some super-audible level. The Arduino Integrated Development Environment (AKA: IDE) makes many simplifications in order to lower the threshold for entry into this interesting world. The unfortunate result of that decision is that the user does not have direct control of all the variables that might be available to someone programming in C for instance. The Arduino IDE does not give me direct access to the frequency of the PWM stream, but C does. So it looks like I'll be headed back to the next DorkBotPDX meeting to learn a little C. Use the Proper Power FET This problem was a piece of cake. The new FETS came in from Sparkfun, and installing was a simple matter of pulling out the amplifying transistor plus associated parts and of course the old power FET. Then I installed the new power FET that has a lower turn-on threshold. Then, the output of the Teensy PWM pin goes straight into the gate of the new device. Here is the before picture... ...and here's the after picture... Much simplified! The LEDs and their associated resistors are in the circuit just for testing purposes, so the final version will get even simpler... Best, -AC |
So, if you don't have control over the frequency, how do you control the PWM with the arduino or can you have it do a 0-10vdc (or 0-5vdc) equivalant
|
Quote:
The above picture is a representation of a PWM wave. If you assume that the rising edge is the beginning of each pulse, the percentage of time the wave is high during each wave is called the duty cycle. In this picture, it looks like the wave is high for about one third of the duration on the wave, so the duty cycle would be 33%. If it was only high a quarter of the time, the duty cycle would be 25%. So, without varying the frequency of the wave you can vary how long the wave is high. With the Arduino, you can send a PWM pin a value between 0 and 256, to control the percentage of time that the wave is high. In the case of the first example, you would send the Arduino PWM pin a value of 256 divided by 3, so you would send it a value of 85. In the second example you would send a value of 256/4 or 64. If you wanted the duty cycle to be 80%, you would send a value of about 204. I'm using the Arduino in integer mode to conserve memory, so there are some math errors but they are not so important. There's a good entry in Wikipedia that goes over this pretty well. Does this help? Best, -AC |
All times are GMT -5. The time now is 04:53 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger