Can multiple sensors be used in a project? How to use if it can? Can we show the values ​​from these sensors on a single LCD screen? Here's the answers to these questions in this example project. We preferred Ardunio Mega because of the number of pins in this project. 3 types of sensors are used in this project. These are the DHT11 temperature and humidity sensor, the MAX30100 heartbeat and oximeter (oxygen level in the blood) sensor, and the MQ2 gas sensor (measuring LPG, Propane and Hydrogen density). Of course more sensors can be added to this equipment. However, we observed that there were conflicts during the application and did not work stably. This may be due to the type of microcontroller or the lack of power supply. More experienced friends can share their experiences in the comments section below.









In this example project, the selection of the relevant sensors is displayed on the LCD screen by selecting them via the buttons. The "Switch-Case" structure was used to provide this status during coding. You can use equipment such as potentiometer or rotary encoder instead of the button. Our aim here is to give an idea for such projects in a simple way.

Materials

Ardunio Mega (Clone)

Breadboards (Two big, one small)

DHT11 Temperature and humidity sensor

MAX30100 Pulse and oximetry sensor

MQ2 Gas sensor

16x2 Lcd module

I2C module

3 x push button

4 x10K Ohm ressistor(3 for buttons, 1 for DHT11 sensor)

Jumper cables

Scheme of the project









Important: Before encoding the project, download the following subdirectories and copy them to the folders in Ardunio's installation directory or to the "My Documents / Ardunio / Libraries" location.

Libraries for this project:

Dht11

https://github.com/adafruit/DHT-sensor-library

LCD I2C:

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

mq-2:

https://github.com/labay11/MQ-2-sensor-library

max30100:

https://github.com/xcoder123/MAX30100



Source Code:

#include "DHT.h" #define DHTPIN 12 #define DHTTYPE DHT11 #include "Wire.h" // For using I2C module #include "LiquidCrystal_I2C.h" //For lcd module LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // I2C address #include "MAX30100.h" MAX30100* pulseOxymeter; uint32_t tsLastReport = 0; int PulsePin=8; int PulseButonPin=4; int pulseButonDurum=0; DHT dht(DHTPIN, DHTTYPE); int buton_value=0; // We use this variable in the Switch-Case structure to display the corresponding sensor values ​​in the LCD according to the button pressed int dht11ButonPin=2; int dht11ButonDurum=0; int mq2ButonPin=3; int mq2ButonDurum=0; const int mq2Pin = A1; void setup() { Serial.begin(9600); pinMode(dht11ButonPin,INPUT); pinMode(mq2ButonPin,INPUT); pinMode(PulseButonPin,INPUT); lcd.begin(16,2); dht.begin(); pulseOxymeter = new MAX30100(); } void loop() { dht11ButonDurum=digitalRead(dht11ButonPin); mq2ButonDurum=digitalRead(mq2ButonPin); pulseButonDurum=digitalRead(PulseButonPin); int h = dht.readHumidity(); int t = dht.readTemperature(); pulseoxymeter_t result = pulseOxymeter->update(); if(dht11ButonDurum==HIGH){ lcd.clear(); buton_value=1; //For showing temperature and humidity } if(mq2ButonDurum==HIGH){ lcd.clear(); buton_value=2; //For showing gas concentration } if(pulseButonDurum==HIGH){ lcd.clear(); buton_value=3; //For showing pulse and oxygen concentration } switch (buton_value) { case 0: lcd.setCursor(0, 0); lcd.print("Project:"); lcd.setCursor(0,1); lcd.print("Multiple Sensor"); break; case 1: lcd.setCursor(0, 0); lcd.print("Gas: "); lcd.print(analogRead(mq2Pin)); delay(100); break; case 2: lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(t); lcd.print("C"); lcd.setCursor(0,1); lcd.print("Humidity: "); lcd.print(h); lcd.print("%"); break; case 3: if( result.pulseDetected == true ) { lcd.setCursor(0, 0); lcd.print("Pulse:"); lcd.print(result.heartBPM); lcd.setCursor(0,1); lcd.print("Oxygen:"); lcd.print(result.SaO2); lcd.println("%"); } delay(10); digitalWrite( PulsePin, !digitalRead(PulsePin) ); break; default: lcd.setCursor(0, 0); lcd.print("Project:"); lcd.setCursor(0,1); lcd.print("Multiple Sensor Equipment"); break; } }