Brittany Bull
Published © MIT

Serial Humidity Monitor

The easiest humidity monitor you will ever make. Be ready to go in less than 5 minutes!

EasyFull instructions provided5 minutes170
Serial Humidity Monitor

Things used in this project

Hardware components

XinaBox CC01
×1
IP01
XinaBox IP01
×1
SW01
XinaBox SW01
×1
XC10
XinaBox XC10
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

HumiditySerialMonitor.ino

Arduino
The code for showing Humidity data on the serial monitor while using Arduino IDE and xCHIPS from XinaBox
#include <xCore.h>  //include xCore library
#include <xSW01.h>  //include sensor library


// Create a variable for the storage of data received from SW01  
  float Relative_Humidity;
  unsigned long previousMilli_1 = 0;  // timing variable for serial monitor
  const long interval_1= 5000;        // time delay for serial monitor
  bool flag;

  
const int DELAY_TIME = 1000;

xSW01 SW01;

void setup() {
  // Start the Serial Monitor
  Serial.begin(115200);

  // START I2C COMMUNICATION
  Wire.begin();
  
  // Start the SW01
  SW01.begin();

  //Intialising variables
  Relative_Humidity = 0;
  
  Serial.println("     Humidity Project        ");
  Serial.println("================================");
  
  //Delay for sensor to normalise
  delay(3000);
}

void loop() {
  
  // Read and calculate data from SW01 sensor
  SW01.poll();
  
  // Request the temperature measurement from SW01 and store in
  // the temperature variable   
  Relative_Humidity = SW01.getHumidity(); // Relative Humidity in Percentage format
  display_humidity();
  
}

void display_humidity() {

  // timing delay according to interval_1 variable
  // do not use the delay() function as it will pause all operations
  unsigned long currentMilli_1 = millis();
  if(currentMilli_1 - previousMilli_1 >= interval_1){
    previousMilli_1 = currentMilli_1;
    if(flag == false){
      flag = true;
    }
    else{
      flag = false;
    }
   
    
 // Show data over the Serial Monitor   
  Serial.print("Relative_Humidity: ");
  Serial.print(Relative_Humidity);
  Serial.println(" %");
  }
}

Credits

Brittany Bull

Brittany Bull

12 projects • 5 followers
A student exploring the world of coding and IoT from a beginners' perspective

Comments