The Sensometer +22 sensors

About This Project

Hey!! I’m Neoxelox and I will show you the “Sensometer”, a great example of IoT!
This project has +22 sensors, “+” because I have more sensors coming! :smile:
Also it has a IR Emitter, so I can pull Up/Down/Stop my blinds (yes my blinds have IR :sunglasses:).
The project is powered by two Arduinos: Mega and MKR100. The Mega reads the sensors data and via Serial transmits it to MKR1000, who is responsible for uploading it to the Cayenne cloud.
This is also a practical way to test how Arduino Mega and Cayenne Dashboard behave with lots of data and sensors.
As I want to make it portable, I will make a connection between the Gas sensors and some NPN transistors to control when the sensors are ON or OFF if they are not used., because they consume a lot of power.

NOTE: This project is not finished, because I cannot finish it in time for the contest because I didn’t receive all the sensors yet, so it’s missing a project box and a Screen for visualize data without internet. So, yes it will look very ugly and very messy :frowning:

Sensors and WHY

Sensors (RIGHT NOW):

  • [DS3231 | RTC] : Control the Time
    It is more focused in the screen that I will put in the Future

  • [KY-039 | Pulse Sensor] : Reads Pulse beats (in the future it will be also an Oxymeter)
    It is always important to monitorize your pulses!

  • [HC-SR04 | Ultrasonic Sensor] : Reads the Distance (and in the future the speed)
    It is VERY useful, really, I mean you can know instanly the distance between two objects! And it has an error of 2 mm :grin:

  • [KY-015 | DHT11] : Reads Temperature and Humidity
    A good IoT project has a Temperature and Humidity Sensor :joy:

  • [GY-91 | BMP280/MPU9250] : Reads Altitude and Pressure (and in the future I will also control the magnetic compass as well as the accelerometer)
    The same as before! :joy: The Altitude is an extra but it is also useful.

  • [PHOTORESISTOR] : Reads Iluminance (lux)
    It is good to know the illuminance to protect ourselves of sunburns!

  • [KY-024 | Magnetic Field] : Reads Magnetic fields (Gauss not Teslas because is too big)
    It is proven that Magnetic fields doesn’t allow us to sleep correctly, so it is good to know if there is a field above our bed.

  • [UVM 30A | UltraViolet] : Reads UltraViolet Radation (UV Index)
    It is very important to know the UV Index (0 - +11) for our health. If it is a big value it can cause several damage to our skin, like a cancer :disappointed_relieved:

  • [HXJ-17 | Sound Sensor] : Reads Sound (Db)
    That’s good if you can’t sleep because of your neighbour, you can know if he/she screams loud enough to report him/her :joy:

  • [KY-022 | IR RECEIVER] : Reads IR (and in the future it will be also a analog read for IR radation of Sun)
    It is good for dump your remote control, so then you can control your device.

  • [EMF SENSOR] : Reads Electromagnetic fields (I don’t know any unit :frowning:)
    It is also proven that Electromagnetic fields produce a devastating effect on us, it can produce several illness and weakness, so it is good to know the strength of the field.

  • [TCS320 | Color Sensor] : Reads Colors (RGB)
    Why? Why not :joy: (Now I don’t have to take a picture and then go to paint to know RGB color value)

  • [KY-005 | IR EMITTER] : Make my blinds go Up/Down or Stop
    I can automate it with Cayenne triggers. If UV Index or Illuminance of Sun (and in the future the IR Radation) is high, my blinds can go down.

  • [MQ8] : Reads Hydrogen Gasses
    They are colorless and they doesn’t smell, but they are so explosive!

  • [MQ3] : Reads Alcohol/Ethanol Gasses
    You don’t need to know why I want this…

  • [MQ9] : Reads CO Gasses
    As Hydrogen they are colorless and they doesn’t smell, but they are EXTREMELY dangerous, they kill you in seconds, it is know as “Sweet dead”.

  • [MQ2] : Reads Fuel Gasses
    I have a gas boiler, it is good to know if there is any leak.

  • [MQ135] : Reads CO2/AIR QUALITY Gasses
    It is good to know how is the aire you are breathing.

