Uno Wifi Rev2 SDS011 compatibility

I'm currently trying to develop an air quality sensor using the Arduino Uno Wifi Rev2. I have implemented my own libraries for various MQ sensors but when trying to use the SDS011 I can't seem to get it to work. I have tried ricki-z's libary ( and various others but to no avail. When trying to read values, mySerial.available() is always returning 0 even though the fans are spinning. Is the sensor incompatible for the Wifi Rev2 architecture? or can someone recommend how I'd go about developing a library for it?

Thanks in advance

When trying to read values, mySerial.available() is always returning 0 even though the fans are spinning.

What is mySerial? I have found an issue with software serial on the Uno WiFi Rev2. Luckily, the Uno WiFi Rev2 has an unused hardware serial port on pins 0 and 1. If you can, I recommend using that instead of software serial.

Everything is pretty vague because you didn’t post your code. There’s a good chance we could provide better assistance if we could see your code.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Hi Pert,
Heres the code:

#ifdef ESP32
#error ESP32 does not work with SoftSerial, use HardwareSerial example instead

#include <SPI.h>
#include <WiFiNINA.h>
#include <Wire.h>
#include <MQ3.h>
#include <MQ4.h>
#include <MQ6.h>
#include <SDS011.h>

#define rxPin 0
#define txPin 1
#include "Wifi_Secrets.h"

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS;
MQ3 mq3(A1, 7);
MQ4 mq4(A2, 8);
MQ6 mq6(A3, 9);
SDS011 pmSensor;

float p10, p25;
int error;
//Initialise mySerial as software serial rx tx
SoftwareSerial mySerial(rxPin, txPin);

void setup() {
  //Initialise SDS011 Serial connection
  // pmSensor.begin(mySerial);
  // pmSensor.begin(&Serial1);

  while (!Serial) {
  //Get output pins for MQ sensors
  int pin3D = mq3.getDigitalPin();
  int pin4D = mq4.getDigitalPin();
  int pin6D = mq6.getDigitalPin();

  //Begin rx, tx serial
  //Set digital pin to output for MQs
  pinMode(pin3D, OUTPUT);
  pinMode(pin4D, OUTPUT);
  pinMode(pin6D, OUTPUT);
  //Wait until Wifi connection is made
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to open SSID: ");
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:

void loop() {
  //Retrieve p2.5 and p10 values
  //Or error = 1 if unavailable
  error =, &p10);
  //If no error print PM values
  if (!error) {
    Serial.println("P2.5:" + String(p25));
    Serial.println("P10:" + String(p10));
  else {
  //Trying to access serial port 1 values manually
  if (mySerial.available()) {

  //Read and print MQ sensor Values
  int mq3Reading = mq3.takeReading();
  int mq4Reading = mq4.takeReading();
  int mq6Reading = mq6.takeReading();
  Serial.println(mq3Reading, DEC);
  Serial.println(mq4Reading, DEC);
  Serial.println(mq6Reading, DEC);


The primary sensor library I’m using is “SDS011 sensor Library” but I have tried the following other two:
Nova Fitness Sds dust sensors library

When I initiate with software serial, compilation goes through fine but “error” is always 1 and therefore no values are ever read
When attempting to use Hardware serial “Serial1” I get the error:
“Main_Sketch:34:25: error: no matching function for call to ‘SDS011::begin(UartClass*)’”
But there is a function in the library that takes only Hardware serial:

void SDS011::begin(HardwareSerial* serial) {
  sds_data = serial;

My MQ sensor libraries get be accessed at:

Thanks again

The issue I had encountered with SoftwareSerial is only for sending, and you're not sending anything, so that's not relevant.

My recommendation is to focus solely on getting the SDS011 working. You're adding a lot of unnecessary complications into the mix with all these other sensors and their code. So disconnect everything except the SDS011 from your Uno WiFi Rev2 and then upload this sketch:

void setup() {
  Serial.println("Starting program");

void loop() {
  if (Serial1.available() > 0) {

Then open the Serial Monitor and make sure the baud rate menu at the lower right corner is set to 9600.

Hi Pert,

Unfortunately no luck with that code, Serial1.available() always returns 0 & always returns -1. Are there any other avenues you could recommend exploring?

Thanks, Jamie

Do you see "Starting program" printed in Serial Monitor?

Yes "Starting program" is printed in serial monitor but nothing else, unfortunately.

From the SDS011’s datasheet, I verified that it does communicate at 9600 baud and sends data at 1 Hz. This makes me think that the problem is not with the code or the Uno WiFi Rev2, but with either the wiring or the SDS011. Please tell us how you have the SDS011 wired to the Uno WiFi Rev2.

I currently have Rx and Tx wired directly to digital 0 & 1 respectively and 5v & Ground wired through a breadboard. The SDS011 has no problem powering up as the LED gives a blink and the visible outlet fan start spinning

Jaamie: I currently have Rx and Tx wired directly to digital 0 & 1 respectively

There's the problem. You need to wire Rx on the SDS011 to pin 1 on the Arduino and Tx on the SDS011 to pin 0 on the Arduino. The reason for this is that Rx stands for "receive" and Tx stands for "transmit". So you need to connect the receive pin to the transmit pin and vice versa. Otherwise, you're listening to the listener and talking to the talker.

Pert, you are a hero! Thank you so much for your help!

You're welcome. I'm glad if I was able to be of assistance. Enjoy! Per