Điện tử vuotlen.com

Arduino MQ2 Gas Sensor & DHT11

Arduino MQ2 Gas Sensor & DHT11 

Linh kiện: Arduino Uno, Dht11, Lm016L, LogicState, Mq-2 gas sensor, res.

Proteus:

Arduino IDE:

Cài Lib: LiquidCrystal

 

#include <DHT.h>

#include <LiquidCrystal.h>

 

DHT dht(8, DHT11);

LiquidCrystal lcd(7, 6 , 5, 4, 3, 2);

float gas_sensor = A0;

 

void setup() {

  // put your setup code here, to run once:

  lcd.begin(16, 2);

  lcd.print("Hello");

  lcd.setCursor(0, 1);

  lcd.print("DHT11 + MQ2");

  delay(2000);

  Serial.begin(9600);

  dht.begin();

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

  float nhietdo = dht.readTemperature();

  float doam = dht.readHumidity();

  float gas = map(analogRead(gas_sensor), 0, 1023, 200, 10000);

  Serial.println();

  Serial.print("Do am:");

  Serial.print(doam);

  Serial.print("% ");

  Serial.print("Nhiet do: ");

  Serial.print(nhietdo);

  Serial.print("*C");

  lcd.clear();

  lcd.print("T: ");

  lcd.print(nhietdo);

  lcd.print(" *C H:");

  lcd.print(doam);

  lcd.print("%");

  lcd.setCursor(0, 1);

  lcd.print("Nong do gas: ");

  lcd.print(gas);

  lcd.print("ppm");

  delay(1000);

}