The Alpha Geek – Geeking Out

PIR Motion Sensor

Project #29 – DFRobot – RHT And MQ – Mk13

——

#DonLucElectronics #DonLuc #DFRobot #BLESensorBeacon #AmbientLight #SoilMoisture #SHT40 #FireBeetle2ESP32E #EEPROM #RTC #SD #Display #Adafruit #ESP32 #IoT #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

RHT And MQ

——

RHT And MQ

——

RHT And MQ

——

Humidity and Temperature Sensor – RHT03

The RHT03 (also known by DHT-22) is a low cost humidity and temperature sensor with a single wire digital interface. The sensor is calibrated and doesn’t require extra components so you can get right to measuring relative humidity and temperature.

MQ Series Gas Sensor

The description of each MQ series gas sensor and its uses that follows will be helpful to anybody who wants to understand the foundations of gas sensing technology. The MQ Series Gas Sensor is a revolutionary technology designed for the detection of combustible gases, such as those used in industry and manufacturing. MQ sensor working principle involves detecting changes in electrical conductivity when specific gases come into contact with the sensor’s sensing element. This variety of semiconductor gas sensors makes it possible to measure concentrations of gasses such as alcohol, methane, propane, butane, and carbon monoxide.

Pololu Carrier for MQ Gas Sensors

This carrier board is designed to work with any of the MQ-series gas sensors, simplifying the interface from 6 to 3 pins—ground, power and analog voltage output +3-5 Volt. This board has two mounting holes and provides convenient pads for mounting the gas sensor’s required sensitivity-setting resistor.

DL2405Mk03

1 x DFRobot FireBeetle 2 ESP32-E
1 x Adafruit SHARP Memory Display
1 x Adafruit MicroSD card breakout board+
1 x MicroSD 16 GB
1 x Adafruit DS3231 Precision RTC FeatherWing – RTC
1 x Battery CR1220
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor – RHT03
1 x PIR Motion Sensor (JST)
1 x Switch
1 x 1K Ohm
1 x Gravity: Analog Soil Moisture Sensor
1 x Gravity: Analog Ambient Light Sensor
1 x Fermion: SHT40 Temperature & Humidity Sensor
3 x Fermion: BLE Sensor Beacon
3 x CR2032 Coin Cell Battery
1 x 1 x Lithium Ion Battery – 1000mAh
1 x Green LED
1 x Slide Switch
1 x SparkFun Serial Basic Breakout – CH340G
1 x SparkFun Cerberus USB Cable
1 x USB 3.1 Cable A to C

DFRobot FireBeetle 2 ESP32-E

LED – 2
DSCK – 4
DMOSI – 16
DSS – 17
SCK – 22
MOSI – 23
MISO – 19
CS – 13
SCL – 21
SDA – 22
LED – 14
RHT – 25
PIR – 26
SWI – 3
MQ8 = A0
MQ9 = A1
MQ7 = A2
MQ3 = A3
VIN – +3.3V
GND – GND

——

DL2405Mk03p.ino

