Using SDS011 via UART

Ok, here we go. To get this working took me quite some googling and trial & error, so hopefully this can help someone out! When you buy the SDS011 sensor, there’s usually a USB dongle included. With this you can easily get the data on Mac, Windows, RPI, etc.

While this does make life easier, it kinda kills your small form factor because it adds the dongle, small PCB and MicroUSB > USB convertor as below:

I want to measure particles with this the SDS011, add some sensors for temperature and such and keep it compact. For the SDS011 alone you end up with what you see below.

Not cool!

All RPI’s have an onboard UART as well which you can use. You could pick ground, 5V and Rx/Tx straight from the GPIO, thus bypassing all clunky adapters!

WARNING: connecting all this AT YOUR OWN RISK!!

Look how nice and clean!

Then the nightmare started… The Raspberry Pi Zero W is a bit more sensitive to changes in voltage than the rest of the family. If you pull the sensor from sleep mode, it creates a tiny tiny drop in voltage which reboots the Pi… Curses all around, since it all worked fine with another model I was testing with.

When I ran this setup on a RPI B+ it worked fine. Was testing via SSH and no errors, just data pouring out as expected. But lo and behold, output via HDMI actually gave a warning low voltage plus the little lightning strike top-right. You do not see this when you work via SSH, which was the reason I didn’t notice the issue…

You might say, just run it continuously then? That’s an option, but the SDS011 has a lifespan of some 8.000 hours. That would mean you can replace the sensor every year or so and they’re not that cheap. Besides that, I don’t like to waste things if I can prevent it.

If you want to read up on other experiences, I can recommend:

As we all know, you’re never unique so surely someone must’ve found a work-around? I have searched and searched for it but couldn’t find it. The inrush current (never heard of that either, here’s wikipedia) seems to be the problem, but didn’t find a solution other than using the USB dongle or run it 24/7.

Then I thought, it doesn’t crash when I use the USB dongle… Brain fart! I sacrificed an old Micro USB power-cable and tied that to the ground and 5V pin. The Tx/Rx still on the correct GPIO pins of course. With this setup I can put the SDS011 to sleep and when I wake it up again, it does NOT REBOOT! Victory at least!

This is not my final form…

So I now have a working sensor that I can address on /dev/ttyS0. I have also added a DHT22 sensor to get temperature and humidity. I made a test-script (based on this python script) that:

  • boots up the SDS011 sensor
  • takes 10 measurements with a second in between
  • I ignore the first 5 (spinning up the sensor gives a few initial fals readings)
  • take the median values
  • put the SDS011 to sleep
  • sleep for 5 minutes
  • rinse and repeat!

So far this has been running without crashing, so fingers crossed!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.