Added code for the MQ5 gas sensor

This commit is contained in:
Yannick van Etten
2024-10-30 18:04:58 +01:00
parent c08f1e434c
commit 9bd9b6c4b2

View File

@@ -2,12 +2,14 @@
#define DHTPIN 4
#define DHTTYPE DHT11
#define MQ5_PIN 2
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(MQ5_PIN, INPUT);
}
void loop() {
@@ -15,6 +17,8 @@ void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int mq5Value = analogRead(MQ5_PIN);
if (isnan(h) || isnan(t)) {
Serial.println("Fout bij het lezen van de sensor!");
@@ -26,4 +30,7 @@ void loop() {
Serial.print(" %\tTemperatuur: ");
Serial.print(t);
Serial.println(" *C");
Serial.print("MQ5 waarde: ");
Serial.println(mq5Value);
}