LUX / RGBC / Color Temp Meter by Spike

 Lux- en Kleur meter met Oled-scherm

Dit klein projectje is bedoeld om Lichtsterkte te meten en de kleuren intensiteit per kleur evenals de kleurTemepatuur van het licht.


Gebruikte onderdelen

Oled Scherm 32 * 128 I2C interface

TCS34725 RGD sensor Adafruit

Arduino Nano


Het schema 




Enkele foto's van de test opstelling








Meer uitleg is er niet nodig 









de Code 

----------------------------------------------------------------------------------------------------------

#include <Wire.h>

#include <Adafruit_TCS34725.h>

#include <Adafruit_SSD1306.h>  // include Adafruit SSD1306 OLED display driver


#define OLED_RESET  4    // define display reset pin


#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 32 // OLED display height, in pixels

 /* 128x32 SSD1306 OLED

 * 

 * PIN AANSLUITINGEN: 

 * 

 * VCC    3.3V

 * GND    GND

 * SCL    A5

 * SDA    A4 

 *  

 */

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

/* Initialise with specific int time and gain values */

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

const int interruptPin = 2;

volatile boolean state = false;



//Interrupt Service Routine

void isr() 

{

  state = true;

}


/* tcs.getRawData() does a delay(Integration_Time) after the sensor readout.

We don't need to wait for the next integration cycle because we receive an interrupt when the integration cycle is complete*/

void getRawData_noDelay(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)

{

  *c = tcs.read16(TCS34725_CDATAL);

  *r = tcs.read16(TCS34725_RDATAL);

  *g = tcs.read16(TCS34725_GDATAL);

  *b = tcs.read16(TCS34725_BDATAL);

}



void setup() {

  pinMode(interruptPin, INPUT_PULLUP); //TCS interrupt output is Active-LOW and Open-Drain

  attachInterrupt(digitalPinToInterrupt(interruptPin), isr, FALLING);


  Serial.begin(9600);

  

  if (tcs.begin()) {

    Serial.println("Found sensor");

  } else {

    Serial.println("No TCS34725 found ... check your connections");

    while (1);

  }

  

  // Set persistence filter to generate an interrupt for every RGB Cycle, regardless of the integration limits

  tcs.write8(TCS34725_PERS, TCS34725_PERS_NONE); 

  tcs.setInterrupt(true);

  

//  Serial.flush();


display.begin(SSD1306_SWITCHCAPVCC, 0x3C);


  // clear the display buffer.

  display.clearDisplay();

 

  display.setTextSize(1);   // text size = 1

  display.setTextColor(WHITE, BLACK);  // set text color to white and black background


  display.setTextSize(1);

  // display.invertDisplay(true);

  display.setTextColor(WHITE);

  display.setCursor(20, 4);

  display.println("Arduino Projects");

  display.drawRoundRect(0, 0, 128, 16, 4, WHITE); //drawRect(x, y, width, height, color) 

    display.setCursor(20, 20);

  display.setTextSize(2);

      display.setCursor(10, 15);

    display.println("By");

      display.setTextSize(2);

          display.setCursor(50, 15);

      display.println("Spike");

  display.display();        // update the display

delay(2000);


  

}



void loop() {

  //if (state) {

    uint16_t r, g, b, c, colorTemp, lux;

    getRawData_noDelay(&r, &g, &b, &c);

    colorTemp = tcs.calculateColorTemperature(r, g, b);

    lux = tcs.calculateLux(r, g, b);

    

    Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");

    Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");

    Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");

    Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");

    Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");

    Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");

    Serial.println(" ");

    Serial.flush();



display.clearDisplay();

 

  display.setTextSize(1);   // text size = 1

  display.setTextColor(WHITE, BLACK);  // set text color to white and black background


  display.setTextSize(1);

//   display.invertDisplay(false);

  display.setTextColor(WHITE);

  display.setCursor(5, 0);

  display.println("Lux:");

 // display.drawRoundRect(0, 0, 128, 16, 4, WHITE); //drawRect(x, y, width, height, color) 

 //   display.setCursor(20, 20);


      display.setTextSize(2);

          display.setCursor(60, 0);

      display.println(lux, DEC);


  display.setTextSize(1);

      display.setCursor(0, 8);

   display.print("T:");

display.println(colorTemp, DEC);


      display.setCursor(0, 16);

   display.print("R:");

display.println(r, DEC);


      display.setCursor(60,16);

   display.print("G:");

display.println(g, DEC);


      display.setCursor(0, 25);

   display.print("B:");

display.println(b, DEC);


      display.setCursor(60, 24);

   display.print("C:");

display.println(c, DEC);


      

  display.display();        // update the display

delay(2000);

    tcs.clearInterrupt();

}


-------------------------------------------------------------------------------------------------------------------

Geen opmerkingen:

Een reactie posten

pzem module op Wemos D1 ESP easy

pzem module voorzien van R 1K tussen rx en 5v RX van pzem op D8 TX van pzem op D7 Wemos Config esp easy RX: GPIO-13 (D7) TX: GPIO-15 (D8) ht...