/****** Don Luc Electronics © ******
Software Version Information
Project #29 - DFRobot - RHT And MQ - Mk13
29-13
DL2404Mk03p.ino
1 x DFRobot FireBeetle 2 ESP32-E
1 x Adafruit SHARP Memory Display
1 x Adafruit MicroSD card breakout board+
1 x MicroSD 16 GB
1 x Adafruit DS3231 Precision RTC FeatherWing - RTC
1 x Battery CR1220
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor - MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor - MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor - RHT03
1 x PIR Motion Sensor (JST)
1 x Switch
1 x 1K Ohm
1 x Gravity: Analog Soil Moisture Sensor
1 x Gravity: Analog Ambient Light Sensor
1 x Fermion: SHT40 Temperature & Humidity Sensor
3 x Fermion: BLE Sensor Beacon
3 x CR2032 Coin Cell Battery
1 x 1 x Lithium Ion Battery - 1000mAh
1 x Green LED
1 x SparkFun Serial Basic Breakout - CH340G
1 x SparkFun Cerberus USB Cable
1 x USB 3.1 Cable A to C
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM
// with Unique ID for Unit
#include "EEPROM.h"
// Wire
#include <Wire.h>
// Arduino
#include <Arduino.h>
// BLE Device
#include <BLEDevice.h>
// BLE Utils
#include <BLEUtils.h>
// BLEScan
#include <BLEScan.h>
// BLE Advertised Device
#include <BLEAdvertisedDevice.h>
// BLE Eddystone URL
#include <BLEEddystoneURL.h>
// BLE Eddystone TLM
#include <BLEEddystoneTLM.h>
// BLE Beacon
#include <BLEBeacon.h>
// DS3231 RTC Date and Time
#include <RTClib.h>
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// RHT Temperature and Humidity Sensor
#include <SparkFun_RHT03.h>

// ENDIAN_CHANGE
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))

// DS3231 RTC Date and Time
RTC_DS3231 rtc;
String sDate;
String sTime;

// MicroSD Card
const int chipSelect = 13;
String zzzzzz = "";

// SHARP Memory Display
#define SHARP_SCK  4
#define SHARP_MOSI 16
#define SHARP_SS   17
// Set the size of the display here, e.g. 144x168!
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
// The currently-available SHARP Memory Display (144x168 pixels)
// requires > 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno
// or other <4K "classic" devices.
#define BLACK 0
#define WHITE 1

// LED Green
int iLEDGreen = 2;

// Define LED
int iLED = 14;

// Fermion: SHT40 Temperature & Humidity Sensor
// Temperature
float TemperatureData;
float Temperature;
// Humidity
float HumidityData;
float Humidity;
// Gravity: Analog Ambient Light Sensor
float Sensor_Data;
// SData => 1~6000 Lux
float SData;
// Gravity: Analog Soil Moisture Sensor
float SensorSM;
float SDataSM;
// In seconds
int scanTime = 5;
// BLE Scan
BLEScan *pBLEScan;

// RHT Temperature and Humidity Sensor
// RHT03 data pin Digital 25
const int RHT03_DATA_PIN = 25;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A0;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet.
// With these two points, a line is formed which is
// "approximately equivalent" to the original curve.
float H2Curve[3] = {2.3, 0.93,-1.44};

// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A1;
int iMQ9Raw = 0;
int iMQ9ppm = 0;

// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A2;
int iMQ7Raw = 0;
int iMQ7ppm = 0;

// Alcohol Gas Sensor - MQ-3
int iMQ3 = A3;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// PIR Motion
// Motion detector
const int iMotion = 26;
// Proximity
int proximity = LOW;
String Det = "";

// Switch
int iSwitch = 3;
// Variable for reading the Switch status
int iSwitchState = 0;

// My Advertised Device Callbacks
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
{

    // onResult
    void onResult(BLEAdvertisedDevice advertisedDevice)
    {
      // Advertised Device
      if (advertisedDevice.haveName())
      {
        // Name: Fermion: Sensor Beacon
        if(String(advertisedDevice.getName().c_str()) == "SHT40"){
          
          // strManufacturerData
          std::string strManufacturerData = advertisedDevice.getManufacturerData();
          uint8_t cManufacturerData[100];
          strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
          
          // strManufacturerData.length
          for (int i = 0; i < strManufacturerData.length(); i++)
          {

             // cManufacturerData[i]
             cManufacturerData[i];
             
          }

          // TemperatureData
          TemperatureData = int(cManufacturerData[2]<<8 | cManufacturerData[3]);
          // HumidityData
          HumidityData = int(cManufacturerData[5]<<8 | cManufacturerData[6]);
   
        }
        // Name: Fermion: Sensor Beacon
        if(String(advertisedDevice.getName().c_str()) == "Fermion: Sensor Beacon"){
          
          // strManufacturerData
          std::string strManufacturerData = advertisedDevice.getManufacturerData();
          uint8_t cManufacturerData[100];
          strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
          
          // strManufacturerData.length
          for (int i = 0; i < strManufacturerData.length(); i++)
          {

             // cManufacturerData[i]
             cManufacturerData[i];
             
          }

          // Sensor_Data
          Sensor_Data = int(cManufacturerData[2]<<8 | cManufacturerData[3]);
   
        }
        // Name: Fermion: Sensor Beacon
        if(String(advertisedDevice.getName().c_str()) == "Soil Moisture"){
          
          // strManufacturerData
          std::string strManufacturerData = advertisedDevice.getManufacturerData();
          uint8_t cManufacturerData[100];
          strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
          
          // strManufacturerData.length
          for (int i = 0; i < strManufacturerData.length(); i++)
          {

             // cManufacturerData[i]
             cManufacturerData[i];
             
          }

          // SensorSM
          SensorSM = int(cManufacturerData[2]<<8 | cManufacturerData[3]);
   
        }                              
      }
    }
};

// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";

// Software Version Information
String sver = "29-13";

void loop() {

  // DS3231 RTC Date and Time
  isRTC();

  // RHT Temperature and Humidity Sensor
  isRHT03();

  // Gas Sensors MQ
  isGasSensor();

  // isPIR Motion
  isPIR();
  
  // ScanResults
  isBLEScanResults();

  // Fermion: SHT40 Temperature & Humidity Sensor
  isSHT40();

  // Gravity: Analog Ambient Light Sensor
  isAmbientLight();

  // Soil Moisture
  isSoilMoisture();

  // Delay 4 Second
  delay(4000);

  // Read the state of the Switch value
  iSwitchState = digitalRead(iSwitch);
  
  // The Switch is HIGH:
  if (iSwitchState == HIGH) {

    // Display Date, Time, Temperature, Humidity
    isDisplayDTTH();
  
  } else {
    
    // Display Temperature, Humidity, MQ, PIR
    isDisplayDTMQPIR();

    
  }
  
  // MicroSD Card
  isSD();

  // iLED HIGH
  digitalWrite(iLED, HIGH );

  // Delay 1 Second
  delay(1000);

}

getAmbientLight.ino

// Gravity: Analog Ambient Light Sensor
// Ambient Light
void isAmbientLight(){

  // Analog Ambient Light Sensor
  // SData => 1~6000 Lux
  SData = map(Sensor_Data, 1, 3000, 1, 6000);

}

getBLEScan.ino

// getBLEScan
// Setup BLE Scan
void isSetupBLEScan(){

  // BLE Device
  BLEDevice::init("");
  // Create new scan
  pBLEScan = BLEDevice::getScan();
  // Set Advertised Device Callbacks
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  // Active scan uses more power, but get results faster
  pBLEScan->setActiveScan(true);
  // Set Interval
  pBLEScan->setInterval(100);
  // Less or equal setInterval value
  pBLEScan->setWindow(99);
  
}
// BLE Scan Results
void isBLEScanResults(){

  // Put your main code here, to run repeatedly:
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  // Delete results fromBLEScan buffer to release memory
  pBLEScan->clearResults();
  
}

getDisplay.ino

// SHARP Memory Display
// SHARP Memory Display - UID
void isDisplayUID() {

    // Text Display 
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Don Luc Electronics
    display.setCursor(0,10);
    display.println( "Don Luc" );
    display.setTextSize(2);
    display.setCursor(0,40);
    display.println( "Electronics" );
    // Version
    //display.setTextSize(3);
    display.setCursor(0,70);
    display.println( "Version" );
    //display.setTextSize(2);
    display.setCursor(0,95);   
    display.println( sver );
    // EEPROM
    display.setCursor(0,120);
    display.println( "EEPROM" );
    display.setCursor(0,140);   
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Date, Time, Temperature, Humidity, Ambient Light, Soil Moisture
void isDisplayDTTH() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Date
    display.setCursor(0,5);
    display.println( sDate );
    // Time
    display.setCursor(0,30);
    display.println( sTime );
    // Temperature
    display.setCursor(0,55);
    display.print( Temperature );
    display.println( "C" );
    // Humidity
    display.setCursor(0,80);
    display.print( Humidity );
    display.println( "%" );
    // Lux
    display.setCursor(0,105);
    display.println( SData );
    // Soil Moisture
    display.setCursor(0,130);
    display.println( SDataSM );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display Temperature, Humidity, MQ, PIR
void isDisplayDTMQPIR() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature
    display.setCursor(0,5);
    display.print( latestTempC );
    display.println( "C" );
    // Humidity
    display.setCursor(0,30);
    display.print( latestHumidity );
    display.println( "%" );
    // MQ-8
    display.setCursor(0,55);
    display.print( "MQ-8: " );
    display.print( iMQ8ppm );
    display.println( " PPM" );
    // MQ-9
    display.setCursor(0,80);
    display.print( "MQ-9: " );
    display.print( iMQ9ppm );
    display.println( " PPM" );
    // MQ-7
    display.setCursor(0,105);
    display.print( "MQ-7: " );
    display.print( iMQ7ppm );
    display.println( " PPM" );
    // MQ-3
    display.setCursor(0,130);
    display.print( "MQ-3: " );
    display.print( iMQ3ppm );
    display.println( "%" );
    // PIR
    display.setCursor(0,145);
    display.println( Det );
    // Refresh
    display.refresh();
    delay( 100 );

}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 

}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 4095);

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
  //return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void isSetupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";

  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRHT.ino

// RHT Temperature and Humidity Sensor
// Setup RHT Temperature and Humidity Sensor
void isSetupRTH03() {

  // RHT Temperature and Humidity Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT Temperature and Humidity Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();

}

getRTC.ino

// DS3231 RTC Date and Time
// Setup DS3231 RTC
void isSetupRTC() {

  if (! rtc.begin()) {
    while (1);
  }

  if (rtc.lostPower()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  
}
// DS3231 RTC Date and Time
void isRTC(){
 
    // Date and Time
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = rtc.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);

    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);

}

getSD.ino

// MicroSD Card
// MicroSD Setup
void setupSD() {

    // MicroSD Card
    pinMode( chipSelect , OUTPUT );
    if(!SD.begin( chipSelect )){
        ;  
        return;
    }
    
    uint8_t cardType = SD.cardType();

    // CARD NONE
    if(cardType == CARD_NONE){
        ; 
        return;
    }

    // SD Card Type
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

    // Size
    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
 
}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  // DFR|EEPROM Unique ID|Version|Date|Time|Temperature|Humidity|Lux|
  // Soil Moisture|Temperature|Humidity|MQ8|MQ9|MQ7|MQ3|PIR|*\r
  zzzzzz = "DFR|" + uid + "|" + sver + "|" + sDate + "|" + sTime + "|" 
  + String(Temperature) + "C|" + String(Humidity) + "%|" 
  + String(SData) + "|" + String(SDataSM) + "|" + String(latestTempC) + "C|" 
  + String(latestHumidity) + "%|" + String(iMQ8ppm) +   
  " PPM|" + String(iMQ9ppm) + " PPM|" + String(iMQ7ppm) + " PPM|" + 
  String(iMQ3ppm) + "%|" + String(Det) + "|*\r";

  // msg + 1
  char msg[zzzzzz.length() + 1];

  zzzzzz.toCharArray(msg, zzzzzz.length() + 1);

  // Append File
  appendFile(SD, "/dfrdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    // List Dir
    dirname;
    
    File root = fs.open(dirname);
    
    if(!root){
        return;
    }
    
    if(!root.isDirectory()){
        return;
    }

    File file = root.openNextFile();
    
    while(file){
        if(file.isDirectory()){
            file.name();
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            file.name();
            file.size();
        }
        file = root.openNextFile();
    }
    
}
// Write File
void writeFile(fs::FS &fs, const char * path, const char * message){
    
    // Write File
    path;
    
    File file = fs.open(path, FILE_WRITE);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}
// Append File
void appendFile(fs::FS &fs, const char * path, const char * message){
    
    // Append File
    path;
    
    File file = fs.open(path, FILE_APPEND);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}

getSHT40.ino

// Fermion: SHT40 Temperature & Humidity Sensor
// SHT40 Temperature & Humidity
void isSHT40(){

  // Fermion: SHT40 Temperature & Humidity Sensor
  // Temperature
  Temperature = (175 * TemperatureData/65535) - 45;
  // Humidity
  Humidity = (125 * HumidityData/65535) - 6;

}

getSoilMoisture.ino

// Gravity: Analog Soil Moisture Sensor
// Soil Moisture
void isSoilMoisture(){

  // SDataSM => 0~900 Soil Moisture
  SDataSM = map( SensorSM, 1, 3000, 0, 900);

}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);

  // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);
  
  // EEPROM Unique ID
  isUID();

  // Give display
  delay(100);

  // Set up I2C bus
  Wire.begin();

  // Give display
  delay(100);

  // Setup BLE Scan
  isSetupBLEScan();

  // Setup DS3231 RTC
  isSetupRTC();

  //MicroSD Card
  setupSD();

  // RHT Temperature and Humidity Sensor
  // Setup RTH03 Temperature and Humidity Sensor
  isSetupRTH03();

  // PIR Motion
  // Setup PIR
  isSetupPIR();

  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();

  // Initialize digital pin iLED as an output
  pinMode(iLED, OUTPUT);

  // Outputting high, the LED turns on
  digitalWrite(iLED, HIGH);

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);

  // iLEDGreen HIGH
  digitalWrite(iLEDGreen, HIGH );

  // Initialize the Switch
  pinMode(iSwitch, INPUT);

  // Don Luc Electronics
  // Version
  // EEPROM
  isDisplayUID();
  
  // Delay 5 Second
  delay( 5000 );

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Teacher, Instructor, E-Mentor, R&D and Consulting

  • Programming Language
  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi, Arm, Silicon Labs, Espressif, Etc…)
  • IoT
  • Wireless (Radio Frequency, Bluetooth, WiFi, Etc…)
  • Robotics
  • Automation
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Machine Learning
  • Artificial Intelligence (AI)
  • RTOS
  • Sensors, eHealth Sensors, Biosensor, and Biometric
  • Research & Development (R & D)
  • Consulting

Follow Us

Luc Paquin – Curriculum Vitae – 2024
https://www.donluc.com/luc/

Web: https://www.donluc.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/@thesass2063
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
LinkedIn: https://www.linkedin.com/in/jlucpaquin/

Don Luc

Project #28 – Sensors – PIR Motion Sensor – Mk13

——

#DonLucElectronics #DonLuc #Sensors #PIR #Adafruit #SparkFun #Pololu #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

PIR Motion Sensor

——

PIR Motion Sensor

——

PIR Motion Sensor

——

PIR Motion Sensor (JST)

This is a simple to use motion sensor. Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room. If anything moves after that period, the “Alarm” pin will go low. This unit works great from 5 to 12 Volt. The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin. The open drain setup allows multiple motion sensors to be connected on a single input pin. If any of the motion sensors go off, the input pin will be pulled low.

At their most fundamental level, PIR sensor’s are infrared-sensitive light detectors. By monitoring light in the infrared spectrum, PIR sensors can sense subtle changes in temperature across the area they’re viewing. When a human or some other object comes into the PIR’s field-of-view, the radiation pattern changes, and the PIR interprets that change as movement. All that’s left for us to connect is three pins: power, ground, and the output signal.

DL2401Mk02

1 x SparkFun Thing Plus – ESP32 WROOM
1 x DS3231 Precision RTC FeatherWing
1 x PIR Motion Sensor
1 x Pololu 5V Step-Up Voltage Regulator U1V10F5
1 x Rocker Switch – SPST
1 x Resistor 10K Ohm
1 x CR1220 3V Lithium Coin Cell Battery
1 x 1 x Lithium Ion Battery – 1000mAh
1 x Terminal Block Breakout FeatherWing
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

LED – LED_BUILTIN
SDA – Digital 23
SCL – Digital 22
SW1 – Digital 21
PIR – Digital 14
VIN – +3.3V
VIN – +5V
GND – GND

——

DL2401Mk01p.ino

/****** Don Luc Electronics © ******
Software Version Information
Project #28 - Sensors - PIR Motion Sensor - Mk13
28-13
DL2401Mk01p.ino
1 x SparkFun Thing Plus - ESP32 WROOM
1 x DS3231 Precision RTC FeatherWing
1 x PIR Motion Sensor
1 x Pololu 5V Step-Up Voltage Regulator U1V10F5
1 x Rocker Switch - SPST
1 x Resistor 10K Ohm
1 x Lithium Ion Battery - 1000mAh
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Bluetooth LE keyboard
#include <BleKeyboard.h>
// Two Wire Interface (TWI/I2C)
#include <Wire.h>
// Serial Peripheral Interface
#include <SPI.h>
// DS3231 Precision RTC 
#include <RTClib.h>

// Bluetooth LE Keyboard
BleKeyboard bleKeyboard;
String sKeyboard = "";
// Send Size
byte sendSize = 0;

// DS3231 Precision RTC 
RTC_DS3231 rtc;
String dateRTC = "";
String timeRTC = "";

// PIR Motion
// Motion detector
const int iMotion = 14;
// Proximity
int proximity = LOW;
String Det = "";

// The number of the Rocker Switch pin
int iSwitch = 21;
// Variable for reading the button status
int SwitchState = 0;

// Software Version Information
String sver = "28-13";

void loop() {

  // Date and Time RTC
  isRTC ();

  // isPIR Motion
  isPIR();

  // Read the state of the Switch value:
  SwitchState = digitalRead(iSwitch);

  // Check if the button is pressed. If it is, the SwitchState is HIGH:
  if (SwitchState == HIGH) {

    // Bluetooth LE Keyboard
    isBluetooth();

  }

  // Delay 1 Second
  delay(1000);

}

getBleKeyboard.ino

// Ble Keyboard
// Bluetooth
// isBluetooth
void isBluetooth() {

  // ESP32 BLE Keyboard
  if(bleKeyboard.isConnected()) {

    // Send Size Length
    sendSize = sKeyboard.length();

    // Send Size, charAt
    for(byte i = 0; i < sendSize+1; i++){

       // Write
       bleKeyboard.write(sKeyboard.charAt(i));
       delay(50);
    
    }
    bleKeyboard.write(KEY_RETURN);

  }

}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";

  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }

  sKeyboard = sKeyboard + String(Det) + "|*";
  
}

getRTC.ino

// Date & Time
// DS3231 Precision RTC
void isSetupRTC() {

  // DS3231 Precision RTC
  if (! rtc.begin()) {
    //Serial.println("Couldn't find RTC");
    //Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    //Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2023, 8, 10, 11, 0, 0));
  }
  
}
// Date and Time RTC
void isRTC () {

  // Date and Time
  dateRTC = "";
  timeRTC = "";
  DateTime now = rtc.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;

  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;

  // bleKeyboard
  sKeyboard = "SEN|" + sver + "|" + String(dateRTC) 
  + "|" + String(timeRTC) + "|";

}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);

  // Bluetooth LE keyboard
  bleKeyboard.begin();
  
  // Wire - Inialize I2C Hardware
  Wire.begin();

  // Give display time to power on
  delay(100);

  // Date & Time RTC
  // DS3231 Precision RTC 
  isSetupRTC();

  // Give display time to power on
  delay(100);
  
  // PIR Motion
  // Setup PIR
  setupPIR();
  
  // Initialize the Switch pin as an input
  pinMode(iSwitch, INPUT);

  // Initialize digital pin LED_BUILTIN as an output
  pinMode(LED_BUILTIN, OUTPUT);
  // Turn the LED on HIGH
  digitalWrite(LED_BUILTIN, HIGH);

  // Delay 5 Second
  delay( 5000 );

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Teacher, Instructor, E-Mentor, R&D and Consulting

  • Programming Language
  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi, Arm, Silicon Labs, Espressif, Etc…)
  • IoT
  • Wireless (Radio Frequency, Bluetooth, WiFi, Etc…)
  • Robotics
  • Automation
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Machine Learning
  • Artificial Intelligence (AI)
  • RTOS
  • eHealth Sensors, Biosensor, and Biometric
  • Research & Development (R & D)
  • Consulting

Follow Us

Luc Paquin – Curriculum Vitae – 2024
https://www.donluc.com/luc/

Web: https://www.donluc.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/@thesass2063
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #28 – Sensors – Pololu MinIMU-9 v5 – Mk04

——

#DonLucElectronics #DonLuc #Sensors #MinIMU9 #Pololu #Adafruit #SparkFun #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Pololu MinIMU-9 v5

——

Pololu MinIMU-9 v5

——

Pololu MinIMU-9 v5

——

Pololu MinIMU-9 v5 Gyro, Accelerometer, and Compass (LSM6DS33 and LIS3MDL Carrier)

The Pololu MinIMU-9 v5 is an inertial measurement unit (IMU) that packs an LSM6DS33 3-axis gyro and 3-axis accelerometer and an LIS3MDL 3-axis magnetometer onto a tiny 0.8″ × 0.5″ board. An I²C interface accesses nine independent rotation, acceleration, and magnetic measurements that can be used to calculate the sensor’s absolute orientation. The MinIMU-9 v5 board includes a voltage regulator and a level-shifting circuit that allow operation from 2.5 to 5.5 Volt.

DL2308Mk05

1 x Adafruit METRO M0 Express
1 x DS3231 Precision RTC FeatherWing
1 x Pololu MinIMU-9 v5 Gyro, Accelerometer, and Compass
1 x ProtoScrewShield
1 x Rocker Switch – SPST
1 x Resistor 10K Ohm
1 x CR1220 3V Lithium Coin Cell Battery
1 x SparkFun Cerberus USB Cable

Adafruit METRO M0 Express

LED – LED_BUILTIN
SDA – Digital 20
SCL – Digital 21
SW1 – Digital 2
VIN – +3.3V
GND – GND

——

DL2308Mk05p.ino

/****** Don Luc Electronics © ******
Software Version Information
Project #28 - Sensors - Pololu MinIMU-9 v5 - Mk04
28-04
DL2308Mk05p.ino
1 x Adafruit METRO M0 Express
1 x DS3231 Precision RTC FeatherWing
1 x Pololu MinIMU-9 v5 Gyro, Accelerometer, and Compass
1 x ProtoScrewShield
1 x Rocker Switch - SPST
1 x Resistor 10K Ohm
1 x CR1220 3V Lithium Coin Cell Battery
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// DS3231 Precision RTC 
#include <RTClib.h>
// Two Wire Interface (TWI/I2C)
#include <Wire.h>
// Keyboard
#include <Keyboard.h>
// Includes and variables for IMU integration
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
#include <LSM6.h>
// STMicroelectronics LIS3MDL Magnetometer
#include <LIS3MDL.h>

// Keyboard
String sKeyboard = "";

// DS3231 Precision RTC 
RTC_DS3231 rtc;
String dateRTC = "";
String timeRTC = "";

// Pololu 9DoF IMU
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
LSM6 imu;
// Accelerometer and Gyroscopes
// Accelerometer
int imuAX;
int imuAY;
int imuAZ;
// Gyroscopes 
int imuGX;
int imuGY;
int imuGZ;
// STMicroelectronics LIS3MDL Magnetometer
LIS3MDL mag;
// Magnetometer
int magX;
int magY;
int magZ;

// The number of the pushbutton pin
int iButton = 2;
// Variable for reading the button status
int buttonState = 0;

// Software Version Information
String sver = "28-04";

void loop() {

  // Date and Time RTC
  isRTC ();

  // Pololu Accelerometer and Gyroscopes
  isIMU();

  // Pololu Magnetometer
  isMag();

  // Read the state of the button value:
  buttonState = digitalRead(iButton);

  // Check if the button is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {

     Keyboard.println(sKeyboard);
    
  }

  // Delay 1 Second
  delay(1000);

}

getAccelGyro.ino

// Accelerometer and Gyroscopes
// Setup IMU
void setupIMU() {

  // Setup IMU
  imu.init();
  // Default
  imu.enableDefault();
  
}
// Accelerometer and Gyroscopes
void isIMU() {

  // Accelerometer and Gyroscopes
  imu.read();
  // Accelerometer x, y, z
  imuAX = imu.a.x;
  imuAY = imu.a.y;
  imuAZ = imu.a.z;
  // Gyroscopes x, y, z
  imuGX = imu.g.x;
  imuGY = imu.g.y;
  imuGZ = imu.g.z;

  sKeyboard = sKeyboard + String(imuAX) + "|" + String(imuAY) + "|" + String(imuAZ) + "|";
  sKeyboard = sKeyboard + String(imuGX) + "|" + String(imuGY) + "|" + String(imuGZ) + "|";
  
}

getIMUMagnetometer.ino

// IMU Magnetometer
// Setup Magnetometer
void setupMag() {

  // Setup Magnetometer
  mag.init();
  // Default
  mag.enableDefault();
  
}
// Magnetometer
void isMag() {

  // Magnetometer
  mag.read();
  // Magnetometer x, y, z
  magX = mag.m.x;
  magY = mag.m.y;
  magZ = mag.m.z;

  sKeyboard = sKeyboard + String(magX) + "|" + String(magY) + "|" + String(magZ) + "|*";
  
}

getRTC.ino

// Date & Time
// DS3231 Precision RTC
void setupRTC() {

  // DS3231 Precision RTC
  if (! rtc.begin()) {
    //Serial.println("Couldn't find RTC");
    //Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    //Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2023, 8, 10, 11, 0, 0));
  }
  
}
// Date and Time RTC
void isRTC () {

  // Date and Time
  dateRTC = "";
  timeRTC = "";
  DateTime now = rtc.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;

  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;

  sKeyboard = "SEN|" + sver + "|" + String(dateRTC) + "|" + 
  String(timeRTC) + "|";
  
}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);
  
  // Wire - Inialize I2C Hardware
  Wire.begin();

  // Give display time to power on
  delay(100);

  // Date & Time RTC
  // DS3231 Precision RTC 
  setupRTC();
  
  // Initialize control over the keyboard:
  Keyboard.begin();

  // Pololu Setup IMU
  setupIMU();

  // Pololu Setup Magnetometer
  setupMag();

  // Initialize the button pin as an input
  pinMode(iButton, INPUT);

  // Initialize digital pin LED_BUILTIN as an output
  pinMode(LED_BUILTIN, OUTPUT);
  // Turn the LED on HIGH
  digitalWrite(LED_BUILTIN, HIGH);

  // Delay 5 Second
  delay( 5000 );

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Programming Language
  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Wireless (Radio Frequency, Bluetooth, WiFi, Etc…)
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Machine Learning
  • RTOS
  • Research & Development (R & D)

Instructor, E-Mentor, STEAM, and Arts-Based Training

  • Programming Language
  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

Luc Paquin – Curriculum Vitae – 2023
https://www.donluc.com/luc/

Web: https://www.donluc.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/@thesass2063
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #15: Environment – HC-SR04 Ultrasonic Sensor – Mk18

——

#DonLucElectronics #DonLuc #Environment #MQ #PIR #HCSR04 #RHT03 #RTC #ArduinoUNO #Arduino #AdafruitPowerBoost #Project #Programming #Electronics #Microcontrollers #Consultant

——

HC-SR04

——

HC-SR04

——

HC-SR04

——

HC-SR04

——

HC-SR04 Ultrasonic Sensor

This is the HC-SR04 ultrasonic distance sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.

There are only four pins that you need to worry about on the HC-SR04: VCC (Power), Trig (Trigger), Echo (Receive), and GND (Ground). You will find this sensor very easy to set up and use for your next range-finding project. This sensor has additional control circuitry that can prevent inconsistent “bouncy” data depending on the application.

DL2110Mk05

1 x Arduino UNO – R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16×2 Character Negative Display
1 x HC-SR04 Ultrasonic Sensor
1 x ChronoDot – Ultra-Precise Real Time Clock – v2.1
1 x CR1632 Batteries
1 x MicroSD Card Breakout Board+
1 x MicroSD 2.0 GB
1 x Rocker Switch – SPST (Round)
1 x 10K Ohm
1 x LED Green
1 x 220 Ohm
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery – 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor- RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable

Arduino UNO – R3

CLK – Digital 13
DO – Digital 12
DI – Digital 11
CS – Digital 10
ECH – Digital 9
TIR – Digital 8
PIR – Digital 7
RHT – Digital 5
RS0 – Digital 3
LEG – Digital 2
MQ8 – Analog 0
MQ9 – Analog 1
MQ7 – Analog 2
MQ3 – Analog 3
SDA – Analog 4
SCL – Analog 5
VIN – +5V
GND – GND

DL2110Mk05p.ino

/* 
***** Don Luc Electronics © *****
Software Version Information
Project #15: Environment – HC-SR04 Ultrasonic Sensor – Mk18
10-05
DL2110Mk05p.ino
1 x Arduino UNO - R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16x2 Character Negative Display
1 x HC-SR04 Ultrasonic Sensor
1 x ChronoDot - Ultra-Precise Real Time Clock - v2.1
1 x CR1632 Batteries
1 x MicroSD Card Breakout Board+
1 x MicroSD 2.0 GB
1 x Rocker Switch - SPST (Round)
1 x 10K Ohm
1 x LED Green
1 x 220 Ohm
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery - 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor - MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor - MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor - RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include <EEPROM.h>
// RHT Temperature and Humidity Sensor
#include <SparkFun_RHT03.h>
// Adafruit RGB LCD Shield 16x2
#include <Adafruit_RGBLCDShield.h>
// Wire
#include <Wire.h>
// DS3231 RTC Date and Time
#include <RTClib.h>
// SD Card
#include <SPI.h>
#include <SD.h>

// RHT Temperature and Humidity Sensor
// RHT03 data pin Digital 5
const int RHT03_DATA_PIN = 5;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A0;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet.
// With these two points, a line is formed which is
// "approximately equivalent" to the original curve.
float H2Curve[3] = {2.3, 0.93,-1.44};

// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A1;
int iMQ9Raw = 0;
int iMQ9ppm = 0;

// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A2;
int iMQ7Raw = 0;
int iMQ7ppm = 0;

// Alcohol Gas Sensor - MQ-3
int iMQ3 = A3;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// PIR Motion
// Motion detector
const int iMotion = 7;
// Proximity
int proximity = LOW;
String Det = "";

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// DS3231 RTC Date and Time
RTC_DS3231 rtc;
String sDate;
String sTime;

// SD Card
const int chipSelect = 10;
String zzzzzz = "";

// LED Green
int iLEDGreen = 2;

// Rocker Switch - SPST (Round)
int iSS1 = 3;
// State
int iSS1State = 0;

// HC-SR04 Ultrasonic Sensor
int iTrig = 8;
int iEcho = 9;
// Stores the distance measured by the distance sensor
float distance = 0;

// Software Version Information
String uid = "";
// Version
String sver = "15-18";

void loop()
{
     
  // Adafruit RGB LCD Shield
  // Clear
  RGBLCDShield.clear();

  // iLEDGreen LOW
  digitalWrite(iLEDGreen,  LOW );
  
  // RHT Temperature and Humidity Sensor
  isRHT03();

  // Gas Sensors MQ
  isGasSensor();

  // isPIR Motion
  isPIR();

  // DS3231 RTC Date and Time
  isRTC();
  
  // HC-SR04 Ultrasonic Sensor
  isHCSR04();

  // Adafruit RGB LCD Shield
  // Display
  isDisplay();

  // Slide Switch
  // Read the state of the iSS1 value
  iSS1State = digitalRead(iSS1);
  
  // If it is the Slide Switch State is HIGH
  if (iSS1State == HIGH) {

    // iLEDGreen HIGH
    digitalWrite(iLEDGreen,  HIGH );
    
    // MicroSD Card
    isSD();

  } else {

    // iLEDGreen LOW
    digitalWrite(iLEDGreen,  LOW );
  
  }

  // Delay
  delay( 500 );
 
}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 

}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getHC-SR04.ino

// HC-SR04 Ultrasonic Sensor
// Setup HC-SR04
void setupHCSR04() {

  // The trigger iTrig will output pulses of electricity
  pinMode(iTrig, OUTPUT);
  // The echo iEcho will measure the duration of pulses coming back from the distance sensor
  pinMode(iEcho, INPUT);
  
}
// HC-SR04
void isHCSR04() {

  // Variable to store the distance measured by the sensor
  distance = isDistance();
    
}
// Distance
float isDistance() {
  
  // Variable to store the time it takes for a ping to bounce off an object
  float echoTime;
  // Variable to store the distance calculated from the echo time
  float calculatedDistance;

  // Send out an ultrasonic pulse that's 10ms long
  digitalWrite(iTrig, HIGH);
  delayMicroseconds(10);
  digitalWrite(iTrig, LOW);

  // Use the pulseIn command to see how long it takes for the
  // pulse to bounce back to the sensor
  echoTime = pulseIn(iEcho, HIGH);

  // Calculate the distance of the object that reflected the pulse
  // (half the bounce time multiplied by the speed of sound)
  // cm = 58.0
  calculatedDistance = echoTime / 58.0;

  // Send back the distance that was calculated
  return calculatedDistance;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";

  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRGBLCDShield.ino

// Adafruit RGB LCD Shield
// Setup RGB LCD Shield
void isSetupRGBLCDShield() {

  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(RED);
  // Don luc 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Don Luc");
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Electronics
  RGBLCDShield.print("Electronics");
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(TEAL);
  // Version 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Version: " + sver);
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Unit ID
  RGBLCDShield.print("Unit ID: " + uid);
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();
  
}
// isDisplay
void isDisplay() {

  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // RHT Temperature and Humidity Sensor
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Temperature C
      RGBLCDShield.print( "Temp C: " );
      RGBLCDShield.print( latestTempC );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Humidity
      RGBLCDShield.print( "Humidity: " );
      RGBLCDShield.print( latestHumidity );

      break;
    case 2:
    
      // Set the cursor to column 0, line 0
      // PIR Motion Sensor
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( "PIR: " );
      RGBLCDShield.print( Det );
      // Set the cursor to column 0, line 1
      // HC-SR04 Ultrasonic Sensor
      RGBLCDShield.setCursor(0, 1);
      RGBLCDShield.print( "HC-SR04: " );
      RGBLCDShield.print( distance );
      
      break;
    case 3:

      // Gas Sensors 1
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Hydrogen Gas Sensor - MQ-8
      RGBLCDShield.print( "MQ-8: " );
      RGBLCDShield.print( iMQ8ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Carbon Monoxide & Flammable Gas Sensor - MQ-9
      RGBLCDShield.print( "MQ-9: " );
      RGBLCDShield.print( iMQ9ppm );
      
      break;
    case 4:

      // Gas Sensors 2
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Carbon Monoxide Gas Sensor - MQ-7
      RGBLCDShield.print( "MQ-7: " );
      RGBLCDShield.print( iMQ7ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Alcohol Gas Sensor - MQ-3
      RGBLCDShield.print( "MQ-3: " );
      RGBLCDShield.print( iMQ3ppm );
      
      break;
    case 5:

      // DS3231 RTC Date and Time
      // Date and Time
      DateTime now = rtc.now();
      // Set the cursor to column 0, line 0
      // Date 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( sDate );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Time
      RGBLCDShield.print( sTime );
      
      break;
    default:

      // Don luc Electronics
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      // Set the cursor to column 0, line 0
      // Don luc 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print("Don Luc");
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Electronics
      RGBLCDShield.print("Electronics");

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // RHT Temperature and Humidity Sensor
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // PIR Motion Sensor
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // Gas Sensors 1
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // Gas Sensors 2
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // DS3231 RTC Date and Time
      RGBLCDShield.setBacklight(WHITE);
   
    }
    
  }
  
}

getRHT.ino

// RHT Temperature and Humidity Sensor
// setup RHT Temperature and Humidity Sensor
void setupRTH03() {

  // RHT Temperature and Humidity Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT Temperature and Humidity Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();

}

getRTC.ino

// DS3231 RTC Date and Time
// Setup DS3231 RTC
void isSetupRTC() {

  if (! rtc.begin()) {
    while (1);
  }

  if (rtc.lostPower()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  
}
// DS3231 RTC Date and Time
void isRTC(){
 
    // Date and Time
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = rtc.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);
    
}

getSD.ino

// MicroSD Card
// MicroSD Setup
void setupSD() {

  // MicroSD Card
  if (!SD.begin(chipSelect)) {

     while (true);

  }
 
}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  // Don Luc Electronics © (1983-2021)
  // Arduino Data
  // EEPROM Unique ID
  // Version
  // Date
  // Time
  // Temperature Celsius
  // Humidity
  // Hydrogen Gas Sensor - MQ-8
  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  // Carbon Monoxide Gas Sensor - MQ-7
  // Alcohol Gas Sensor - MQ-3
  // PIR Motion
  // HC-SR04 Ultrasonic Sensor
  // EEPROM Unique ID|Version|Date|Time|Temperature Celsius|Humidity|MQ-8|MQ-9|MQ-7|MQ-3|PIR Motion|HC-SR04|
  zzzzzz = uid + "|" + sver + "|" + sDate + "|" + sTime + "|" + latestTempC + "|" + latestHumidity + "|"
  + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + 
  iMQ3ppm + "|" + Det + "|" + distance + "|";

  
  // Open the file. Note that only one file can be open at a time,
  // so you have to close this one before opening another.

  File dataFile = SD.open("arddata.txt", FILE_WRITE);

  // If the file is available, write to it:
  if ( dataFile ) {

    dataFile.println( zzzzzz );

    dataFile.close();

  }
  
}

setup.ino

// Setup
void setup()
{
    
  // EEPROM Unique ID
  isUID();
  
  // RHT Temperature and Humidity Sensor
  // Setup RTH03 Temperature and Humidity Sensor
  setupRTH03();

  // PIR Motion
  // Setup PIR
  setupPIR();

  // Setup DS3231 RTC
  isSetupRTC();

  //MicroSD Card
  setupSD();

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);
  // iLEDGreen LOW
  digitalWrite(iLEDGreen,  LOW );

  // Slide Switch
  pinMode(iSS1, INPUT);

  // Setup HC-SR04
  setupHCSR04();

  // Adafruit RGB LCD Shield
  isSetupRGBLCDShield();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2021 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #15: Environment – MicroSD Card – Mk17

——

#DonLucElectronics #DonLuc #Environment #MQ #PIR #RHT03 #RTC #ArduinoUNO #Arduino #AdafruitPowerBoost #Project #Programming #Electronics #Microcontrollers #Consultant

——

MicroSD Card

——

MicroSD Card

——

MicroSD Card

——

MicroSD Card

——

MicroSD Card Breakout Board+

Not just a simple breakout board, this microSD adapter goes the extra mile – designed for ease of use.

  • -Onboard 5v->3v regulator provides 150mA for power-hungry cards
  • -3v level shifting means you can use this with ease on either 3v or 5v systems
  • -Uses a proper level shifting chip, not resistors: less problems, and faster read/write access
  • -Use 3 or 4 digital pins to read and write 2Gb+ of storage
  • -Activity LED lights up when the SD card is being read or written
  • -Push-push socket with card slightly over the edge of the PCB so its easy to insert and remove
  • -Comes with 0.1″ header so you can get it on a breadboard or use wires

To use with an Arduino, connect GND to ground, 5V to 5V, CLK to pin 13, DO to pin 12, DI to pin 11, and CS to pin 10.

DL2110Mk04

1 x Arduino UNO – R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16×2 Character Negative Display
1 x ChronoDot – Ultra-Precise Real Time Clock – v2.1
1 x MicroSD Card Breakout Board+
1 x MicroSD 2.0 GB
1 x Rocker Switch – SPST (Round)
1 x 10K Ohm
1 x LED Green
1 x 220 Ohm
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery – 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor- RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable

Arduino UNO – R3

CLK – Digital 13
DO – Digital 12
DI – Digital 11
CS – Digital 10
PIR – Digital 7
RHT – Digital 5
RS0 – Digital 3
LEG – Digital 2
MQ8 – Analog 0
MQ9 – Analog 1
MQ7 – Analog 2
MQ3 – Analog 3
SDA – Analog 4
SCL – Analog 5
VIN – +5V
GND – GND

——

DL2110Mk04p.ino

/* 
***** Don Luc Electronics © *****
Software Version Information
Project #15: Environment – MicroSD Card – Mk17
10-04
DL2110Mk04p.ino
1 x Arduino UNO - R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16x2 Character Negative Display
1 x ChronoDot - Ultra-Precise Real Time Clock - v2.1
1 x MicroSD Card Breakout Board+
1 x MicroSD 2.0 GB
1 x Rocker Switch - SPST (Round)
1 x 10K Ohm
1 x LED Green
1 x 220 Ohm
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery - 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor - MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor - MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor - RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include <EEPROM.h>
// RHT Temperature and Humidity Sensor
#include <SparkFun_RHT03.h>
// Adafruit RGB LCD Shield 16x2
#include <Adafruit_RGBLCDShield.h>
// Wire
#include <Wire.h>
// DS3231 RTC Date and Time
#include <RTClib.h>
// SD Card
#include <SPI.h>
#include <SD.h>

// RHT Temperature and Humidity Sensor
// RHT03 data pin Digital 5
const int RHT03_DATA_PIN = 5;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A0;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet.
// With these two points, a line is formed which is
// "approximately equivalent" to the original curve.
float H2Curve[3] = {2.3, 0.93,-1.44};

// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A1;
int iMQ9Raw = 0;
int iMQ9ppm = 0;

// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A2;
int iMQ7Raw = 0;
int iMQ7ppm = 0;

// Alcohol Gas Sensor - MQ-3
int iMQ3 = A3;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// PIR Motion
// Motion detector
const int iMotion = 7;
// Proximity
int proximity = LOW;
String Det = "";

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// DS3231 RTC Date and Time
RTC_DS3231 rtc;
String sDate;
String sTime;

// SD Card
const int chipSelect = 10;
String zzzzzz = "";

// LED Green
int iLEDGreen = 2;

// Rocker Switch - SPST (Round)
int iSS1 = 3;
// State
int iSS1State = 0;

// Software Version Information
String uid = "";
// Version
String sver = "15-17";

void loop()
{
     
  // Adafruit RGB LCD Shield
  // Clear
  RGBLCDShield.clear();

  // iLEDGreen LOW
  digitalWrite(iLEDGreen,  LOW );
  
  // RHT Temperature and Humidity Sensor
  isRHT03();

  // Gas Sensors MQ
  isGasSensor();

  // isPIR Motion
  isPIR();

  // DS3231 RTC Date and Time
  isRTC();

  // Adafruit RGB LCD Shield
  // Display
  isDisplay();

  // Slide Switch
  // Read the state of the iSS1 value
  iSS1State = digitalRead(iSS1);
  
  // If it is the Slide Switch State is HIGH
  if (iSS1State == HIGH) {

    // iLEDGreen HIGH
    digitalWrite(iLEDGreen,  HIGH );
    
    // MicroSD Card
    isSD();

  } else {

    // iLEDGreen LOW
    digitalWrite(iLEDGreen,  LOW );
  
  }

  // Delay
  delay( 1000 );
 
}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 

}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";

  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRGBLCDShield.ino

// Adafruit RGB LCD Shield
// Setup RGB LCD Shield
void isSetupRGBLCDShield() {

  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(RED);
  // Don luc 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Don Luc");
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Electronics
  RGBLCDShield.print("Electronics");
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(TEAL);
  // Version 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Version: " + sver);
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Unit ID
  RGBLCDShield.print("Unit ID: " + uid);
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();
  
}
// isDisplay
void isDisplay() {

  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // RHT Temperature and Humidity Sensor
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Temperature C
      RGBLCDShield.print( "Temp C: " );
      RGBLCDShield.print( latestTempC );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Humidity
      RGBLCDShield.print( "Humidity: " );
      RGBLCDShield.print( latestHumidity );

      break;
    case 2:
    
      // PIR Motion Sensor
      // Set the cursor to column 0, line 0
      // PIR Motion Sensor
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( "PIR Motion" );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Det
      RGBLCDShield.print( Det );
      
      break;
    case 3:

      // Gas Sensors 1
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Hydrogen Gas Sensor - MQ-8
      RGBLCDShield.print( "MQ-8: " );
      RGBLCDShield.print( iMQ8ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Carbon Monoxide & Flammable Gas Sensor - MQ-9
      RGBLCDShield.print( "MQ-9: " );
      RGBLCDShield.print( iMQ9ppm );
      
      break;
    case 4:

      // Gas Sensors 2
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Carbon Monoxide Gas Sensor - MQ-7
      RGBLCDShield.print( "MQ-7: " );
      RGBLCDShield.print( iMQ7ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Alcohol Gas Sensor - MQ-3
      RGBLCDShield.print( "MQ-3: " );
      RGBLCDShield.print( iMQ3ppm );
      
      break;
    case 5:

      // DS3231 RTC Date and Time
      // Date and Time
      DateTime now = rtc.now();
      // Set the cursor to column 0, line 0
      // Date 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( sDate );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Time
      RGBLCDShield.print( sTime );
      
      break;
    default:

      // Don luc Electronics
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      // Set the cursor to column 0, line 0
      // Don luc 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print("Don Luc");
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Electronics
      RGBLCDShield.print("Electronics");

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // RHT Temperature and Humidity Sensor
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // PIR Motion Sensor
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // Gas Sensors 1
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // Gas Sensors 2
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // DS3231 RTC Date and Time
      RGBLCDShield.setBacklight(WHITE);
   
    }
    
  }
  
}

getRHT.ino

// RHT Temperature and Humidity Sensor
// setup RHT Temperature and Humidity Sensor
void setupRTH03() {

  // RHT Temperature and Humidity Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT Temperature and Humidity Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();

}

getRTC.ino

// DS3231 RTC Date and Time
// Setup DS3231 RTC
void isSetupRTC() {

  if (! rtc.begin()) {
    while (1);
  }

  if (rtc.lostPower()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  
}
// DS3231 RTC Date and Time
void isRTC(){
 
    // Date and Time
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = rtc.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);
    
}

getSD.ino

// MicroSD Card
// MicroSD Setup
void setupSD() {

  // MicroSD Card
  if (!SD.begin(chipSelect)) {

     while (true);

  }
 
}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  // Don Luc Electronics © (1983-2021)
  // Arduino Data
  // EEPROM Unique ID
  // Version
  // Date
  // Time
  // Temperature Celsius
  // Humidity
  // Hydrogen Gas Sensor - MQ-8
  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  // Carbon Monoxide Gas Sensor - MQ-7
  // Alcohol Gas Sensor - MQ-3
  // PIR Motion
  // EEPROM Unique ID|Version|Date|Time|Temperature Celsius|Humidity|MQ-8|MQ-9|MQ-7|MQ-3|PIR Motion|\r
  zzzzzz = uid + "|" + sver + "|" + sDate + "|" + sTime + "|" + latestTempC + "|" + latestHumidity + "|"
  + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + 
  iMQ3ppm + "|" + Det + "|";

  
  // Open the file. Note that only one file can be open at a time,
  // so you have to close this one before opening another.

  File dataFile = SD.open("arddata.txt", FILE_WRITE);

  // If the file is available, write to it:
  if ( dataFile ) {

    dataFile.println( zzzzzz );

    dataFile.close();

  }
  
}

setup.ino

// Setup
void setup()
{
    
  // EEPROM Unique ID
  isUID();
  
  // RHT Temperature and Humidity Sensor
  // Setup RTH03 Temperature and Humidity Sensor
  setupRTH03();

  // PIR Motion
  // Setup PIR
  setupPIR();

  // Setup DS3231 RTC
  isSetupRTC();

  //MicroSD Card
  setupSD();

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);
  // iLEDGreen LOW
  digitalWrite(iLEDGreen,  LOW );

  // Slide Switch
  pinMode(iSS1, INPUT);

  // Adafruit RGB LCD Shield
  isSetupRGBLCDShield();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2021 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #15: Environment – ChronoDot – Mk16

——

#DonLucElectronics #DonLuc #Environment #MQ #PIR #RHT03 #RTC #ArduinoUNO #Arduino #AdafruitPowerBoost #Project #Programming #Electronics #Microcontrollers #Consultant #VideoBlog

——

ChronoDot

——

ChronoDot

——

ChronoDot

——

ChronoDot

——

ChronoDot – Ultra-Precise Real Time Clock – v2.1

The ChronoDot RTC is an extremely accurate real time clock module, based on the DS3231 temperature compensated RTC. It includes a CR1632 battery, which should last at least 8 years if the I2C interface is only used while the device has 5V power available. No external crystal or tuning capacitors are required.

The top side of the Chronodot now features a battery holder for 16mm 3V lithium coin cells. It pairs particularly well with CR1632 batteries. The DS3231 has an internal crystal and a switched bank of tuning capacitors. The temperature of the crystal is continously monitored, and the capacitors are adjusted to maintain a stable frequency. Other RTC solutions may drift minutes per month, especially in extreme temperature ranges…the ChronoDot will drift less than a minute per year. This makes the ChronoDot very well suited for time critical applications that cannot be regularly synchronized to an external clock.

DL2110Mk03

1 x Arduino UNO – R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16×2 Character Negative Display
1 x ChronoDot – Ultra-Precise Real Time Clock – v2.1
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery – 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor- RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable

Arduino UNO – R3

RHT – Digital 5
PIR – Digital 7
MQ8 – Analog 0
MQ9 – Analog 1
MQ7 – Analog 2
MQ3 – Analog 3
SDA – Analog 4
SCL – Analog 5
VIN – +5V
GND – GND

——

DL2110Mk03p.ino

/* 
***** Don Luc Electronics © *****
Software Version Information
Project #15: Environment – ChronoDot – Mk16
10-03
DL2110Mk03p.ino
1 x Arduino UNO - R3
1 x ProtoScrewShield
1 x RGB LCD Shield 16x2 Character Negative Display
1 x ChronoDot - Ultra-Precise Real Time Clock - v2.1
1 x Adafruit PowerBoost 500 Shield
1 x Lithium Ion Battery - 3.7v 2000mAh
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor - MQ-8
1 x 4.7K Ohm
1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
1 x 22k Ohm
1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
1 x 10K Ohm
1 x SparkFun Alcohol Gas Sensor - MQ-3
1 x 220k Ohm
1 x Temperature and Humidity Sensor - RHT03
1 x PIR Motion Sensor (JST)
1 x SparkFun Solderable Half-Breadboard
1 x Half-Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include <EEPROM.h>
// RHT Temperature and Humidity Sensor
#include <SparkFun_RHT03.h>
// Adafruit RGB LCD Shield 16x2
#include <Adafruit_RGBLCDShield.h>
// Wire
#include <Wire.h>
// DS3231 RTC Date and Time
#include <RTClib.h>

// RHT Temperature and Humidity Sensor
// RHT03 data pin Digital 5
const int RHT03_DATA_PIN = 5;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A0;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet.
// With these two points, a line is formed which is
// "approximately equivalent" to the original curve.
float H2Curve[3] = {2.3, 0.93,-1.44};

// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A1;
int iMQ9Raw = 0;
int iMQ9ppm = 0;

// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A2;
int iMQ7Raw = 0;
int iMQ7ppm = 0;

// Alcohol Gas Sensor - MQ-3
int iMQ3 = A3;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// PIR Motion
// Motion detector
const int iMotion = 7;
// Proximity
int proximity = LOW;
String Det = "";

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// DS3231 RTC Date and Time
RTC_DS3231 rtc;
String sDate;
String sTime;

// Software Version Information
String uid = "";
// Version
String sver = "15-16";

void loop()
{
     
  // Adafruit RGB LCD Shield
  // Clear
  RGBLCDShield.clear();
  
  // RHT Temperature and Humidity Sensor
  isRHT03();

  // Gas Sensors MQ
  isGasSensor();

  // isPIR Motion
  isPIR();

  // DS3231 RTC Date and Time
  isRTC();

  // Adafruit RGB LCD Shield
  // Display
  isDisplay();

  // Delay
  // Turn the LED on HIGH is the voltage level
  digitalWrite(LED_BUILTIN, HIGH);
  // Wait for a 0.5 second
  delay( 500 );
  // Turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
  // Wait for a 0.5 second
  delay( 500 );
 
}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 

}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";

  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRGBLCDShield.ino

// Adafruit RGB LCD Shield
// Setup RGB LCD Shield
void isSetupRGBLCDShield() {

  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(RED);
  // Don luc 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Don Luc");
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Electronics
  RGBLCDShield.print("Electronics");
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();

  // Set the cursor to column 0, line 0
  RGBLCDShield.setBacklight(TEAL);
  // Version 
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Version: " + sver);
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  // Unit ID
  RGBLCDShield.print("Unit ID: " + uid);
  // Delay
  delay(5000);
  // Clear
  RGBLCDShield.clear();
  
}
// isDisplay
void isDisplay() {

  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // RHT Temperature and Humidity Sensor
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Temperature C
      RGBLCDShield.print( "Temp C: " );
      RGBLCDShield.print( latestTempC );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Humidity
      RGBLCDShield.print( "Humidity: " );
      RGBLCDShield.print( latestHumidity );

      break;
    case 2:
    
      // PIR Motion Sensor
      // Set the cursor to column 0, line 0
      // PIR Motion Sensor
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( "PIR Motion" );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Det
      RGBLCDShield.print( Det );
      
      break;
    case 3:

      // Gas Sensors 1
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Hydrogen Gas Sensor - MQ-8
      RGBLCDShield.print( "MQ-8: " );
      RGBLCDShield.print( iMQ8ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Carbon Monoxide & Flammable Gas Sensor - MQ-9
      RGBLCDShield.print( "MQ-9: " );
      RGBLCDShield.print( iMQ9ppm );
      
      break;
    case 4:

      // Gas Sensors 2
      // Set the cursor to column 0, line 0
      RGBLCDShield.setCursor(0,0);
      // Carbon Monoxide Gas Sensor - MQ-7
      RGBLCDShield.print( "MQ-7: " );
      RGBLCDShield.print( iMQ7ppm );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Alcohol Gas Sensor - MQ-3
      RGBLCDShield.print( "MQ-3: " );
      RGBLCDShield.print( iMQ3ppm );
      
      break;
    case 5:

      // DS3231 RTC Date and Time
      // Date and Time
      DateTime now = rtc.now();
      // Set the cursor to column 0, line 0
      // Date 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print( sDate );
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Time
      RGBLCDShield.print( sTime );
      
      break;
    default:

      // Don luc Electronics
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      // Set the cursor to column 0, line 0
      // Don luc 
      RGBLCDShield.setCursor(0,0);
      RGBLCDShield.print("Don Luc");
      // Set the cursor to column 0, line 1
      RGBLCDShield.setCursor(0, 1);
      // Electronics
      RGBLCDShield.print("Electronics");

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // RHT Temperature and Humidity Sensor
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // PIR Motion Sensor
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // Gas Sensors 1
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // Gas Sensors 2
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // DS3231 RTC Date and Time
      RGBLCDShield.setBacklight(WHITE);
   
    }
    
  }
  
}

getRHT.ino

// RHT Temperature and Humidity Sensor
// setup RHT Temperature and Humidity Sensor
void setupRTH03() {

  // RHT Temperature and Humidity Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT Temperature and Humidity Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();

}

getRTC.ino

// DS3231 RTC Date and Time
// Setup DS3231 RTC
void isSetupRTC() {

  if (! rtc.begin()) {
    while (1);
  }

  if (rtc.lostPower()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  
}
// DS3231 RTC Date and Time
void isRTC(){
 
    // Date and Time
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = rtc.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);
    
}

setup.ino

// Setup
void setup()
{
    
  // EEPROM Unique ID
  isUID();
  
  // RHT Temperature and Humidity Sensor
  // Setup RTH03 Temperature and Humidity Sensor
  setupRTH03();

  // PIR Motion
  // Setup PIR
  setupPIR();

  // Setup DS3231 RTC
  isSetupRTC();

  // Initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);

  // Adafruit RGB LCD Shield
  isSetupRGBLCDShield();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor and E-Mentor

  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2021 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Web: https://zoom.us/
Patreon: https://www.patreon.com/DonLucElectronics
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #14: Components – SparkFun Solderable Breadboard – Mk20

——

#DonLuc #Electronics #Components #SolderableBreadboard #Microcontrollers #Environment #SparkFun #Consultant #Vlog #Aphasia

——

Components

——

Components

——

SparkFun Solderable Breadboard

SparkFun Item: PRT-12070

This is the SparkFun Solderable Breadboard. A bare PCB that is the exact size as our regular breadboard with the same connections to pins and power rails. This board is especially useful for preserving a prototype or experiment you just created on a solderless breadboard by soldering all the pieces in place.

Technology Experience

  • Single-Board Microcontrollers (Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #15: Environment – PIR Motion Sensor – Mk12

——

#DonLuc #Environment #ESP32 #MQ #GPS #EMF #PIR #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Consultant #Electronics #Microcontrollers #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

PIR Motion Sensor (JST)

SparkFun Item: SEN-13285

This is a simple to use motion sensor. Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room. If anything moves after that period, the ‘alarm’ pin will go low. The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin. The open drain setup allows multiple motion sensors to be connected on a single input pin. If any of the motion sensors go off, the input pin will be pulled low.

We’ve finally updated the connector! Gone is the old “odd” connector, now you will find a common 3-pin JST! This makes the PIR Sensor much more accessible for whatever your project may need. Red = Power, White = Ground, and Black = Alarm.

DL2006Mk02

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x Telescopic Antenna SMA – 300 MHz to 1.1 GHz (ANT700)
1 x SMA Connector
1 x Humidity and Temperature Sensor – RHT03
1 x PIR Motion Sensor (JST)
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
1 x 200k Ohm
1 x 3.3m Ohm
12 x Jumper Wires 3in M/M
13 x Jumper Wires 6in M/M
20 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A1
MH1 – Analog A0
MC1 – Analog A2
MC2 – Analog A3
MA1 – Analog A4
EMF – Analog A5
GPS – Digital 14
RHT – Digital 15
PIR – Digital 17
VIN – +3.3V
GND – GND

DL2006Mk02p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - PIR Motion Sensor (JST) - Mk12
// 06-02
// DL2006Mk02p.ino 15-12
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 4 x Pololu Carrier for MQ Gas Sensors
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x SparkFun Alcohol Gas Sensor - MQ-3
// 1 x Telescopic Antenna SMA - 300 MHz to 1.1 GHz (ANT700)
// 1 x SMA Connector
// 1 x Humidity and Temperature Sensor - RHT03
// 1 x PIR Motion Sensor (JST)
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 2 x 10K Ohm
// 1 x 20k Ohm
// 1 x 200k Ohm
// 1 x 3.3m Ohm
// 12 x Jumper Wires 3in M/M
// 13 x Jumper Wires 6in M/M
// 20 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include "EEPROM.h"
// Wire
#include <Wire.h>
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>
// RHT Humidity and Temperature Sensor
#include <SparkFun_RHT03.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 144x168
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
// The currently-available SHARP Memory Display (144x168 pixels)
// requires > 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno
// or other <4K "classic" devices!
#define BLACK 0
#define WHITE 1
// 1/2 of lesser of display width or height
int minorHalfSize; 

// SparkFun CCS811 - eCO2 & tVOC
// Default I2C Address
#define CCS811_ADDR 0x5B 
CCS811 myCCS811(CCS811_ADDR);
float CCS811CO2 = 0;
float CCS811TVOC = 0;

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
BME280 myBME280;
float BMEtempC = 0;
float BMEhumid = 0;
float BMEaltitudeM = 0;
float BMEpressure = 0;

// Date and Time
// PCF8523 Precision RTC 
RTC_PCF8523 rtc;
String dateRTC = "";
String timeRTC = "";

// microSD Card
const int chipSelect = 33;
String zzzzzz = "";

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

// Rotary Switch - 10 Position
// Number 1 => 10
int iRotNum = A0;
// iRotVal - Value 
int iRotVal = 0;
// Number
int z = 0;
int x = 0;

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A4;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// EMF Meter (Single Axis)
int iEMF = A5;
// Raise this number to increase data smoothing
#define NUMREADINGS 15
// Raise this number to decrease sensitivity (up to 1023 max)
int senseLimit = 15;
// EMF Value
int valEMF = 0;
// Readings from the analog input
int readings[ NUMREADINGS ];
// Index of the current reading
int indexEMF = 0;
// Running total
int totalEMF = 0;
// Final average of the probe reading
int averageEMF = 0;
int iEMFDis = 0;
int iEMFRect = 0;

// RHT Humidity and Temperature Sensor
// RHT03 data pin Digital 15
const int RHT03_DATA_PIN = 15;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;
float latestTempF;

// PIR Motion
// Motion detector
const int iMotion = 17;
// Proximity
int proximity = LOW;
String Det = "";

// Software Version Information
String sver = "15-12";
// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

  // SparkFun CCS811 - eCO2 & tVOC
  isCCS811();

  // Gas Sensors MQ
  isGasSensor();

  // EMF Meter (Single Axis)
  isEMF();

  // RHT03 Humidity and Temperature Sensor
  isRHT03();

  // isPIR Motion
  isPIR();

  // Rotary Switch
  isRot();

  // Slide Switch
  // Read the state of the iSS1 value
  iSS1State = digitalRead(iSS1);
  
  // If it is the Slide Switch State is HIGH
  if (iSS1State == HIGH) {

    // iLEDGreen
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    digitalWrite(iLEDGreen,  LOW );
  
  }

  delay( 1000 );
  
}

getBME280.ino

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
// isBME280 - Temperature, Humidity, Altitude and Barometric Pressure
void isBME280(){

  // Temperature Celsius
  BMEtempC = myBME280.readTempC();
  // Humidity
  BMEhumid = myBME280.readFloatHumidity();
  // Altitude Meters
  BMEaltitudeM = (myBME280.readFloatAltitudeMeters(), 2);
  // Barometric Pressure
  BMEpressure = myBME280.readFloatPressure();
  
}

getCCS811.ino

// CCS811 - eCO2 & tVOC
// isCCS811 - eCO2 & tVOC
void isCCS811(){

  // This sends the temperature & humidity data to the CCS811
  myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);

  // Calling this function updates the global tVOC and eCO2 variables
  myCCS811.readAlgorithmResults();

  // eCO2 Concentration
  CCS811CO2 = myCCS811.getCO2();
  
  // tVOC Concentration
  CCS811TVOC = myCCS811.getTVOC();
  
}

getDisplay.ino

// Display
// SHARP Memory Display - UID
void isDisplayUID() {

    // Text Display 
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Don Luc Electronics
    display.setCursor(0,10);
    display.println( "Don Luc" );
    display.setTextSize(2);
    display.setCursor(0,40);
    display.println( "Electronics" );
    // Version
    display.setTextSize(3);
    display.setCursor(0,70);
    display.println( "Version" );
    display.setTextSize(2);
    display.setCursor(0,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display Date
void isDisplayDate() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Date
    display.setCursor(0,5);
    display.println( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
void isDisplayBME280() {

     // Text Display BME280
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,10);
    display.println( "Temperature" );
    display.setCursor(0,30);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,50);
    display.println( "Humidity" );
    display.setCursor(0,70);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,90);
    display.println( "Altitude M" );
    display.setCursor(0,110);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,130);    
    display.println( "Barometric" );
    display.setCursor(0,150);
    display.print( BMEpressure );
    display.println( "Pa" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display CCS811 - eCO2 & tVOC
void isDisplayCCS811() {

    // Text Display CCS811
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // eCO2 Concentration
    display.setCursor(0,10);
    display.println( "eCO2" );
    display.setCursor(0,30);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,60);
    display.println( "tVOC" );
    display.setCursor(0,80);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,30);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,50);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,70);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,90);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,110);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    display.setCursor(0,130);
    display.println( "BAC MQ3" );
    display.setCursor(0,150);
    display.print( iMQ3ppm );
    display.println( "%" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// EMF Meter (Single Axis)
void isDisplayEMF() {

    // Text Display EMF Meter
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // EMF Meter
    display.setCursor(0,10);
    display.println( "EMF Meter" );
    display.setCursor(0,30);
    display.print( "EMF: " );
    display.println( averageEMF );
    display.setCursor(0,50);
    display.println( iEMFDis );
    display.setCursor(0,70);
    display.setTextSize(1);
    display.println( "0  1 2 3 4 5 6 7 8 9  10" );
    display.setCursor(0,90);
    display.drawRect(0, 90, iEMFRect , display.height(), BLACK);
    display.fillRect(0, 90, iEMFRect , display.height(), BLACK);
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display PIR Motion
void isDisplayPIR() {

    // Text Display PIR
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // PIR Motion
    display.setCursor(0,10);
    display.println( "PIR Motion" );
    display.setCursor(0,30);
    display.println( Det );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display RHT
void isDisplayRHT() {

    // Text Display RHT
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature
    display.setCursor(0,10);
    display.println( "Temp C" );
    display.setCursor(0,30);
    display.print( latestTempC );
    display.println( "C" );
    // Temp F
    display.setCursor(0,60);
    display.println( "Temp F" );
    display.setCursor(0,80);
    display.print( latestTempF );
    display.println( "F" );
    // Humidity
    display.setCursor(0,110);
    display.println( "Humidity" );
    display.setCursor(0,130);
    display.print( latestHumidity );
    display.println( " %" );    
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display Z
void isDisplayZ() {

    // Text Display Z
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Z
    display.setCursor(0,10);
    display.print( "Z: " );
    display.println( z );
    // Refresh
    display.refresh();
    delay( 100 );

}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getEMF.ino

// EMF Meter (Single Axis)
// Setup EMF Meter
void isSetupEMF() {

  // EMF Meter (Single Axis)
  pinMode( iEMF, OUTPUT );
  for (int i = 0; i < NUMREADINGS; i++){
    readings[ i ] = 0;     // Initialize all the readings to 0
  }
  
}
// EMF Meter
void isEMF() {

  // Probe EMF Meter
  // Take a reading from the probe
  valEMF = analogRead( iEMF );

  // If the reading isn't zero, proceed
  if( valEMF >= 1 ){

    // Turn any reading higher than the senseLimit value into the senseLimit value
    valEMF = constrain( valEMF, 1, senseLimit );
    // Remap the constrained value within a 1 to 1023 range
    valEMF = map( valEMF, 1, senseLimit, 1, 1023 );
    
    // Subtract the last reading
    totalEMF -= readings[ indexEMF ];
    // Read from the sensor
    readings[ indexEMF ] = valEMF;
    // Add the reading to the total
    totalEMF += readings[ indexEMF ];
    // Advance to the next index
    indexEMF = ( indexEMF + 1 );
    
    // If we're at the end of the array...
    if ( indexEMF >= NUMREADINGS ) {

      // Wrap around to the beginning
      indexEMF = 0;
      
    }  

    // Calculate the average
    averageEMF = totalEMF / NUMREADINGS;

    iEMFDis = averageEMF;
    iEMFRect = map( averageEMF, 1, 1023, 1, 144 );

  }
  else
  {

    averageEMF = 0;
    
  }
  
}

getGPS.ino

// GPS Receiver
// Setup GPS
void setupGPS() {

  // Setup GPS
  tGPS.begin(  9600 , SERIAL_8N1, gpsRXPIN, gpsTXPIN );
  
}
// isGPS
void isGPS(){

  // Receives NEMA data from GPS receiver
  // This sketch displays information every time a new sentence is correctly encoded.
  while ( tGPS.available() > 0)
    if (gps.encode( tGPS.read() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

}
// GPS Vector Pointer Target
void displayInfo(){

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";
    
  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRHT.ino

// RHT03 Humidity and Temperature Sensor
// setup RTH03 Humidity and Temperature Sensor
void setupRTH03() {

  // RHT03 Humidity and Temperature Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT03 Humidity and Temperature Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();
  latestTempF = rht.tempF();
  
}

getRTC.ino

// Date & Time
// PCF8523 Precision RTC 
void setupRTC() {

  // Date & Time
  // pcf8523 Precision RTC   
  if (! rtc.begin()) {
    while (1);
  }  
  
  if (! rtc.initialized()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2018, 9, 29, 12, 17, 0));
  }
  
}
// Date and Time RTC
void isRTC () {

  // Date and Time
  dateRTC = "";
  timeRTC = "";
  DateTime now = rtc.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;
  
  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

  // Range Value
  switch ( iRotVal ) {
    case 0:

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

      // Display Date
      isDisplayDate();
      
      break;
    case 2:

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // RHT03 Humidity and Temperature Sensor
      isDisplayRHT();
      
      break;
    case 4:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 5:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;       
    case 6:

      // EMF Meter (Single Axis)
      isDisplayEMF();
      
      break; 
    case 7:
         
      // Display PIR Motion
      isDisplayPIR();
      
      break; 
    case 8:

      // Display UID
      isDisplayUID();
      
      break;
    case 9:

      // Z
      isDisplayZ();
      
      break;
  }

}

getSD.ino

// microSD Card
// microSD Setup
void setupSD() {

    // microSD Card
    pinMode( chipSelect , OUTPUT );
    if(!SD.begin( chipSelect )){
        ;  
        return;
    }
    
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  
}
// microSD Card
void isSD() {

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|Latest Temp C|Latest Temp F|Latest Humidity|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7|Alcohol Gas Sensor MQ-3|EMF Meter (Single Axis)|PIR Motion
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + latestTempC + "|" + latestTempF + "|" + latestHumidity + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + iMQ9ppm + "|" + iMQ3ppm + "|" + averageEMF + "|" + Det + "|\r";

  char msg[zzzzzz.length() + 1];

  zzzzzz.toCharArray(msg, zzzzzz.length() + 1);

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    dirname;
    
    File root = fs.open(dirname);
    
    if(!root){
        return;
    }
    
    if(!root.isDirectory()){
        return;
    }

    File file = root.openNextFile();
    
    while(file){
        if(file.isDirectory()){
            file.name();
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            file.name();
            file.size();
        }
        file = root.openNextFile();
    }
    
}
// Write File
void writeFile(fs::FS &fs, const char * path, const char * message){
    
    path;
    
    File file = fs.open(path, FILE_WRITE);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}
// Append File
void appendFile(fs::FS &fs, const char * path, const char * message){
    
    path;
    
    File file = fs.open(path, FILE_APPEND);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}

setup.ino

// Setup
void setup() {

  // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);
  
  // EEPROM Unique ID
  isUID();
  
  // GPS Receiver
  // Setup GPS
  setupGPS();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  // EMF Meter (Single Axis) - Setup
  isSetupEMF();

  // RHT03 Humidity and Temperature Sensor
  // setup RTH03 Humidity and Temperature Sensor
  setupRTH03();

  // PIR Motion
  // Setup PIR
  setupPIR();

  delay( 5000 );

}

Technology Experience

  • Single-Board Microcontrollers (Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #11: ESP32 Feather – PIR Motion Sensor – Mk11

PIR Motion Sensor

——

——

PIR Motion Sensor

——

PIR Motion Sensor

——

PIR Motion Sensor

——

PIR Motion Sensor

——

PIR Motion Sensor

Passive infrared (PIR) sensors are motion-detecting devices used in security systems across the world, even though you may not see them, they probably see you.

This is a simple to use motion sensor. Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room. If anything moves after that period, the ‘alarm’ pin will go low.

Pololu Adjustable Boost Regulator 2.5-9.5V

This powerful, adjustable boost regulator can generate an output voltage as high as 9.5 V from an input voltage as low as 1.5 V, all in a compact, 0.42″ x 0.88″ x 0.23″ package. A trimmer potentiometer lets you set the boost regulator’s output voltage to a value between 2.5 and 9.5 V.

DL1911Mk02

1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x CR1220 12mm Lithium Battery
1 x 8Gb Micro SD Card
1 x RHT03 Humidity and Temperature Sensor
1 x GPS Receiver GP-20U
1 x LED Green
1 x Rocker Switches
1 x 100 Ohm
1 x 10K Ohm
1 x 3.3M Ohm
1 x Antenna
1 x Lithium Ion Battery – 2.5Ah
1 x PIR Motion Sensor
1 x Pololu Adjustable Boost Regulator 2.5-9.5V
1 x LED Green 1
14 x Jumper Wires 3″ M/M
10 x Jumper Wires 6″ M/M
2 x Wire
1 x Full-Size Breadboard
2 x Breadboard
1 x SparkFun Cerberus USB Cable

Adafruit HUZZAH32 ESP32 Feather

LG0 – Digital 21
RO1 – Digital 16
RHT – Digital 17
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
GPS – Digital 4
EMF – Analog A0
BAT – Analog A13
MOT – Digital 32
LG1 – Digital 14
GND – GND
VIN – +3.3V

DL1911Mk02.ino

// ***** Don Luc Electronics *****
// Software Version Information
// Project #11: HUZZAH32 ESP32 Feather - PIR Motion - Mk11
// 11-02
// DL1911Mk02p.ino 11-11
// Adafruit HUZZAH32 ESP32 Feather Board
// SHARP Display
// LED Green
// Adalogger FeatherWing - RTC + SD
// EEPROM
// RHT03 Humidity and Temperature Sensor
// Rocker Switches
// GPS Receiver
// EMF Meter (Single Axis)
// Lithium Ion Battery - 2.5Ah
// PIR Motion
// Pololu Adjustable Boost Regulator 2.5-9.5V
// LED Green 1

// include Library Code
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// Date and Time
#include "RTClib.h"
// EEPROM library to read EEPROM with unique ID for unit
#include "EEPROM.h"
// RHT Humidity and Temperature Sensor
#include <SparkFun_RHT03.h>
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
#include <HardwareSerial.h>

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here, e.g. 144x168!
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
// The currently-available SHARP Memory Display (144x168 pixels)
// requires > 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno
// or other <4K "classic" devices!
#define BLACK 0
#define WHITE 1
int minorHalfSize; // 1/2 of lesser of display width or height

// LED Green
int iLEDGreen =  21;                 // LED Green

// PCF8523 Precision RTC 
RTC_PCF8523 rtc;
String dateRTC = "";
String timeRTC = "";

// RHT Humidity and Temperature Sensor
const int RHT03_DATA_PIN = 17;          // RHT03 data pin Digital 17
RHT03 rht;                              // This creates a RTH03 object, which we'll use to interact with the sensor
float latestHumidity;
float latestTempC;
float latestTempF;

// SD Card
const int chipSelect = 33;              // SD Card
String zzzzzz = "";

// Rocker Switches
int iRow1 = 16;                         // Rocker Switches Digital 16
int iRow1State = 0;                     // Variable for reading the pushbutton status

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 4
#define gpsTXPIN 36                     // This one is unused and doesnt have a conection
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int Status = 0;

// EMF Meter (Single Axis)
#define NUMREADINGS 15                    // Raise this number to increase data smoothing
int senseLimit = 15;                      // Raise this number to decrease sensitivity (up to 1023 max)
int val = 0;                              // Val
int iEMF = A0;                            // EMF Meter
int readings[ NUMREADINGS ];              // Readings from the analog input
int ind = 0;                              // Index of the current reading
int total = 0;                            // Running total
int average = 0;                          // Final average of the probe reading
int iEMFDis = 0;
int iEMFRect = 0;

// LiPo Battery
const int bat = A13;                      // LiPo Battery
uint16_t vbat = 0;
int iBat = 0;

// PIR Motion
const int iMotion = 32;                   // Motion detector
const int iLEDGreen1 = 14;                // LED Green 1
int proximity = LOW;                      // Proximity
String Det = "";

// The current address in the EEPROM (i.e. which byte
// we're going to  read to next)
#define EEPROM_SIZE 64
String sver = "11-2.p";
// Unit ID information
String uid = "";

void loop() {

  // Receives NEMA data from GPS receiver
  // This sketch displays information every time a new sentence is correctly encoded.
  while ( tGPS.available() > 0)
    if (gps.encode( tGPS.read() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

  // Date and Time 
  isRTC();
  
  // RHT03 Humidity and Temperature Sensor
  isRHT03();
  
  // SHARP Memory Display On
  isDisplayOn();
  
  // Rocker Switched
  // Read the state of the iRow1 value
  iRow1State = digitalRead(iRow1);

  // EMF Meter (Single Axis)
  isEMF();

  // LiPo Battery
  isBattery();

  // isPIR Motion
  isPIR();

  // Check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (iRow1State == HIGH) {

    // iLEDGreen
    digitalWrite(iLEDGreen,  HIGH );
    // SD Card
    isSD();

  } else {

    // iLEDGreen
    digitalWrite(iLEDGreen,  LOW );
  
  }
   
  // Delay 
  delay( 1000 );

}

getBattery.ino

// LiPo Battery
void isBattery() {

  // Battery
  vbat = analogRead(bat);
  vbat = vbat / 2;

  iBat = map( vbat, 1, 1064, 1, 100);
  
}

getDisplay.ino

// SHARP Memory Display On
void isDisplayOn() {

    // Clear Display
    display.clearDisplay();
    // Text display date, time, LED on, Etc...
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Date
    display.setCursor(0,1);
    display.println( dateRTC );
    // Time
    display.setCursor(0,17);
    display.println( timeRTC );
    // Longitude  
    display.setCursor(0,35);
    display.print("Lon: ");
    display.println( TargetLon );
    // Latitude
    display.setCursor(0,55);
    display.print("Lat: ");
    display.println( TargetLat );
    // Humidity
    display.setCursor(0,74);
    display.print("Hum: ");
    display.print( latestHumidity );
    display.println("%");
    // Temp C
    display.setCursor(0,94);
    display.print("Cel: ");
    display.print( latestTempC );
    display.println("*C");
    // EMF Meter
    display.setCursor(0,114);
    display.print("EMF: ");
    display.println( iEMFDis );
    // Battery
    display.setCursor(0,134);
    display.print("Bat: ");
    display.print( iBat );
    display.println( "%" );
    // PIR Motion
    display.println( Det );
    display.setCursor(0,154);
    // Refresh
    display.refresh(); 

}
// SHARP Memory Display - UID
void isDisplayUID() {

    // Clear Display
    display.clearDisplay();
    // text display EEPROM
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // EEPROM with Unique ID
    display.setCursor(0,20);
    display.print( "UID: " );
    display.println( uid );
    // Version
    display.setCursor(0,45);
    display.print( "VER: ");
    display.println( sver  );
    // Refresh
    display.refresh();
    delay( 100 );
    
}

getEEPROM.ino

// EEPROM
void GetUID()
{
  
  // Get unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getEMF.ino

// EMF Meter (Single Axis)
// setupEMF
void setupEMF() {

  // EMF Meter (Single Axis)
  pinMode( iEMF, OUTPUT ); // EMF Meter
  for (int i = 0; i < NUMREADINGS; i++){
    readings[ i ] = 0;     // Initialize all the readings to 0
  }
  
}
// isEMF
void isEMF(){

  // Probe
  val = analogRead( iEMF );                    // Take a reading from the probe
  
  if( val >= 1 ){                              // If the reading isn't zero, proceed

    val = constrain( val, 1, senseLimit );     // Turn any reading higher than the senseLimit value into the senseLimit value
    val = map( val, 1, senseLimit, 1, 1023 );  // Remap the constrained value within a 1 to 1023 range

    total -= readings[ ind ];                  // Subtract the last reading
    readings[ ind ] = val;                     // Read from the sensor
    total += readings[ ind ];                  // Add the reading to the total
    ind = ( ind + 1 );                         // Advance to the next index

    if ( ind >= NUMREADINGS ) {                // If we're at the end of the array...
      ind = 0;                                 // ...wrap around to the beginning
    }  

    average = total / NUMREADINGS;             // Calculate the average

    
   // average = val;
  }
  else
  {
      
    iEMFRect = 0;
    val = 0;
    average = 0;
    
  }

  iEMFDis = average;
  iEMFRect = map( average, 1, 1023, 1, 144 );
    
}

getGPS.ino

// GPS Receiver
void setupGPS() {

  // Setup GPS
  tGPS.begin(  9600 , SERIAL_8N1, gpsRXPIN, gpsTXPIN );
  
}
// GPS Vector Pointer Target
void displayInfo()
{

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    Status = 2;
    
  }
  else
  {

    Status = 0;
    
  }

}

getPIR.ino

// PIR Motion
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  pinMode(iLEDGreen1, OUTPUT);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    // LED Green 1 - HIGH
    digitalWrite(iLEDGreen1, HIGH);
    Det = "Motion!";
    
  }
  else
  {

    // PIR Motion Sensor's HIGH
    // LED Green 1 - LOW
    digitalWrite(iLEDGreen1, LOW);
    Det = "****";
    
  }
  
}

getRHT.ino

// RHT03 Humidity and Temperature Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();
  latestTempF = rht.tempF();
  
}

getRTCpcf8523.ino

// PCF8523 Precision RTC 
void setupRTC() {

  // pcf8523 Precision RTC   
  if (! rtc.begin()) {
    while (1);
  }  
  if (! rtc.initialized()) {
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2018, 9, 29, 12, 17, 0));
  }
  
}
// Date and Time RTC
void isRTC () {

  // Date and Time
  DateTime now = rtc.now();
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;
  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;
  
}

getSD.ino

// SD Card
void setupSD() {

  // SD Card
    pinMode( chipSelect , OUTPUT );
    if(!SD.begin( chipSelect )){
        ;  
        return;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  
}
// SD Card
void isSD() {

  zzzzzz = "";

  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + Status + "|" + TargetLon + "|" + TargetLat + "|" + latestHumidity + "|" + latestTempC + "|" + latestTempF + "|" + average + "|" + iBat + "|" + Det + "|\r";

  char msg[zzzzzz.length() + 1];

  zzzzzz.toCharArray(msg, zzzzzz.length() + 1);

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    dirname;
    File root = fs.open(dirname);
    if(!root){
        return;
    }
    if(!root.isDirectory()){
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            file.name();
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            file.name();
            file.size();
        }
        file = root.openNextFile();
    }
}
// Write File
void writeFile(fs::FS &fs, const char * path, const char * message){
    path;
    File file = fs.open(path, FILE_WRITE);
    if(!file){
        return;
    }
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    file.close();
}
// Append File
void appendFile(fs::FS &fs, const char * path, const char * message){
    //Serial.printf("Appending to file: %s\n", path);
    path;
    File file = fs.open(path, FILE_APPEND);
    if(!file){
        return;
    }
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    file.close();
}

setup.ino

// Setup
void setup() {

  // EEPROM with Unique ID
  EEPROM.begin(EEPROM_SIZE);
   
  // Get Unit ID
  GetUID();

  // GPS Receiver
  // Setup GPS
  setupGPS();
  
  // SHARP Display start & clear the display
  display.begin();
  display.clearDisplay();

  isDisplayUID();

  delay( 5000 );
  
  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);

  // PCF8523 Precision RTC 
  setupRTC();

  // Date and Time RTC
  isRTC();

  // RHT03 Humidity and Temperature Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);

  // SD Card
  setupSD();

  // Rocker Switches
  pinMode(iRow1, INPUT);

  // EMF Meter (Single Axis)
  setupEMF();

  // PIR Motion
  setupPIR();

}

Follow Us

Web: https://www.donluc.com/
Web: http://neosteamlabs.com/
Web: http://www.jlpconsultants.com/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Facebook: https://www.facebook.com/neosteam.labs.9/
Instagram: https://www.instagram.com/neosteamlabs/
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Twitter: https://twitter.com/labs_steam
Etsy: https://www.etsy.com/shop/NeoSteamLabs

Categories
Archives