What’s Connected

The project has two Arduino Boards. It combines the power of Arduino Mega, and the connectivity of Arduino MKR1000. They are connected each other through Serial communication.
The Arduino Mega is responsible of reading all the sensors, and controlling my blinds, whereas the Arduino MKR1000 is responsible of reading the data of the Mega and uploading it to Cayenne Cloud (in the future this board will also control a screen and a couple of speakers, so with a button from Cayenne Dashboard I could listen to my favourite track).

Triggers & Alerts

This project has (right now) two Triggers, but I could easily put 22 triggers/alerts for every sensor.

UV INDEX:
It pull my blinds down when there is a high UV Index

Illuminance of Sun:
It also pull my blinds down when there is a high Illuminance (yes I know UV Index and Illumicance of Sun are proportional, but this is just in case UV sensor fails, I don’t want a sunburn:joy:)

Scheduling

As right now I only have one actuator (I mean my blinds), the project has only one schedule action:
Every day at 6:45 (yes I have to get up at that hour…) the blinds pull up automatically, so I can get up.

Dashboard Screenshots

A pretty messy Dashboard :joy:



The gauges seems to be a little bugged


Photos of the Project

Data of Arduino Mega (it seems very messy and it actually is, but it is because debug mode was set to True, but this is not the way I transmit it to the Arduino MKR1000):

Arduino Mega:

Arduino MKR1000 (I just realized that in this photo is not connected):

The Project (as I said I KNOW IT LOOKS UGLY but I didn’t finish it yet):
The cable without the cover is the antenna for the emf sensor

Code

Arduino MKR1000:

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMKR1000.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "**********";
// Your network name and password.
char ssid[] = "********";
char password[] = "*****";

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

void loop()
{
  Cayenne.run();
  Serial.println("8");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V23, Serial.read());
  }
  Serial.println("9");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V17, Serial.read());
  }
  Serial.println("11");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V20, Serial.read());
  }
  Serial.println("12");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V21, Serial.read());
  }
  Serial.println("13");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V19, Serial.read());
  }
  Serial.println("14");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V18, Serial.read());
  }
  Serial.println("15");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V22, Serial.read());
  }
  Serial.println("16");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V15, Serial.read());
  }
  Serial.println("17");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V16, Serial.read());
  }
  Serial.println("18");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V11, Serial.read());
  }
  Serial.println("19");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V14, Serial.read());
  }
  Serial.println("20");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V24, Serial.read());
  }
  Serial.println("21");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V5, Serial.read());
    Cayenne.virtualWrite(V6, Serial.read());
    Cayenne.virtualWrite(V7, Serial.read());
  }
  Serial.println("25");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V0, Serial.read());
  }
  Serial.println("26");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V1, Serial.read());
  }
  Serial.println("27");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V2, Serial.read());
  }
  Serial.println("28");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V3, Serial.read());
  }
  Serial.println("29");
  delay(250);
  if (Serial.available() > 0) {
    Cayenne.virtualWrite(V4, Serial.read());
  }
 
}
CAYENNE_IN(V8)
{
int value = getValue.asInt();
if (value == 1){
Serial.println("22");  
}
}
CAYENNE_IN(V9)
{
int value = getValue.asInt();
if (value == 1){
Serial.println("23");  
}
}
CAYENNE_IN(V10)
{
int value = getValue.asInt();
if (value == 1){
Serial.println("24");  
}
}

Arduino Mega:

//SENSOMETER V1.0 REV2
//Project made by @Neoxelox
//----------------------------------------------------|
// LIBRARY SECTION  LIBRARY SECTION  LIBRARY SECTION  |
//----------------------------------------------------|
// [KY-015 | DHT11]
#include <DHT.h>
#include <DHT_U.h>

// [GY-91 | BMP280/MPU9250]
#include <Wire.h>
#include "i2c.h"
#include "i2c_BMP280.h"
BMP280 bmp280;

