Hi!
I changed a little bit the code of AQ-Sensor with a piezo sum and LED for quality.
/*
AirQuality Demo V1.0.
connect to A0 to start testing. it will needs about 20s to start
- By: http://www.seeedstudio.com
*/
#include"AirQuality.h"
#include"Arduino.h"
AirQuality airqualitysensor;
int Tast = 2;
#define LED 13
const int Sum = 3;
#define Red 5
#define Yellow 6
#define Green 7
int current_quality =-1;
void setup()
{
Serial.begin(9600);
airqualitysensor.init(14);
pinMode(Tast, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(Sum, OUTPUT);
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
digitalWrite(LED, LOW);
digitalWrite (Sum, LOW);
digitalWrite (Red, LOW);
digitalWrite (Yellow, LOW);
digitalWrite (Green, LOW);
}
void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)// if a valid data returned.
{
if (current_quality==0)
{
Serial.println(“High pollution! Force signal active”);
digitalWrite(LED, LOW);
digitalWrite (Green, LOW);
digitalWrite (Yellow, LOW);
tone (Sum, 2000);
digitalWrite (Red, HIGH);
}
else if (current_quality==1)
{
Serial.println(“High pollution!”);
digitalWrite(LED, LOW);
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
noTone(Sum);
digitalWrite(Red, HIGH);
}
else if (current_quality==2)
{
Serial.println(“Low pollution!”);
digitalWrite(LED, LOW);
digitalWrite(Green, LOW);
digitalWrite(Red, LOW);
noTone(Sum);
digitalWrite(Yellow, HIGH);
}
else if (current_quality ==3)
{
Serial.println(“Fresh air”);
digitalWrite(LED, LOW);
digitalWrite(Red, LOW);
digitalWrite(Yellow, LOW);
noTone(Sum);
digitalWrite(Green, HIGH);
}
}
}
ISR(TIMER1_OVF_vect)
{
if(airqualitysensor.counter==61)//set 2 seconds as a detected duty
{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}
else
{
airqualitysensor.counter++;
}
}
*********
Now, I would like to tunr off the piezo with Tast on Pin 2.
It should do the following:
- AQ = 0 and
- Tast = 1
then tone(Sum, 2000)
- Tast = 0
then noTone(Sum);
and stay, until AQ > 0
then it should reset the piezo until AQ = 0 again.
I am not very good in programming - thanks for help!
Peter
Hi there:
*
AirQuality Demo V1.0.
connect to A0 to start testing. it will needs about 20s to start
- By: http://www.seeedstudio.com
/
#include"AirQuality.h"
#include"Arduino.h"
AirQuality airqualitysensor;
int Tast = 2;
#define LED 13
const int Sum = 3;
#define Red 5
#define Yellow 6
#define Green 7
int current_quality =-1;
void setup()
{
Serial.begin(9600);
airqualitysensor.init(14);
pinMode(Tast, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(Sum, OUTPUT);
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
digitalWrite(LED, LOW);
digitalWrite (Sum, LOW);
digitalWrite (Red, LOW);
digitalWrite (Yellow, LOW);
digitalWrite (Green, LOW);
}
void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)// if a valid data returned.
{
if (current_quality==0)
{
Serial.println(“High pollution! Force signal active”);
/ add coder :
AQ = 0 and
- Tast = 1
/
digitalWrite(Tast, HIGH);
//
digitalWrite(LED, LOW);
digitalWrite (Green, LOW);
digitalWrite (Yellow, LOW);
tone (Sum, 2000);
/ add coder : /
digitalWrite(Tast, LOW);
//
digitalWrite (Red, HIGH);
}
else if (current_quality==1)
{
Serial.println(“High pollution!”);
digitalWrite(LED, LOW);
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
noTone(Sum);
/ add /
current_quality = 0;
digitalWrite(Red, HIGH);
}
else if (current_quality==2)
{
Serial.println(“Low pollution!”);
digitalWrite(LED, LOW);
digitalWrite(Green, LOW);
digitalWrite(Red, LOW);
noTone(Sum);
/ add /
current_quality = 0;
digitalWrite(Yellow, HIGH);
}
else if (current_quality ==3)
{
Serial.println(“Fresh air”);
digitalWrite(LED, LOW);
digitalWrite(Red, LOW);
digitalWrite(Yellow, LOW);
noTone(Sum);
/ add */
current_quality = 0;
digitalWrite(Green, HIGH);
}
}
}
ISR(TIMER1_OVF_vect)
{
if(airqualitysensor.counter==61)//set 2 seconds as a detected duty
{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}
else
{
airqualitysensor.counter++;
}
}
Hi There,
unfortunately I always get the error message: expected constructor, destructor, or type conversion before ‘(’ token. this message references the code line 101 ISR (TIMER1_OVF_vect).
What am I doing wrong?
Best Regards
Christoph
Hi:
Could you please take a photo about your hardware? I have tested the code above, and get a right data.
Here is my .ino file<LINK_TEXT text=“https://github.com/SeeedDocument/forum_ … Sensor.ino”>https://github.com/SeeedDocument/forum_doc/raw/master/reg/Air_Quality_Sensor.ino</LINK_TEXT>, maybe you can download to have a test. When you test, please do not connect any other sensors, just connect Air Quality Sensor.
Hello and thank you very much for your answer. Unfortunately, it still doesn’t work for me. Too bad, more information in the appendix. And I am very happy and grateful if you help me further. I use a board called ExpLoRer form Sodaq (https://shop.sodaq.com/explorer.html)
Best regards
Christoph
Hi there,
ISR(TIMER1_OVF_vect) is run whenever the interrupt* “TIMER1_OVF_vect” is triggered. This is an interrupt that the ATmega328P * triggers whenever Timer 1 overflows past its maximum value.
I see you use the SAMD21 that’s the reason behind, it can’t be compiled successfully. You have to modify the library and code to make it work with SAMD21.
Bill