MQ 135 & DHT 22 with Qwiic Micro Oled Dual Display

Hi,

I need somne help with my first ‘‘project’’ I have combined several parts of codes found on internet for creating an air quality sensor and temperature and humidity sensor with dual displays. Now the problem is that I have no idea how to write a code it is like chinese to me.

Can anyone help me in making this right and explain what I have done wrong?
It works, the problem is that when I start it, the buzzer turn on until the MQ 135 heats up and only one of the two displays is showing the Adafruit logo at start for 2 seconds.

I would really like to change the Adafruit logo with a air quality sign and temperature sing to be shown separately for both screens (one shows temperature and humidity the other the air quality) Or maybe to show alternatively the signs. Can it be done?

And please, try to understand that I do not have any experience at all with this.

/*

//#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h> //I2C for OLED
#include <Adafruit_GFX.h> //grafix library for OLED
#include <Adafruit_SSD1306.h>

#define DHTPIN 2 //Pin which is connected to the DHT sensor.
#define anInput A0 //analog feed from MQ135
#define digTrigger 2 //digital feed from MQ135
#define co2Zero 55 //calibrated CO2 0 level
#define buzzer 9 //buzzer on pin 9
#define led 8 //led on pin 8
#define led 10 //led on pin 10
#define OLED_RESET 4
Adafruit_SSD1306 Display1(OLED_RESET);
Adafruit_SSD1306 Display2(OLED_RESET);

int i, j;

// Uncomment the type of sensor in use:

#define DHTTYPE DHT22 // DHT 22 (AM2302)

// See guide for details on sensor wiring and usage:
// Overview | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {
dht.begin();
pinMode(anInput, INPUT); //MQ135 analog feed set for input
pinMode(digTrigger, INPUT); //MQ135 digital feed set for input
pinMode(buzzer, OUTPUT); //led set for output
pinMode(8, OUTPUT);
pinMode(10,OUTPUT);
Serial.begin(9600); //serial comms for debuging
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3D);
Display1.display();
Display1.clearDisplay();
Serial.begin(9600);
Display2.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Display2.display();
Display2.clearDisplay();

sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);

delayMS = sensor.min_delay / 2000; // Set delay between sensor readings based on sensor details.
}

void loop() {
for (i = 0; i < 10; i += 10)
delay(delayMS); // Delay between measurements.
sensors_event_t event; // Get temperature event and print its value.
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {

}
else {
Display1.setTextSize(1);
Display1.setTextColor(WHITE, BLACK);
Display1.setCursor(0, 2);
Display1.println(“Temp / Hum”);
Display1.println(" “); //skip a line
Display1.print(“T: “);
Display1.print(event.temperature);
Display1.println(” C”);
Display1.println(” "); //skip a line

}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Display1.println(“Error reading humidity!”);
}
else {
Display1.print(“RH:”);
Display1.print(event.relative_humidity);
Display1.println(" %");
Display1.display();
Display1.clearDisplay();

}
int co2now[10]; //int array for co2 readings
int co2raw = 0; //int for raw value of co2
int co2comp = 0; //int for compensated co2
int co2ppm = 0; //int for calculated ppm
int zzz = 0; //int for averaging
int grafX = 0; //int for x value of graph

for (int x = 0; x < 10; x++) { //samplpe co2 10x over 2 seconds
co2now = analogRead(A0);
delay(200);
}

for (int x = 0; x < 10; x++) { //add samples together
zzz = zzz + co2now;
}
co2raw = zzz / 10; //divide samples by 10
co2comp = co2raw - co2Zero; //get compensated value
co2ppm = map(co2comp, 0, 1023, 400, 5000); //map value for atmospheric levels
{
Display2.setTextSize(1); //set text size
Display2.setTextColor(WHITE); //set text color
Display2.setCursor(0, 4); //set cursor
Display2.println(“CO2-Level”); //print title
Display2.println(" “); //skip a line
Display2.print(co2ppm); //print co2 ppm
Display2.print(” PPM"); //print units
grafX = map(co2ppm, 0, 1000, 0, 64); //map value to screen width
Display2.fillRect(0, 38, grafX, 5, WHITE); //print graph 400min 1000max
Display2.display(); //show the buffer
Display2.clearDisplay();
}
if (co2ppm > 1000) { //if co2 ppm > 900
digitalWrite(buzzer, LOW); //turn on led
}
else { //if not
digitalWrite(buzzer, HIGH); //turn off led
}
if (co2ppm < 700) { //if co2 ppm < 600
digitalWrite(led, LOW); //turn on led
}
else {
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50);
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
delay(80 );
digitalWrite(8, HIGH); /
delay(50);
digitalWrite(8, LOW);
delay(80);
digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW);
delay(80 );
digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW);
delay(80 );

digitalWrite(10, HIGH);
delay(50);
digitalWrite(10, LOW);
delay(80 );
digitalWrite(10, HIGH);
delay(50);
digitalWrite(10, LOW);
delay(80);
digitalWrite(10, HIGH);
delay(50);
digitalWrite(10, LOW);
delay(80 );
digitalWrite(10, HIGH);
delay(50);
digitalWrite(10, LOW);
delay(80 );
}
}
*/

Finala_cu_o_singura_problema.ino (6.41 KB)

It is a terrible idea to learn to code by Frankensteining creepy pasta from the Internet. It would be better to take each part of your project and code it a little at a time until you understand the whole.

mdorin:
For the moment I am trying to understand your language...

Frankensteining = hack together from parts, like Dr Frankenstein made Adam.
Creepy pasta = copy and paste scary stuff from the Internet.
If you search (mangifying glass in the upper right) this forum for "first project" you might be amazed at how many posts follow the same theme, (paraphrasing) "I have this idea for my first project. I want to go to the moon, but have no idea how to get there." Arduino was made to teach you the steps. Your first project should be blinking an LED, but understanding most of the code. Then move to blinking an LED in response to some input. Then progress a little at a time, until you undestand 90% of the code you've copied and hacked. If you want to have people actually read your sketch, and comment on it, post the contents of your INO file between code tags. People don't like to download a sketch, then open the IDE, which has to make a new folder etc. just to see how much time it might take to answer your question.