// [DS3231 | RTC]
#include <avr/pgmspace.h>
#include <SoftwareWire.h>
#include <RtcDS3231.h>

// [KY-022 | IR RECEIVER]
#include <IRLremote.h>

// [KY-005 | IR EMITTER]
#include <IRremote.h>
#include <IRremoteInt.h>

//---------------------------------------------------------------------|
// QUICK SETTINGS   QUICK SETTINGS   QUICK SETTINGS   QUICK SETTINGS   |
//---------------------------------------------------------------------|
//-----------------------------[PINS]----------------------------------|
#define pulsePin A0 // [KY-039 | Pulse Sensor]
#define dhtPin 3 // [KY-015 | DHT11]
SoftwareWire myWire(6, 7); // [DS3231 | RTC] (SDA, SCL) NOT the real I2C pins
#define ultraTrigPin 4 // [HC-SR04 | Ultrasonic Sensor]
#define ultraEchoPin 5 // [HC-SR04 | Ultrasonic Sensor]
#define photoPin A1 // [PHOTORESISTOR]
#define magneticPin A2 // [KY-024 | Magnetic Field]
#define uvPin A3 // [UVM 30A | UltraViolet]
#define soundPin A4 // [HXJ-17 | Sound Sensor]
#define irPin 0 // [KY-022 | IR RECEIVER] 0 = digital pin 2
#define emfPin A5 // [EMF SENSOR] 
#define S0 9 // [TCS320 | Color Sensor]
#define S1 8 // [TCS320 | Color Sensor]
#define S2 11 // [TCS320 | Color Sensor]
#define S3 12 // [TCS320 | Color Sensor]
#define sensorOut 10 // [TCS320 | Color Sensor]
#define irePin 13 // [KY-005 | IR EMITTER]
#define mq8Pin A7 // [MQ8 | Hydrogen Gasses]
#define mq3Pin A8 // [MQ3 | Alcohol/Ethanol Gasses]
#define mq9Pin A9 // [MQ9 | CO Gasses]
#define mq2Pin A10 // [MQ2 | Fuel Gasses]
#define mq135Pin A11 // [MQ135 | CO2/AIR QUALITY Gasses]
//---------------------[TIMER (for DebugMode)]-------------------------|
#define timeDht 1000 // [KY-015 | DHT11]
#define timeRtc 1000 // [DS3231 | RTC]
#define timeUltra 1000 // [HC-SR04 | Ultrasonic Sensor]
#define timePhoto 1000 // [PHOTORESISTOR]
#define timeMagnetic 1000 // [KY-024 | Magnetic Field]
#define timeGy91 1000 // [GY-91 | BMP280/MPU9250]
#define timeUv 1000 // [UVM 30A | UltraViolet]
#define timeSound 1000 // [HXJ-17 | Sound Sensor]
#define timeEmf 1000 // [EMF SENSOR] 
#define timeTcs 1000 // [TCS320 | Color Sensor]
#define timeMq8 1000 // [MQ8 | Hydrogen Gasses]
#define timeMq3 1000 // [MQ3 | Alcohol/Ethanol Gasses]
#define timeMq9 1000 // [MQ9 | CO Gasses]
#define timeMq2 1000 // [MQ2 | Fuel Gasses]
#define timeMq135 1000 // [MQ135 | CO2/AIR QUALITY Gasses]
//-----------------------------[DEBUG]---------------------------------|
#define debugMode false
//----------------------------------------------------------|
// VARIABLES SECTION  VARIABLES SECTION  VARIABLES SECTION  |
//----------------------------------------------------------|
// [KY-039 | Pulse Sensor]
float alpha = 0.75;
int period = 50;
float max = 0.0;
int realbpm = 0;
int shbpm = 0;
int lastbpm = 0;

// [DS3231 | RTC]
RtcDS3231<SoftwareWire> Rtc(myWire);
char weekDay[][4] = {"Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab" };

// [KY-015 | DHT11]
DHT dht (dhtPin, DHT11);

