Diana Khalipina
Published © GPL3+

Control of room conditions for healthy work

Provide continuous info about room temperature, humidity, CO2 and luminoscity levels and turn on leds at the end of the work to relax eyes

IntermediateFull instructions provided1 hour3,703

Things used in this project

Story

Read more

Schematics

Schematics for arduino

Code

Code for arduino

Arduino
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_SGP30.h>
#include <rgb_lcd.h>
#include "Adafruit_NeoPixel.h"

#define LED_COUNT_NP2         30

DHT dht(A0, DHT11);
Adafruit_SGP30 sgp30;
rgb_lcd lcdRgb;
Adafruit_NeoPixel Neopixel_2(LED_COUNT_NP2, 2, NEO_GRB + NEO_KHZ800);

void serial_setupConnection(int baudrate) {
  Serial.begin(baudrate);
  while (!Serial) {
    Serial.println("En attente de l'ouverture du port série...");
    delay(1000);
  }
  Serial.println("Port série activé. Baudrate: " + String(baudrate));
}

uint16_t sgp30_readCO2() {
  if (!sgp30.IAQmeasure()) {
    Serial.println("Measurement failed");
    return 0;
  }
  else return sgp30.eCO2;
}

void showAllNeopixel(Adafruit_NeoPixel neoPx, uint8_t ledCount, uint8_t r, uint8_t g, uint8_t b) {
  for (int i=0; i<ledCount; i++) {
    neoPx.setPixelColor(i, neoPx.Color(r, g, b));
  }
  neoPx.show();
  delay(5);
}

void rainbow(Adafruit_NeoPixel neoPx, uint8_t ledCount) {
  uint8_t R = 255;
  uint8_t G = 50;
  uint8_t B = 50;
  for (G; G<254; G=G+5) showAllNeopixel(neoPx, ledCount, R, G, B);
  for (R; R>49; R=R-5) showAllNeopixel(neoPx, ledCount, R, G, B);
  for (B; B<254; B=B+5) showAllNeopixel(neoPx, ledCount, R, G, B);
  for (G; G>49; G=G-5) showAllNeopixel(neoPx, ledCount, R, G, B);
  for (R; R<254; R=R+5) showAllNeopixel(neoPx, ledCount, R, G, B);
  for (B; B>49; B=B-5) showAllNeopixel(neoPx, ledCount, R, G, B);
}


void setup() {
  serial_setupConnection(9600);
  dht.begin();
  while (!sgp30.begin()) {
    Serial.println("En attente du capteur SGP30...");
    delay(1000);
  }
  pinMode(A1, INPUT);
  lcdRgb.begin(16, 2);
  pinMode(3, INPUT);
  Neopixel_2.begin();
}

void loop() {
  Serial.print("@Graph:");
  Serial.print("Temperature:");
  Serial.print(dht.readTemperature());
  Serial.print("|");
  Serial.print("Humidity:");
  Serial.print(dht.readHumidity());
  Serial.print("|");
  Serial.print("CO2:");
  Serial.print(sgp30_readCO2());
  Serial.print("|");
  Serial.print("Light:");
  Serial.print(analogRead(A1));
  Serial.print("|");
  Serial.print("\n");
  delay(50);
  lcdRgb.setCursor(0, 0);
  lcdRgb.print(String(dht.readTemperature()));
  lcdRgb.setCursor(0, 1);
  lcdRgb.print(String(dht.readHumidity()));
  if (dht.readTemperature() >= 22.01) {
    lcdRgb.setRGB(255, 0, 0);
  } else if (dht.readHumidity() <= 40.01) {
    lcdRgb.setRGB(255, 0, 0);
  } else if (dht.readTemperature() <= 18.01) {
    lcdRgb.setRGB(255, 0, 0);
  }
  lcdRgb.setRGB(255, 255, 255);
  delay(2000);
  lcdRgb.setCursor(0, 0);
  lcdRgb.print(String(sgp30_readCO2()));
  lcdRgb.setCursor(0, 1);
  lcdRgb.print(String(analogRead(A1)));
  if (sgp30_readCO2() >= 100000.01) {
    lcdRgb.setRGB(255, 0, 0);
  } else if (analogRead(A1) <= 50.01) {
    lcdRgb.setRGB(255, 0, 0);
  }
  if (digitalRead(3) == true) {
    rainbow(Neopixel_2, LED_COUNT_NP2);
  }
  delay(2000);
  lcdRgb.setRGB(255, 255, 255);
}

Credits

Diana Khalipina

Diana Khalipina

22 projects • 93 followers
Integrating Web Accessibility in Healthcare Tech | Web Developer & Bioengineering Specialist in Paris | MSc in Biomedical Engineering

Comments