Building the Pocket CO2 Project
Intro
Most of my previous posts have been focused on software topics. I'm going to stray a little into hardware for this article. At the end of 2022 I made a promise to myself to learn how to use KiCad so that I could design my own printed circuit boards. I have some experience with electronics and I thought that I could design some relatively simple PCBs for my own use. I found this 100 minute YouTube tutorial and it provided enough practical info to get me started. This blog post is not about learning KiCad; instead I'm going to walk through all of the steps and equipment necessary to build my Pocket CO2 sensor project. The KiCad files and firmware can be found here.
(SMD) Surface Mount Soldering is Easy?
After seeing videos of professional makers such as Seon "Unexpected Maker" Rozenblum use pick-n-place machines to build complex PCB boards with impossibly small components, I wrongly assumed that SMD soldering required expensive equipment and lots of expertise. To get to Seon's level, you do need expensive equipment and lots of expertise, but there are much simpler SMD PCB projects that can be done with inexpensive tools and very little experience. Over the years, I had tried at various times to work with some SMD components on tinned proto-boards using a fine tip soldering iron. I was able to clumsily solder a few 0603 components and destroy/remove others, but it frequently resulted in frustrating failures. What made it much easier was my first new piece of equipment - the hot air rework station. It sounds more impressive than it is; more akin to a high temperature hair dryer. I purchased one of these 858D clones (see below) for about $35. There are many variants of this in the market, but they're all very similar. It has a knob to control the fan speed, buttons to raise or lower the temperature and a heat 'wand' on a short cable. For safety, there's a magnetic switch which turns off the heater when it's sitting in the holster.
Armed with only the hot air gun and a good pair of tweezers, it's possible to solder or rework (simple) SMD PCBs with minimal frustration. This is just the "getting started" tool and certainly not the best or only one for SMD hobby work. If you don't have a lot of extra space or budget for the more advanced tools, then at least you can get a feel for it without investing too heavily. There is a long list of tools people use for working with surface mount components such as reflow ovens, hot plates, pick-n-place machines, microscopes, cameras, suction pick-up pens, and on and on. I don't have the space or budget for them, so I make do with the hot air gun and I recently added an inexpensive ($40) hot plate:
The reason I say that it's easy (compared to through hole soldering), is that component placement or removal goes much quicker. Once solder paste is applied and components are in place, a few seconds under the hot air flow and you can solder the whole board at once. Removing parts is just as simple - blast them with hot air and they slide right off the board.
Component Choices
It's useful to explain why I chose each specific component and size. I've been on a sort of mission for the last several years to acquire useful knowledge about the entire electronics market - cost, capabilities, availability. I recently became aware of low cost RISC-V MCUs from WCH.cn and decided to try using them in some projects as a learning experience. With that as a starting point, the goals of the Pocket CO2 project were to keep BOM (bill of material) costs as low as possible and have a device that fits easily in tight jeans pockets. I generally looked for the smallest and least expensive parts for this project. Here's a rundown of each component I chose and why:
MCU - CH32V003
The TSSOP20 version of this chip is relatively easy to solder (compared to the QFP20/QFN20), has plenty of exposed I/O and cost me about 17 cents each for Qty. 50. It has plenty of speed and enough internal RAM/FLASH to do quite a few tasks, so it seemed like a good choice. After writing the firmware, I'm hitting the 16K FLASH limit and would like to have more space, but 16K is the only choice for this chip. The next version of this device will move up to the 48 cent CH32V203.
CO2 Sensor - SCD40
I've tested Sensiron's SCD40, SCD41 and a MH-Z19B. The SCD40 is the smallest and lowest cost true CO2 sensor I could find. There are a lot of tiny/cheap VOC (volatile organic compound) sensors that claim to report "eCO2" values. I wrote about these in another blog post. The SCD4x delivers reliable results, doesn't use too much power and as a bonus, includes a temperature and humidity sensor. The only down side is the SMD footprint is unnecessarily difficult.
Display - SSD1306 128x64 OLED
This is my go-to display for several reasons: day/night readability, low cost, low power usage, fast display update, multiple suppliers, multiple color choices, and simple I2C communication. For this project, the breakout board version saved me some soldering headaches and was about the same price as the raw display panel. It also allowed me to reduce the 2D size of this project by having the display board sit on top of most of the other components.
Power Source - 3.7V LiPo Battery
I was hoping to run this board from a coin cell battery for improved safety. It's not possible to run the SCD40 from a coin cell because it has brief power spikes up to 250mA. The internal resistance of disposable coin cells prevents them from sourcing that much current. A pair of alkaline cells could work, but are much larger. LiPo batteries can handle huge current spikes without the voltage sagging. The average power use of the sensor can be under 1mA in low power mode (samples once every 30 seconds). I support this mode with a menu option called "low power mode". In this mode, the display is off until you press a button and then it will show the data for 5 seconds and turn off again. I also reduced the default MCU clock from 48Mhz to 8Mhz; this allows it to consume only 1.8mA while running; RISC-V 32-bit @8Mhz is still plenty of speed to do the job. The OLED display uses only 2-4mA when lit because less than half of the pixels are on. In continuous mode (samples every 5 seconds), and the display lit constantly, it averages about 8mA of total current draw. A 200-400mAh battery will be a good size for this project.
3.3V LDO Regulator - WL9005S5-33R
LCSC had this part on sale for 3 cents when I bought them. It uses a common SOT23-5 footprint and has quiescent current that's not too terrible. I don't feel too bad about using a mediocre LDO for this project because the power switch completely disconnects the battery.
LiPo Charge Controller - TP4057
This chip is small, cheap and does the job of managing/protecting the charging of the battery from the USB 5V power. It only needs one resistor to set the maximum charge current and provides two LED outputs to indicate charging/charged.
The Rest
I think 0603 SMD parts are a good balance between "take up a small amount of board real estate" and "too small to see". They're also very affordable from sources like LCSC. Your personal preference might be for a larger component size such as 0805 or 1206.
BOM costs
A primary aim of this project is to be a low cost true CO2 sensor. Here is the breakout down of my purchases (small qty, not including shipping, AliExpress + LCSC):
- SCD40 CO2 sensor: $14
- SSD1306 OLED breakout: $1.81
- TP4057 LiPo charge controller: $0.10
- 2-layer PCB: $0.40
- CH32V003 MCU: $0.17
- WL9005S5-33R LDO: $0.10
- N-Channel FET: $0.017
- LEDs + resistors: < $0.10
- Switch & buttons: < $0.10
- PH2.0 socket: $0.03
- USB micro-b socket: $0.29
Total: approximately $17.11
Applying Solder Paste
This is where personal choice will probably guide how you do things. I use 60/40 tin/lead solder paste because it melts at a lower temperature (compared to lead-free solder) and generally reacts well to the HASL (hot air solder leveling) finish I choose for my PCBs. Many of the SMD components have limited temperature tolerance, so reducing the solder melt temperature protects them from getting damaged. The SCD40 soldering instructions tell you to use a relatively low temperature and avoid hitting the permeable membrane on top.
The next choice is whether or not to use a stencil to apply the paste. The stencil allows you to brush paste across the board surface in one pass. I've successfully used stencils on some of my boards, but I've been going for minimum cost on my latest PCBs by skipping the stencil ($7 from JLCPCB). I've gotten good results doing it by hand because I can control how much solder paste is applied. Too much paste can cause tiny pads to short together. I mix the paste with additional flux (it already has flux, but more is better). This makes it less viscous and easier to spread. I use solderless breadboard wire as a solder "paintbrush" to apply it to the PCB (see photo below).
Once the paste is applied, The components can be placed on the board with a tweezer. The more difficult ones are LEDs or diodes. They only work in one direction, so I test them with a 3V power source before placing them. It's hard to see the polarity marker with the naked eye. I don't have a microscope, so I use my phone camera at 3-10x zoom to see if all of the pins are lined up with the pads. 0603 resistors and capacitors can be skewed or off-center a little, but the micro-b USB socket and TSSOP20 footprint of the MCU need to be placed with high precision to not short or miss the tiny pins.
Baking / Reflow
Once the components have been placed on the board, they mostly stay in place because of the viscosity of the solder paste. There's no hurry to bake the board because the paste doesn't dry in air. For this build, I also use a hot plate and set it to 150C. It gets the solder close to its melting point, then I can blow hot air on each set of pins to melt the paste. You'll see the solder paste go from dull to shiny when the solder melts. With the hot plate as a pre-heater, the melting occurs quickly. Without the hot plate, you need to keep the hot air blowing on the spot a bit longer to heat up the PCB first. Make sure you have a silicone rubber mat or other heat resistant surface as your work area. When everything has been melted, I let the hot plate cool down (it does this rather slowly), before removing the board. You probably noticed that I didn't solder the SCD40 in place yet. If there's a defect on the PCB or I messed something up badly, I don't want to risk soldering an expensive part. It's easy enough to solder just one additional part after everything checks out. If I have to remove the SCD40 to use on another board, it may get damaged in the process of soldering/de-soldering it multiple times.
Inspection / Pre-Power Testing
After the board cools, I use isopropyl alcohol to clean off excess flux. The soldered pins may not look very shiny even though the joint is soldered well. Touch each component to make sure it's soldered down. Using less flux will get shinier results, but it won't allow the solder to flow as easily towards the pads/pins. Next I visually inspect the board for any obvious shorts or problems. If there is excess solder, I can add a little flux to the spot and melt it with my fine tip soldering iron. I can usually get rid of little solder bridges this way. Once things all look good to the eye, then I use a continuity tester to make sure that GND/3V/5V are not shorted. I then proceed to test various connections on the board (e.g. GPIO pins to buttons). If everything looks good, then I solder on the 3-pin programming header and try to load firmware onto the CH32V003. Here's what I found for this specific build:
- Program loaded successfully using the WCH-LinkE SWDIO programmer
- Running the code for the first time revealed that one of the indicator LEDs wasn't working. The resistor next to it had one side not soldered well.
- Next, connected USB 5V to check the battery charging circuit. Neither charge nor ready LEDs lit. Again, the resistor next to them was not soldered well.
- After fixing the resistor with the soldering iron, charge+ready LEDs both light.
- Soldered PH2.0 connector, connected battery and checked current draw with low battery connected. I selected a max current of 300mA with a 3K resistor on the TP4057. The current meter showed 298mA; all is well.
- Placed the OLED breakout (unsoldered) into the pin sockets, powered up the board and the display showed the menu correctly. Nice :)
Conclusions so far: I should have used more solder paste on the resistors. A tiny dot of diluted paste wasn't sufficient to make solid connections. Luckily the board isn't that dense and I was able to reach the problems with my soldering iron without disturbing nearby parts.
Final Steps
Now that the main parts are tested, it's time to attach the SCD40 and display. I'm using parts I recovered from an early version of the board; I damaged them a bit when removing them, so they have a slight burnt tinge. Some early attempts with the SCD40 (with stencil) failed to solder correctly. I believe the problem was too much solder and shorts forming underneath. The last few times I soldered it with much less solder and it succeeded. Here's a photo of my solder paste application for the SCD40. Just a dot on each pad and a glob for the ground plane. You can see why I'm not pleased with Sensiron's footprint - there are only 5 unique pins, the rest are no-connect / not used. A much simpler footprint could have been done with the same 5 connections and the same physical and thermal properties.
I use plenty of kapton tape when reheating a single part. This serves to block some of the heat from the parts I don't want to re-flow with the hot air. In the photo below, I've placed the SCD40 very carefully with a tweezer and surrounded the nearby components with tape. Now it's ready to heat.
I set my heat gun for 280C. I didn't want to use the hotplate because of the plastic parts on the bottom side. I overdid it a bit with the hot air. The soldering job was successful, but I toasted the top membrane a bit. I added masking tape to the back of the OLED PCB to make sure that the components don't make electrical contact with anything on my PCB:
It works!
Video Walk-Thru
Closing Thoughts
- It functions as I envisioned
A very well-written article. I thoroughly enjoyed reading it.
ReplyDeleteGreat article, thanks! You’ve inspired me to have a play … I’ve just ordered some scd40s from AliExpress. I’m comfortable with esp8266s and 32s so will be trying that out first … using risc chips like yours is slightly out of my comfort zone right now …. I’ve been playing with the bme680 and pms5003 sensors around my house, having a good co2 meter will be a great bonus ! Thanks again, much appreciated!
ReplyDeleteHi Larry,
ReplyDeleteThanks for sharing your post, I really enjoyed reading it.
I'm trying to build similar ch32v003 + battery hobby product and I have one question: Can you explain the wiring to the voltage regulator, the part which I don't understand is EN pin, why not just connect it to VIN? What is the reason of using two 470k resistors and the connection to the PD4 pin?
Have a nice day!
The 470K+470K is a voltage divider to allow half of the LiPo battery voltage to go into an ADC pin to measure the battery level.
DeleteDo you have software build instructions? I built a unit (with only the expected soldering errors) and it works great with your hex file from github, but I've been unable to replicate the software. I'd like to make a few tweaks, but my build comes out vastly oversize, by thousands of bytes. I'm using a fairly recent download of the MounRiver suite. I"m perennially unable to get Eclipse to cooperate with me, but I've been unable to assemble a make-based build that fits either
ReplyDeleteThe software was built with MounRiver Studio IDE on Linux
Delete