Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1079

Need help on adding TCS34725 Color sensor on a line tracking robot

$
0
0

Hey guys! I am new to this forum but was hoping on getting a bit of help/feedback on my code. I am currently working on a project for my robotics course, it is a line tracking robot with a ultrasonic sensor for obstacle detection, IR sensors for line tracking, a RGB LED that changes color depending on the movement the robot is performing, and a TCS34725 Color sensor that will be used to detect red tape on the track and stop as if it were a stop sign. I have gotten all of my other sensors to work well together, but have not had a lot of success with getting the color sensor to work. I connected it the interrupt pin #3 on my Arduino UNO, but it is not responding except for when my hand completely covers the sensor. Was hoping to get some feedback or help with getting the color sensor working. I am pretty confused on how to use this sensor, any help would be greatly appreciated. Here is my code for just the color sensor

// Libraries for Color Sensor
#include <Wire.h>               //library for communicating with L2C device
#include <Adafruit_TCS34725.h>  //library of commands for color sensor

// Instance of Color Sensor and interrupt variables
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_4X);
#define interruptPin 3
volatile boolean changeDetected = false; 

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 redInterrupt()
{
  changeDetected = true;
}


void setup()
{
    pinMode(interruptPin, INPUT);
    if (tcs.begin()) 
    {
    Serial.println("Found sensor");
    } 
    else 
    {
      Serial.println("No TCS34725 found ... check your connections");
      while (1); // halt!
    }
    attachInterrupt(digitalPinToInterrupt(interruptPin), redInterrupt, FALLING);
    tcs.setInterrupt(false);
    tcs.setIntLimits(1900, 2300);
    tcs.clearInterrupt();
}

void loop() 
{
  // Get Color Sensor Values
 // delay(100);
  uint16_t  r, g, b, c;
  getRawData_noDelay(&r, &g, &b, &c);
  if(changeDetected == true)
  {
    if (r > g || r > b )
    {
      Serial.println("Red Detcted");
      color(255, 255, 255);  // White
      stop(0);
    }
      //goForward(100);
      changeDetected = false;
      tcs.clearInterrupt();
  }
  else
  {
    /** movement functions**/
  }
}

I Can also provide the rest of the code with all of the components as well and pictures of the circuit if need be, just let me know. Thank you!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1079

Trending Articles