element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Just Encase
  • Challenges & Projects
  • Design Challenges
  • Just Encase
  • More
  • Cancel
Just Encase
Blog Monitoring and Protection an Ecological Area #8 - Adding Multiple Sensors: DS18B20, DHT22 and MQ-135
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Just Encase requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
Author: guillengap
Date Created: 18 Jan 2022 10:16 PM
Views: 417
Likes: 5
Comments: 1
  • Arduino MKR WAN 1300
  • lora
  • Waterproof DS18B20 Sensor
  • DHT22 Sensor
  • Monitoring and Protection an Ecological Area
  • MQ-135 Sensor
  • just_encase
Related
Recommended

Monitoring and Protection an Ecological Area #8 - Adding Multiple Sensors: DS18B20, DHT22 and MQ-135

guillengap
guillengap
18 Jan 2022

Table of Contents

  1. Project Introduction
  2. Getting Started
  3. Communication Between Two MKR WAN 1300
  4. LoRaWAN System Range Testing
  5. Assembling and Adding LCD Display to the Transmitter
  6. Assembling and Adding LCD Display to the Receiver
  7. LoRaWAN´s Field Test with a DS18B20 Sensor
  8. Adding Multiple Sensors: DS18B20, DHT22 and MQ-135
  9. Modifying Receiver Code for Multiple Sensors
  10. LoRaWAN´s Field Test with Multiple Sensors
  11. Connecting LoRaWAN to an IoT Provider through the Arduino NANO 33 IoT
  12. LoRaWAN and IoT Connection with a DS18B20 Sensor
  13. Testing LoRaWAN and IoT Connection with a DS18B20 Sensor
  14. LoRaWAN and IoT Connection with Multiple Sensors
  15. Testing LoRaWAN and IoT Connection with Multiple Sensors
  16. Project Report Updated

**********************************************************************************************************************

 Adding Multiple Sensors: DS18B20, DHT22 and MQ-135

Transmitter Schematic Diagram

In the figure below I show you the electrical diagram of the transmitter after adding the DHT22 humidity sensor and the MQ-135 air quality sensor.

Adding the DHT22 Sensor

In the figure below I show you the DHT22 sensor.

In this sensor I only obtain humidity readings with value ranges between 0 to 100%. I omit the temperature readings as the DS18B20 temperature sensor has a better measurement range (-55°C to +125°C). You can get the library used to program this sensor here: DHT-sensor-library

Adding the MQ-135 Sensor

In the figure below I show you the MQ-135 sensor.

Sensitive material of gas sensor is SnO2, which with lower conductivity in clean air. When target pollution gas exists, the sensor’s conductivity gets higher along with the gas concentration rising. Users can convert the change of conductivity to correspond output signal of gas concentration through a simple circuit.

I use this sensor to detect and measure carbon dioxide (CO2) particles in parts per million (ppm). In the following links you can find the reference information and the code to obtain it:

https://github.com/5cottyD/Projects/blob/master/co2ppm_meter.ino

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

Since these sensors have small differences, I made a small adjustment to this code to calibrate the CO2 level to 0. This is done in the following line of code:

#define co2Zero 55 //calibrated CO2 0 level

After mounting the three sensors, the device would look like the image below.

Transmitter code

After adding the DHT22 and MQ-135 sensors, the transmitter code would be as shown below:

LoRaSender_v3.ino

// AUTHOR: GUILLERMO PEREZ GUILLEN

#include <SPI.h> // LoRa->
#include <LoRa.h>
#include <OneWire.h> // DS18B20->               
#include <DallasTemperature.h>
#include <Wire.h> // LCD->
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 173;
const int colorG = 255;
const int colorB = 47;

#include "DHT.h" // DHT22 ->
#define DHTPIN 3    // Pin where the sensor is connected
#define DHTTYPE DHT22   // DHT22 sensor
DHT dht(DHTPIN, DHTTYPE);

// DS18B20-> Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); 

#define anInput     A0 // MQ135-> analog feed from MQ135
#define co2Zero     0 // calibrated CO2 0 level

int counter = 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  lcd.print("ECOLOGY!");  
  pinMode(anInput,INPUT); // MQ135 
  lcd.setCursor(0, 1); // LCD 
  lcd.print("LoRa Sender");
  if (!LoRa.begin(915E6)) {
  lcd.setCursor(0, 1); // LCD 
  lcd.print("Starting LoRa failed!");    
    while (1);
  }
  sensors.begin();   
  dht.begin();
}

void loop() {
  int co2now[10]; //int array for co2 readings
  int co2raw = 0; //int for raw value of co2
  int co2ppm = 0; //int for calculated ppm
  int zzz = 0; //int for averaging
  for (int x = 0;x<10;x++) // MQ135-> samplpe co2 10x over 2 seconds
  {                   
    co2now[x]=analogRead(A0);
    delay(200);
  }
  for (int x = 0;x<10;x++) // add samples together
  {                     
    zzz=zzz + co2now[x];  
  }  
  co2raw = zzz/10; // divide samples by 10
  co2ppm = co2raw - co2Zero; // get calculated ppm
  if (co2ppm <= 0) {
    co2ppm = 1;
  }
  else {
    co2ppm = co2ppm;
  }     
  int h = dht.readHumidity(); //We read the Humidity
  sensors.requestTemperatures();   //The command to read the temperature is sent
  int temp = sensors.getTempCByIndex(0); //The temperature is obtained in ยบC 
  // send packet
  LoRa.beginPacket();
  LoRa.print(temp);
  LoRa.print(",");
  LoRa.print(h);  
  LoRa.print(",");
  LoRa.print(co2ppm);
  LoRa.endPacket();
  // LCD display data
  lcd.clear();
  lcd.setCursor(0, 0); // LCD 
  lcd.print("P=");
  lcd.setCursor(3, 0); // LCD 
  lcd.print(counter);
  lcd.setCursor(8, 0); // LCD 
  lcd.print("T=");  
  lcd.setCursor(11, 0); // LCD 
  lcd.print(temp);
  lcd.setCursor(14, 0); // LCD 
  lcd.print("C");
  lcd.setCursor(0, 1); // LCD 
  lcd.print("H=");
  lcd.setCursor(3, 1); // LCD 
  lcd.print(h);   
  lcd.setCursor(6, 1); // LCD 
  lcd.print("%");
  lcd.setCursor(8, 1); // LCD 
  lcd.print("CO2="); 
  lcd.setCursor(13, 1); // LCD 
  lcd.print(co2ppm);
  counter++;   
  delay(2000);
}

Analysis:

As you can see, the data from the three sensors is separated by a comma(",").

  // send packet
  LoRa.beginPacket();
  LoRa.print(temp);
  LoRa.print(",");
  LoRa.print(h);  
  LoRa.print(",");
  LoRa.print(co2ppm);
  LoRa.endPacket();

Download section:

  • You can get the code from this post below:

adding_multiple_sensors_dsS18B20_dht22_and_mq135.zip

Anonymous
  • maydaymayday
    maydaymayday 12 days ago

    Hi, great tutorial!

    I have a question regarding the signal input voltage on the Arduino.

    Arduino writes: "Please read: operating voltage is 3.3V. The microcontroller on this board runs at 3.3V, which means that you must never apply more than 3.3V to its Digital and Analog pins".

    So how do you manage to get 5V into the analog and digital inputs of the Arduino without destroying the board?

    Thank you very much!

    Best reagards
    maydaymayday

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube