A_Wild_Noodle
Published © CC BY

Smart Campus Remote Sensing Station

ESP32 remote sensing station equipped with an array of sensors capable of reporting and graphing results to ThingSpeak.

BeginnerFull instructions provided8 hours135
Smart Campus Remote Sensing Station

Things used in this project

Hardware components

Hackster EEDU Kit - Getting started with Environmental Sensing
DFRobot Hackster EEDU Kit - Getting started with Environmental Sensing
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Machine Screw, M4
Machine Screw, M4
×2
Machine Screw, M3
Machine Screw, M3
×4
Machine Screw, M2
Machine Screw, M2
×2
Outdoor Enclosure
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Hex Key

Story

Read more

Custom parts and enclosures

Mounting Plate

Bolt in plate

Schematics

Remote Sensing Station System Schematic

This is the system level schematic. It functions as a high level system interconnect to show you at a cable level how to plug your peripheral sensor suites and breakout boards.

Code

Remote Sensing Station Code

Arduino
To use this Arduino sketch you will first need to create a free https://thingspeak.com/ account. Once you have created an account you will need to make a channel with 8 data streams for the various sensors onboard the Remote Sensing Station (RSS). Before using flashing the code to your ESP32 based microcontroller you will need to create a file called "secrets.h" in the same folder this Arduino sketch is in. Inside that folder you will define two variables: SECRET_SSID and SECRET_PASS, set these equal to your network SSID and Password. Keep in mind that you will have to connect to a 2.4Ghz network.
#include <Wire.h>
#include <DFRobot_SGP40.h>
#include <DFRobot_EnvironmentalSensor.h>
#include <WiFi.h>
#include "secrets.h" //this is a local header file created which contains SSID, Pass, API Keys etc. You will need to create this file "secrets.h" and place your SSID and define the variables SECRET_SSID and SECRET_PASS Password there.
#include <ThingSpeak.h>



#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
#include <SoftwareSerial.h>
#endif


/*NOTES:
SEN0500 Pinout: TX::D3, RX::D2
*/

#define MODESWITCH        /*UART:*/1 /*I2C: 0*/

#if MODESWITCH
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
  SoftwareSerial mySerial(/*rx =*/4, /*tx =*/5);
  DFRobot_EnvironmentalSensor environment(/*addr =*/SEN050X_DEFAULT_DEVICE_ADDRESS, /*s =*/&mySerial);
#else
  DFRobot_EnvironmentalSensor environment(/*addr =*/SEN050X_DEFAULT_DEVICE_ADDRESS, /*s =*/&Serial1);
#endif
#else
DFRobot_EnvironmentalSensor environment(/*addr = */SEN050X_DEFAULT_DEVICE_ADDRESS, /*pWire = */&Wire);
#endif



char ssid[] = SECRET_SSID;   // your network SSID (name) 
char pass[] = SECRET_PASS;   // your network password
WiFiClient  client;
DFRobot_SGP40 mySgp40;
unsigned long myChannelNumber = SECRET_CH_ID;
const char* myWriteAPIKey = SECRET_WRITE_APIKEY;


void setup() {
  WiFi.mode(WIFI_STA);   
  ThingSpeak.begin(client);  // Initialize ThingSpeak
  Serial.println("----------------------------------------------");
//LED test
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay(2000); 
digitalWrite(2, LOW);

//START THE EXTREMLEY TOUCHY SEN0500 BREAKOUT BOARD
#if MODESWITCH
  //Init MCU communication serial port
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
  mySerial.begin(9600);
#elif defined(ESP32)
  Serial1.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
  Serial1.begin(9600);
#endif
#endif
  Serial.begin(115200);
  while(environment.begin() != 0){
    Serial.println(" SEN0500 initialize failed!!");
    delay(1000);
  }
  Serial.println(" SEN0500  initialize success!!");

//CONNECT TO WIFI
  Serial.println("Starting WiFi...");
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to network...");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("Connected to network!!!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

//START AND CAL SGP40
  Serial.println("SGP40 is starting, the reading can be taken after 10 seconds...");
  //The preheating time of the sensor is 10s.
  //duration:Initialize the wait time. Unit: millisecond. Suggestion: duration > = 10000 ms
  while(mySgp40.begin(/*duration = */10000) !=true){
    Serial.println("failed to init chip, please check if the chip connection is fine");
    delay(1000);
  }
  Serial.println("sgp40 initialized successfully!");
  Serial.println("----------------------------------------------");
}




void loop() {
//CHECK WIFI STATUS
  if((WiFi.status() != WL_CONNECTED)){
    Serial.println("!!!!!!!!!!!!!!! NETWORK DISCONNECTED !!!!!!!!!!!!!!!");
    digitalWrite(2, LOW);
    WiFi.begin(ssid, pass);
  }
  if((WiFi.status() == WL_CONNECTED)){
    digitalWrite(2, HIGH);
  }



  ThingSpeak.setField(1, environment.getTemperature(TEMP_F));
  ThingSpeak.setField(2, environment.getHumidity());
  ThingSpeak.setField(3, environment.getUltravioletIntensity());
  ThingSpeak.setField(4, environment.getLuminousIntensity());
  ThingSpeak.setField(5, environment.getAtmospherePressure(HPA));
  ThingSpeak.setField(6, environment.getElevation());
  ThingSpeak.setField(7, analogRead(A4));
  ThingSpeak.setField(8, mySgp40.getVoclndex());

  Serial.println("Sensor Scan Successful");

  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }

/*
//PRINT ALL VOC INDEX SGP40 
  Serial.println();
  Serial.print("VOC_Index:");
  Serial.println(mySgp40.getVoclndex());



//PRINT MOISTURE SENSOR READING
  Serial.print("Moisture:");
  Serial.println(analogRead(A4));



//PRINT RESULTS OF ALL SEN0500 SENSORS
  Serial.print("Temp: ");
  Serial.print(environment.getTemperature(TEMP_C));
  Serial.println("C");
  Serial.print("Temp: ");
  Serial.print(environment.getTemperature(TEMP_F));
  Serial.println("F");
  Serial.print("Humidity: ");
  Serial.print(environment.getHumidity());
  Serial.println(" %");
  Serial.print("Ultraviolet intensity: ");
  Serial.print(environment.getUltravioletIntensity());
  Serial.println(" mw/cm2");
  Serial.print("LuminousIntensity: ");
  Serial.print(environment.getLuminousIntensity());
  Serial.println(" lx");
  Serial.print("Atmospheric pressure: ");
  Serial.print(environment.getAtmospherePressure(HPA));
  Serial.println(" hpa");
  Serial.print("Altitude: ");
  Serial.print(environment.getElevation());
  Serial.println(" m");
  Serial.println();
*/



  delay(100000);
}



/*
String moistStatus(){

  int waterlevel = analogRead(A4);
  Serial.print(waterlevel);
  String moist = "";
  if (waterlevel >= 3000){
    moist = "Dry";
  }
  else if (waterlevel < 3000 && waterlevel >= 2000){
    moist = "Damp";
  }
  else if (waterlevel < 2000){
    moist = "Saturated";
  }
  return moist;
}



String vocStatus(){

  int index = mySgp40.getVoclndex();
  Serial.print(index);
  String safeLevel = "";

  if (index <= 100){
    safeLevel = "Very Safe";
  }
  else if (index > 100 && index <= 200){
    safeLevel = "Safe";
  }
  else if (index > 200 && index <= 400){
    safeLevel = "Ventilate";
  }
  else if (index > 400 && index <= 500){
    safeLevel = "Ventilate Immediately";
  }
  else{
    safeLevel = "Error: No Index";
  }
  
  delay(1000);

  return safeLevel;
}
*/

Secrets File For Your SSID, Password, Read/Write API Keys

C Header File
replace generic placeholders in this file with your network information and ThingSpeak channel ID and API keys.
//This contains secret info such as network SSID and password as well as API keys 

/*
For storing multiple networks if you want:
ssid:          
pass: 
ssid:         
pass: 
*/


#define SECRET_SSID "SSID" //Your 2.4Ghz Network SSID MAKE STRING
#define SECRET_PASS "PASSWORD" //Your 2.4Ghz Network Pass MAKE STRING
#define SECRET_CH_ID 0000000 //From ThingSpeak MAKE INTEGER
#define SECRET_WRITE_APIKEY "WRITE_API_KEY" //From ThingSpeak MAKE STRING
#define SECRET_READ_APIKEY "READ_API_KEY" //From ThingSpeak MAKE STRING

Credits

A_Wild_Noodle

A_Wild_Noodle

1 project • 0 followers
Hobbyist, engineer, and avid maker.

Comments