1

I'm fairly new to this and I'm having trouble with a code for a dust sensor. Getting a couple of errors. I downloaded this code from GitHub. Anyone have any idea how to fix any of these errors? Any help is appreciated. Sorry if this formatted wrong, this is also my first post. Thanks for your time

// SDS011 dust sensor example
// -----------------------------
//
// By R. Zschiegner ([email protected]).
// April 2016
#include "SDS011.h"
#include<SoftwareSerial.h>
SoftwareSerial myserial(0, 1);
SDS011(byte pin_rx, byte pin_tx) 
float p10,p25;
int error;
SDS011 my_sds;
void setup() {
 my_sds.begin(0, 1);
 Serial.begin(9600);
 while (!Serial) {
 ;
 }
}
void loop() {
 error = my_sds.read(&p25,&p10);
 if (! error) {
 Serial.println("P2.5: "+String(p25));
 Serial.println("P10: "+String(p10));
 }
delay(100);
}

here are the errors I'm getting

code:10: error: expected ')' before 'pin_rx'
 SDS011(byte pin_rx, byte pin_tx) 
 ^
C:\Users\Nick\Desktop\code\code.ino: In function 'void loop()':
code:26: error: 'p25' was not declared in this scope
 error = my_sds.read(&p25,&p10);
 ^
code:26: error: 'p10' was not declared in this scope
 error = my_sds.read(&p25,&p10);
 ^
exit status 1
expected ')' before 'pin_rx'
per1234
4,2782 gold badges23 silver badges43 bronze badges
asked Sep 18, 2017 at 0:11

2 Answers 2

2

You have to use the begin command. Instead of:

SDS011(byte pin_rx, byte pin_tx) 
...
SDS011 my_sds;

Use

SDS011 my_sds;

(Thus remove the first line: SDS011(byte pin_rx, byte pin_tx)).

And in setup add:

my_sds.begin(0, 1);

This follows the library function of SDS011:

void begin(uint8_t pin_rx, uint8_t pin_tx);

Other errors: because you forgot the ; in

SDS011(byte pin_rx, byte pin_tx) 

the next line:

float p10,p25;

is misinterpreted, and p10 and p25 are not known. Therefore errors are shown while trying to use p10 and p25.

These errors will go when changing the begin code as described earlier.

answered Sep 18, 2017 at 0:47
0

Your code should be like below; there are multiple syntax and semantic errors in the code you have posted;

Below is the edited and working code;

#include <SDS011.h>
float p10,p25;
int error;
SDS011 my_sds;
void setup() {
 my_sds.begin(0, 1);
 Serial.begin(9600);
 while (!Serial) {
 ;
 }
}
void loop() {
 error = my_sds.read(&p25,&p10);
 if (! error) {
 Serial.println("P2.5: "+String(p25));
 Serial.println("P10: "+String(p10));
 }
 delay(100);
}
answered Sep 18, 2017 at 5:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.