Prasannaa Kumar
Published © CC BY-SA

Color Sensor with Particle Boron

This project in order to evaluate the pH value of the soil which reacts with a substrate and changes its color.

ExpertWork in progress12 hours1,367
Color Sensor with Particle Boron

Things used in this project

Hardware components

Boron
Particle Boron
×1
Adafruit TCS34725 Color Sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

pH Paper

Story

Read more

Code

Thingspeak Code

Arduino
Copy and paste the code in the Particle Web IDE.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
TCPClient client;
unsigned long myChannelNumber = YOUR CHANNEL NUMBER HERE;
const char * myWriteAPIKey = "YOUR WRITE API KEY HERE";

// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_TCS34725.h"
#include <math.h>

boolean commonAnode = false;
char szInfo[128];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
    Serial.begin(9600);
  ThingSpeak.begin(client);

    Serial.println("Color View Test!");
    
    if (tcs.begin()) {
        Serial.println("Found sensor");
    } else {
        Serial.println("No TCS34725 found ... check your connections");
        while (1); // halt!
    }
}


void loop() {
    uint16_t clear, red, green, blue;

    tcs.setInterrupt(false);      // turn on LED
    
    delay(60);  // takes 50ms to read 
      
    tcs.getRawData(&red, &green, &blue, &clear);
    tcs.setInterrupt(true);  // turn off LED
    
    // Figure out some basic hex code for visualization
    uint32_t sum = clear;
    float r, g, b;
    
    r = red; r /= sum;
    g = green; g /= sum;
    b = blue; b /= sum;
    r *= 256; g *= 256; b *= 256;
    
    sprintf(szInfo, "%d,%d,%d", (int)r, (int)g, (int)b);
    
    ThingSpeak.writeField(myChannelNumber, 1, r, myWriteAPIKey);
    ThingSpeak.writeField(myChannelNumber, 2, g, myWriteAPIKey);
    ThingSpeak.writeField(myChannelNumber, 3, b, myWriteAPIKey);

    Serial.println(szInfo);
    
    delay(1000);
}

Basic Code

Arduino
#include "Adafruit_TCS34725.h"
#include <math.h>

boolean commonAnode = false;
char szInfo[128];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
    Serial.begin(9600);
    Serial.println("Color View Test!");
    
    if (tcs.begin()) {
        Serial.println("Found sensor");
    } else {
        Serial.println("No TCS34725 found ... check your connections");
        while (1); // halt!
    }
}

void loop() {
    uint16_t clear, red, green, blue;

    tcs.setInterrupt(false);      // turn on LED
    
    delay(60);  // takes 50ms to read 
      
    tcs.getRawData(&red, &green, &blue, &clear);
    tcs.setInterrupt(true);  // turn off LED
    
    // Figure out some basic hex code for visualization
    uint32_t sum = clear;
    float r, g, b;
    
    r = red; r /= sum;
    g = green; g /= sum;
    b = blue; b /= sum;
    r *= 256; g *= 256; b *= 256;
    
    sprintf(szInfo, "%d,%d,%d", (int)r, (int)g, (int)b);
    
    Spark.publish("colorinfo", szInfo);
    
    Serial.println(szInfo);
    
    delay(1000);
}

Credits

Prasannaa Kumar

Prasannaa Kumar

9 projects • 24 followers
I'm a Maker and I have been continuously developing skills in IoT, 3D Printing, Fabrication, Machine Learning and Robotics.

Comments

Add projectSign up / Login