Technology, Projects, Linux, Coding, Internet of Things...

Arduino: Cheap Sensors Cheap Results…

I mentioned last post I had ordered some cheap Temperature and Humidity Sensors for my Arduino boards. Well they came in, and so I got to do some nice experimenting with code to test them out. I already had a bit of code from the DHT Test Sketch (Arduino programs are called Sketches) that would poll one sensor and display the results over serial. Sort of the ultimate goal here is potentially running several fo these sensors around the house and polling them to gather temperature data and store it in a data base that can be accessed via the web.

The first step is getting a Sketch that would poll each sensor and output the result over the serial monitor, preferably with labels. I started out cutting and pasting the original single sensor code repeatedly and altering the pin before realizing a loop would be way more efficient for this task. After some fiddling I came up with the following Sketch which polls pins 2-7 sequentially in 2 second intervals and outputs the data to the serial monitor. This code requires the basic DHT includes from the DHT library.

I don’t have my Network Shields yet so I can’t play around with getting these numbers to dump into an SQL database (probably one running on my NAS) just yet. This basic proof of concept though is great since it allowed me to learn some code and test the basic functionality of the sensors. This code can be modified for any number of sensors by changing the “while (i<7)” line to “while (i<# of Pins/sensors Used)”.

Wiring up the bread board was also a bit of a tricky task, mostly because of the sheer number of connections being made. Each sensor gets a +Voltage and Ground connection off the bus bar and a wire from the senor. The new cheap sensors use a different pin out from my “official” expensive senor, not really a problem, but something to look out for.

After wiring everything up, I could plug the Arduino into my laptop and open the serial monitor on the appropriate baud rate and record the results. The results are actually a bit worrying but further testing will be needed to verify the integrity of the results…

Probe 1 is the official sensor, the one that cost me $10, the other 5 are cheap probes, they cost me like $9 total. I have to assume that Probe 1 is pretty accurate and probably has gone through some quality testing before being sold. The other 5, for all I know, are rejects that were swept off of some floor in China by the janitor. The point is, all of the readings of the cheap sensors are pretty off from each other, especially the humidity. This may actually be the case if these sensors were in separate rooms or even any distance from each other, however, these senzors are all within a few centimeters of each other on the same bread board.

There may be a few things happening here causing this discrepancy, and I only say this because they are at the very least consistent with themselves.

One, it’s possible, that there isn’t enough juice to run all of the sensors at once. If they are being under powered, I would likely get bad readings. I can easily test this by running each sensor independently with the old single probe Sketch.

Two, it’s possible that while no accurate to each other, they are accurate to themselves. I don’t really know what these numbers actually mean, I am assuming % Humidity and Degrees C. It may be some sort of internal scale factor and I simple need to adapt the program to return scaled results. The issue with this will be that each probe is polled in a loop, so there isn’t really an easy way to apply a different scale factor to each sensor individually.

Whatever the case, the Temperature is at least semi precise, which is what I care more about anyway. I’ll probably continue with the project with the idea that if I really want accurate results I could eventually invest in better sensors. The next step on the software end will be to add network functionality to record the data. On the hardware end I plan to use some CAT5 wire to allow the probes to be positioned in various places beyond just the Bread Board.

Related

One Comment

[…] used the default Arduino Ethernet libraries. I also simplified the code down to one probe, though adding more temperature probes will be trivial. After I managed to get the dummy data to post reliably, I moved on to adding variables in place […]