// [HC-SR04 | Ultrasonic Sensor]
long ultraduration;
float ultradistance;
int ultraspeed1;
int ultraspeed2;
int ultraspeed3;
int ultraspeed4;
int ultrarealspeed;
int timersp;

// [KY-024 | Magnetic Field]
int rawfield = 0;
long readedgauss = 0;
#define NOFIELD 535
#define TOMILLIGAUSS 1.953125

// [UVM 30A | UltraViolet]
int uvvalue = 0;
int uvvoltage = 0;
int uvindex = 0;

// [HXJ-17 | Sound Sensor]
int soundvalue = 0;
int soundrefine = 0;
int sounddb = 0;

// [KY-022 | IR RECEIVER]
uint8_t protocolo = 0;
uint16_t direccion = 0;
uint32_t tecla = 0;
uint8_t oldSREG;

// [EMF SENSOR] 
#define emfsample 300          
float emfvalue;                                                          
int emfarray[emfsample];                    
unsigned long emfaveraging;

// [TCS320 | Color Sensor]
int tcsfrequency = 0;

// [KY-005 | IR EMITTER]
IRsend irsend;
IRrecv irrecv(irePin);
int khz = 38;
unsigned int PullBlindsUp[] = {6000, 4200, 560, 760, 560, 560, 360, 1690, 560, 560, 860, 560, 560, 560, 560, 560, 560, 260, 560, 1690, 560, 1890, 560, 560, 560, 1390, 160, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560 }; 
unsigned int PullBlindsDown[] = {6000, 5600, 860, 760, 560, 560, 360, 2690, 560, 560, 860, 660, 560, 560, 460, 560, 560, 560, 560, 1690, 560, 1890, 560, 560, 560, 1690, 160, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560 }; 
unsigned int StopBlinds[] = {2000, 3200, 960, 760, 560, 560, 360, 1790, 560, 560, 860, 560, 760, 560, 560, 560, 560, 960, 560, 1690, 560, 1890, 560, 560, 560, 1490, 160, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560 };
//----------------------------------------------|
// SETUP SECTION  SETUP SECTION  SETUP SECTION  |
//----------------------------------------------|
void setup() {
Serial.begin(9600);

// [HC-SR04 | Ultrasonic Sensor]
pinMode(ultraTrigPin, OUTPUT);
pinMode(ultraEchoPin, INPUT);

// [DS3231 | RTC]
Rtc.Begin();

// [KY-015 | DHT11]
dht.begin();

// [GY-91 | BMP280/MPU9250]
bmp280.initialize();
bmp280.setEnabled(0);
bmp280.triggerMeasurement();

// [PHOTORESISTOR] 
pinMode(photoPin, INPUT);

// [KY-024 | Magnetic Field]
pinMode(magneticPin, INPUT); 

// [UVM 30A | UltraViolet]
pinMode(uvPin, INPUT);

// [HXJ-17 | Sound Sensor]
pinMode(soundPin, INPUT);

// [KY-022 | IR RECEIVER]
IRLbegin<IR_ALL>(irPin);

// [EMF SENSOR]
pinMode(emfPin,INPUT);

// [TCS320 | Color Sensor]
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
// [MQ8 | Hydrogen Gasses]
pinMode(mq8Pin,INPUT);
// [MQ3 | Alcohol/Ethanol Gasses]
pinMode(mq3Pin,INPUT);
// [MQ9 | CO Gasses]
pinMode(mq9Pin,INPUT);
// [MQ2 | Fuel Gasses]
pinMode(mq2Pin,INPUT);
// [MQ135 | CO2/AIR QUALITY Gasses]
pinMode(mq135Pin,INPUT);  
}
//-------------------------------------------|
// LOOP SECTION  LOOP SECTION  LOOP SECTION  |
//-------------------------------------------|
void loop() {
waitForRequest();

}
//----------------------------------------------------|
// REQUEST SECTION  REQUEST SECTION  REQUEST SECTION  |
//----------------------------------------------------|
void waitForRequest(){
if (debugMode == false) {
// [KY-039 | Pulse Sensor]  
shbpm = getbpm();

// [KY-022 | IR RECEIVER]
oldSREG = SREG;
cli();
if (Serial3.available() > 0) {
switch (Serial3.read()) {
  // [DS3231 | RTC]
  case 1: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Second());
  case 2: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Minute());
  case 3: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Hour());
  case 4: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Day());
  case 5: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(weekDay[timerino.DayOfWeek()]);
  case 6: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Month());
  case 7: 
  //RtcDateTime timerino = Rtc.GetDateTime();
  //Serial3.println(timerino.Year());
  // [KY-039 | Pulse Sensor]
  case 8:  
  if((shbpm > 0) && (shbpm != lastbpm)){
  Serial3.println(shbpm);
  lastbpm = shbpm;
  }
  // [HC-SR04 | Ultrasonic Sensor]  
  case 9:
  Serial3.println(getdistance());
  case 10:
  // Serial.print(getspeed());
  // [KY-015 | DHT11]
  case 11:
  Serial3.println(dht.readTemperature());
  case 12:
  Serial3.print(dht.readHumidity());
  // [GY-91 | BMP280/MPU9250]
  case 13:
  bmp280.awaitMeasurement();
  float pascal;
  bmp280.getPressure(pascal);
  bmp280.triggerMeasurement();
  Serial3.println(pascal);
  case 14:
  bmp280.awaitMeasurement();
  static float meters;
  bmp280.getAltitude(meters);
  bmp280.triggerMeasurement();
  Serial3.println(meters);
  // [PHOTORESISTOR]
  case 15:
  Serial3.println(int(Light(analogRead(photoPin))));
  // [KY-024 | Magnetic Field]
  case 16:
  Serial3.println(readMagnetic());
  // [UVM 30A | UltraViolet]
  case 17:
  Serial3.println(readUV());
  // [HXJ-17 | Sound Sensor]
  case 18:
  Serial3.println(readSound());
  // [KY-022 | IR RECEIVER]
  case 19:
  if(protocolo!=0){
   Serial3.println(protocolo);
   Serial3.println(direccion);
   Serial3.println(tecla);
    protocolo=0;
  }
  SREG = oldSREG;
  // [EMF SENSOR]
  case 20:
  Serial3.println(readEmf());
  // [TCS320 | Color Sensor]
  case 21:
  Serial3.println(readColorRed());
  Serial3.println(readColorGreen());
  Serial3.println(readColorBlue());
  // [KY-005 | IR EMITTER]
  case 22:
  setBlindsUP();
  case 23:
  setBlindsDOWN();
  case 24:
  setBlindsSTOP();
  // [MQ8 | Hydrogen Gasses]
  case 25:
  Serial3.println(analogRead(mq8Pin), DEC);
  // [MQ3 | Alcohol/Ethanol Gasses]
  case 26:
  Serial3.println(analogRead(mq3Pin), DEC);
  // [MQ9 | CO Gasses]
  case 27:
  Serial3.println(analogRead(mq9Pin), DEC);
  // [MQ2 | Fuel Gasses]
  case 28:
  Serial3.println(analogRead(mq2Pin), DEC);
  // [MQ135 | CO2/AIR QUALITY Gasses]
  case 29:
  Serial3.println(analogRead(mq135Pin), DEC);
}
}
}
else if (debugMode == true) {
// [DS3231 | RTC]
static unsigned long RTC1read = millis();
if (millis() >= RTC1read + timeRtc) {
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();

//RtcTemperature temp = Rtc.GetTemperature();
//Serial.print(temp.AsFloat());
//Serial.println("C");
 RTC1read = millis();
}
// [KY-039 | Pulse Sensor]  
shbpm = getbpm();
if((shbpm > 0) && (shbpm != lastbpm)){
  Serial.print("BPM: ");
  Serial.println(shbpm);
  lastbpm = shbpm;
}
// [KY-022 | IR RECEIVER]
oldSREG = SREG;
cli();

if(protocolo!=0){
    Serial.print("COMUNICACION INFRAROJOS: ");
    Serial.print("Protocolo: ");
    Serial.print(protocolo);
    Serial.print(" Direccion: ");
    Serial.print(direccion, HEX);
    Serial.print(" Tecla: ");
    Serial.println(tecla);
    protocolo=0;
  }

  SREG = oldSREG;
// [HC-SR04 | Ultrasonic Sensor]
static unsigned long ultraread = millis();
if (millis() >= ultraread + timeUltra) {
  Serial.print("Distance: ");
  Serial.print(getdistance());
  Serial.println(" cm");
 // Serial.print("Speed: ");
 // Serial.print(getspeed());
 // Serial.println("m/s");
   ultraread = millis();
  }
// [KY-015 | DHT11] 
static unsigned long dhtread = millis();
if (millis() >= dhtread + timeDht) {
    Serial.print("Temperature: ");
    Serial.print(dht.readTemperature());
    Serial.println(" C");
    Serial.print("Humidity: ");
    Serial.print(dht.readHumidity());
    Serial.println("%");
    dhtread = millis();
  }
// [GY-91 | BMP280/MPU9250]
static unsigned long gy91read = millis();
if (millis() >= gy91read + timeGy91) {
  
 bmp280.awaitMeasurement();

    float temperature;
    bmp280.getTemperature(temperature);

    float pascal;
    bmp280.getPressure(pascal);

    static float meters;
    bmp280.getAltitude(meters);
    

    bmp280.triggerMeasurement();

    Serial.print("Height: ");
    Serial.print(meters);
    Serial.print(" m");
    Serial.print(" Pressure: ");
    Serial.print(pascal);
    Serial.print(" Pa; T: ");
    Serial.print(temperature);
    Serial.println(" C");
    gy91read = millis();
}
// [PHOTORESISTOR] 
static unsigned long photoread = millis();
if (millis() >= photoread + timePhoto) {
Serial.print(int(Light(analogRead(photoPin))));
Serial.println(" lux");
  photoread = millis();
}
// [KY-024 | Magnetic Field]
static unsigned long magneticread = millis();
if (millis() >= magneticread + timeMagnetic) {
 readedgauss = readMagnetic();
 Serial.print(readedgauss);
  Serial.print(" Gauss ");

  if (readedgauss > 0)     Serial.println("(POLO SUR)");
  else if(readedgauss < 0) Serial.println("(POLO NORTE)");
  else               Serial.println();
  magneticread = millis();
}
// [UVM 30A | UltraViolet]
static unsigned long ultravioletread = millis();
if (millis() >= ultravioletread + timeUv) {
  Serial.print("INDICE UV: ");
  Serial.println(readUV());
  ultravioletread = millis();
}
// [HXJ-17 | Sound Sensor]
static unsigned long soundread = millis();
if (millis() >= soundread + timeSound) {
  Serial.print(readSound());
  Serial.println(" Db");
 soundread = millis();
}
//
static unsigned long emfread = millis();
if (millis() >= emfread + timeEmf) {
  Serial.print(readEmf());
  Serial.println(" µV/m");
  emfread = millis();
}
// [TCS320 | Color Sensor]
static unsigned long colorread = millis();
if (millis() >= colorread + timeTcs) {
  Serial.print("ROJO: ");
  Serial.println(readColorRed());
  Serial.print("VERDE: ");
  Serial.println(readColorGreen());
  Serial.print("AZUL: ");
  Serial.println(readColorBlue());
  colorread = millis();
}
// [MQ8 | Hydrogen Gasses]
static unsigned long mq8read = millis();
if (millis() >= mq8read + timeMq8) {
  Serial.print(analogRead(mq8Pin), DEC);
  Serial.println(" ppm");
  mq8read = millis();
}
// [MQ3 | Alcohol/Ethanol Gasses]
static unsigned long mq3read = millis();
if (millis() >= mq3read + timeMq3) {
  Serial.print(analogRead(mq3Pin), DEC);
  Serial.println(" ppm");
  mq3read = millis();
}
// [MQ9 | CO Gasses]
static unsigned long mq9read = millis();
if (millis() >= mq9read + timeMq9) {
  Serial.print(analogRead(mq9Pin), DEC);
  Serial.println(" ppm");
  mq9read = millis();
}
// [MQ2 | Fuel Gasses]
static unsigned long mq2read = millis();
if (millis() >= mq2read + timeMq2) {
  Serial.print(analogRead(mq2Pin), DEC);
  Serial.println(" ppm");
  mq2read = millis();
}
// [MQ135 | CO2/AIR QUALITY Gasses]
static unsigned long mq135read = millis();
if (millis() >= mq135read + timeMq135) {
  Serial.print(analogRead(mq135Pin), DEC);
  Serial.println(" ppm");
  mq135read = millis();
}
}
}
//----------------------------------------------|
// PULSE SECTION  PULSE SECTION  PULSE SECTION  |
//----------------------------------------------|
int getbpm(){
  
  static float oldValue = 500;
  static unsigned long bpmMills = millis();
  static int bpm = 0;
  static unsigned long timeBetweenBeats = millis();
  int minDelayBetweenBeats = 400;
  int rawValue = analogRead((unsigned char) pulsePin);

  // MATHS FOR READING A PEAK
  float value = alpha * oldValue + (1 - alpha) * rawValue;
  float change = value - oldValue;
  oldValue = value;

   if ((change >= max) && (millis() > timeBetweenBeats + minDelayBetweenBeats)) {

    max = change;
    
    timeBetweenBeats = millis();
    bpm++;
  }
  else {
  }
  max = max * 0.97;

  if (millis() >= bpmMills + 15000) {
    realbpm = bpm * 4;
    realbpm = realbpm - 20;
    bpm = 0;
    bpmMills = millis();
  }
  delay(period);
  return(realbpm);
}
//-------------------------------------------------------------|
// ULTRASONIC SECTION  ULTRASONIC SECTION  ULTRASONIC SECTION  |
//-------------------------------------------------------------|
float getdistance(){
  digitalWrite(ultraTrigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(ultraTrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(ultraTrigPin, LOW);
  ultraduration = pulseIn(ultraEchoPin, HIGH);
  ultradistance = ultraduration*0.034/2;
  return(ultradistance);
}

/*float getspeed(){
  while(timersp != 1000){
    
    timersp++;
    }
  digitalWrite(ultraTrigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(ultraTrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(ultraTrigPin, LOW);
  ultraduration = pulseIn(ultraEchoPin, HIGH);

  
  ultraspeed1 = getdistance();
  ultraspeed1 = ultraspeed1/100;
  delay(500);
  ultraspeed2 = getdistance();
  ultraspeed2 = ultraspeed2/100;
  ultrarealspeed = (ultraspeed2 - ultraspeed1)/(500/1000);
  return(ultrarealspeed);
}*/
//----------------------------------------------------------------------|
// PHOTORESISTOR SECTION  PHOTORESISTOR SECTION  PHOTORESISTOR SECTION  |
//----------------------------------------------------------------------|
double Light (int RawADC0){
double Vout=RawADC0*0.0048828125;
int lux=(2500/Vout-500)/10;
return lux;
}
//-------------------------------------------------------------------------|
// MAGNETIC FIELD SECTION  MAGNETIC FIELD SECTION  MAGNETIC FIELD SECTION  |
//-------------------------------------------------------------------------|
long readMagnetic(){
rawfield = analogRead(magneticPin);

  long compensated = rawfield - NOFIELD;
  long gauss = compensated * TOMILLIGAUSS;
  return(gauss);  
}
//----------------------------------------------------------|
// DS3231RTC SECTION  DS3231RTC SECTION  DS3231RTC SECTION  |
//----------------------------------------------------------|
#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
    char datestring[21];

    snprintf_P(datestring, 
            countof(datestring),
            PSTR("%02u/%02u/%04u %02u:%02u:%02u "),
            dt.Day(),
            dt.Month(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
    Serial.print(datestring);
    Serial.print(weekDay[dt.DayOfWeek()]);
}
//----------------------------------------------------------------|
// UltraViolet SECTION  UltraViolet SECTION  UltraViolet SECTION  |
//----------------------------------------------------------------|
int readUV(){
  uvvalue = analogRead(uvPin);
  uvvoltage = (uvvalue * (5.0 / 1023.0)) * 1000;
  if(uvvoltage<227){
    uvindex = 0;
  }
  if(uvvoltage>=227){
    uvindex = 1;
  }
  if(uvvoltage>=318){
    uvindex = 2;
  }
  if(uvvoltage>=408){
    uvindex = 3;
  }
  if(uvvoltage>=503){
    uvindex = 4;
  }
  if(uvvoltage>=606){
    uvindex = 5;
  }
  if(uvvoltage>=669){
    uvindex = 6;
  }
  if(uvvoltage>=795){
    uvindex = 7;
  }
  if(uvvoltage>=881){
    uvindex = 8;
  }
  if(uvvoltage>=976){
    uvindex = 9;
  }
  if(uvvoltage>=1079){
    uvindex = 10;
  }
  if(uvvoltage>=1170){
    uvindex = 11;
  }
  return(uvindex);
}
//-------------------------------------------------------------------|
// Sound Sensor SECTION  Sound Sensor SECTION  Sound Sensor SECTION  |
//-------------------------------------------------------------------|
int readSound(){
  soundvalue = analogRead(soundPin);
  soundrefine = abs(536 - soundvalue);
  sounddb = 17 + (soundrefine * 15);
  return(sounddb);
}
//----------------------------------------------------------------|
// IR Receiver SECTION  IR Receiver SECTION  IR Receiver SECTION  |
//----------------------------------------------------------------|
void IREvent (uint8_t protocol, uint16_t address, uint32_t command){
  protocolo = protocol;
  direccion = address;
  tecla = command;
}
//-------------------------------------------------------------|
// EMF Sensor SECTION  EMF Sensor SECTION  EMF Sensor SECTION  |
//-------------------------------------------------------------|
int readEmf(){                   
for(int i = 0; i < emfsample; i++){              
  emfarray[i] = analogRead(emfPin);      
  emfaveraging += emfarray[i];  
  }              
  emfvalue = emfaveraging / emfsample;                  
  emfvalue = constrain(emfvalue, 0, 100);                                                    
  emfaveraging = 0;    
  return(emfvalue);              
}
//-------------------------------------------------------------------|
// Color Sensor SECTION  Color Sensor SECTION  Color Sensor SECTION  |
//-------------------------------------------------------------------|
int readColorRed(){
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  tcsfrequency = pulseIn(sensorOut, LOW);
  tcsfrequency = map(tcsfrequency, 25,72,255,0);
  delay(100);
  return(tcsfrequency);
}
int readColorGreen(){
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  tcsfrequency = pulseIn(sensorOut, LOW);
  tcsfrequency = map(tcsfrequency, 30,90,255,0);
  delay(100);
  return(tcsfrequency);
}
int readColorBlue(){
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  tcsfrequency = pulseIn(sensorOut, LOW);
  tcsfrequency = map(tcsfrequency, 25,70,255,0);
  delay(100);
  return(tcsfrequency);
}
//-------------------------------------------------------------|
// IR Emitter SECTION  IR Emitter SECTION  IR Emitter SECTION  |
//-------------------------------------------------------------|
void setBlindsUP(){
  irsend.sendRaw(PullBlindsUp, sizeof(PullBlindsUp) / sizeof(PullBlindsUp[0]), khz);
  }
void setBlindsDOWN(){
  irsend.sendRaw(PullBlindsUp, sizeof(PullBlindsUp) / sizeof(PullBlindsUp[0]), khz);
  }
void setBlindsSTOP(){
  irsend.sendRaw(PullBlindsDown, sizeof(PullBlindsDown) / sizeof(PullBlindsDown[0]), khz);
  }    

Video

When I finish the project :smiley:

3 Likes

A beautiful dashboard :slight_smile:

3 Likes