This project came about because I bought a capacitor kit with mainly X7R (good quality) capacitors, but some of the higher values 100nF and above were the cheaper and less stable Y5V dielectric, which exhibit a massive change over temperature and operating voltage. I wouldn’t normally use Y5V in a product I’m designing, so I tried to find alternative uses for them rather than let them sit on the shelf forever.
I wanted to see if the temperature change could be exploited to make a useful and very low cost sensor, and as you'll see over the next few pages it was quite simple, with only one other component required.
Step 1: Theory
First it helps to know a little about how capacitors are constructed, and the types available. Ceramic capacitors consist of a number of metal sheets, or ‘plates’ separated by an insulator, known as a dielectric. The characteristics of this material (thickness, type of ceramic, number of layers) give the capacitor it’s properties such as operating voltage, capacitance, temperature coefficient (capacitance change with temperature) and operating temperature range. There are quite a few dielectrics available, but the most popular are shown on the graph.
NP0 (also called C0G) - these are the best, with virtually no change over temperature however they tend to only be available for low capacitance values in the picoFarad and low nanoFarad range.
X7R - these are reasonable, with only a small percentage change over the operating range.
Y5V - as you can see these are the steepest curve on the graph, with a peak around 10C. This limits the usefulness of the effect somewhat, because if the sensor has the possibility of ever going below 10 degrees it will be impossible to determine which side of the peak it is.
The other dielectrics shown on the graph are intermediate steps between the three most popular described above.
So how can we measure this? A microcontroller has a logic level at which its inputs are considered high. If we charge the capacitor via a resistor (to control the charge time), the time to reach the high level will be proportional to the capacitance value.
Step 2: Gather Your Materials
You will need:
- Y5V Capacitors, I used 100nF 0805 size.
- Small pieces of prototyping board to mount the capacitors.
- Heatshrink to insulate the sensors. Alternatively you could dip them in epoxy, or use insulation tape.
- Network cable which can be stripped down to yield 4 twisted pairs. Not mandatory to use twisted pairs, but the twisting helps reduce electrical noise.
- Microcontroller - I used an Arduino but any will do
- Resistors - I used 68k but this depends on the size of your capacitor and how accurate you want the measurement to be.
- Soldering Iron.
- Prototyping board to mount the microcontroller/Arduino.
- Heat gun for the heatshrink. A cigarette lighter can be used also with slightly poorer results.
- Infrared thermometer or thermocouple, to calibrate the sensors.
Step 3: Solder Your Capacitors
No explanation needed here - just fit them to your boards using your preferred soldering method, and attach the two wires.
Step 4: Insulate the Sensors
Fit appropriately sized heatshrink tube over the sensors ensuring no ends are exposed, and shrink it using hot air.
Step 5: Fit Your Resistor and Connect the Sensor
I selected the following pinout.
Step 6: Write Software
The basic measurement technique is shown above. To explain how it works, using the millis() command returns the number of milliseconds since the Arduino was powered up. If you take a reading at the start and end of measurement, and subtract the starting value from the end you obtain the time in milliseconds for the capacitor to charge.
After measurement, it is very important that you set the output pin low to discharge the capacitor, and wait an appropriate amount of time before repeating the measurement so that the capacitor is completely discharged. In my case a second was sufficient.
I then spewed the results out of the serial port so that I could observe them. Initially I found that milliseconds was not accurate enough (giving only a single figure value), so I changed it to use the micros() command to obtain the result in microseconds, which as you'd expect was around 1000x the previous value. The ambient value at around 5000 fluctuated significantly, so to make it easier to read I divided by 10.
Step 7: Perform Calibration
I took readings at 27.5C (room temperature - hot here for the UK!), then placed the sensor bundle in the fridge and allowed them to cool to approximately 10C, checking with the infrared thermometer. I took a second set of readings, then put them in the oven on the defrost setting, continually monitoring with thermometer until they were ready to record at 50C.
As you can see from the plots above, the results were quite linear, and consistent across all 4 sensors.
Step 8: Software Round 2
I now modified my software using the Arduino map function, to remap the upper and lower average readings from the plots to 10C and 50C respectively.
All is working as planned, I performed a few checks across the temperature range.
Step 9: Project Summary - Pros and Cons
So there you have it, a temperature sensor for less than £0.01 in components.
So, why wouldn't you want to do this in your project?
- Capacitance fluctuates with supply voltage, so must use a regulated supply (cannot directly power from a battery) and if you decide to change supply then you must calibrate the sensors again.
- The capacitance is not the only thing that changes with temperature - consider that your input high threshold on your microcontroller may change with temperature, and it is not usually defined in the datasheet with any precision.
- Whilst my 4 capacitors were all pretty consistent, they were from the same batch and the same component reel and I honestly have no idea how bad the batch-to-batch variation would be.
- If you only want to measure low temperatures (below 10C) or high temperatures (above 10C) only this is OK, but relatively useless if you need to measure both.
- Measurement is slow! You have to fully discharge the capacitor before you can measure again.
I hope this project has given you some ideas, and maybe inspire you to use other components for purposes other than they were intended.