0
$\begingroup$

I have a GY-31 Light sensor and I am trying to make a skittle sorting machine. There is a little wheel skittles can drop into then they are turn to 90 degrees read by the light sensor then dropped out the bottom. The problem is the code seems to get stuck after reading the light sensor (it still flows through but won't execute the moving of the servo). As soon as I take out the ReadSensor line the servo works like normal. Do I have to dispose of the Color Sensor some how?

#include <Servo.h>
#include <MD_TCS230.h>
#include <FreqCount.h>

#define  S2_OUT  2
#define  S3_OUT  3
MD_TCS230  CS(S2_OUT, S3_OUT);

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

void setup() 
{ 
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object 
  Serial.begin(57600);
  Serial.println("[TCS230 Simple BLOCKING Example]");
  Serial.println("Move the sensor to different color to see the value");
  Serial.println("Note: These values are being read in without sensor calibration");
  Serial.println("and are likely to be far from reality");

  CS.begin();
  CS.setFilter(TCS230_RGB_X);
  CS.setFrequency(TCS230_FREQ_HI);
  CS.setSampling(100); 
} 

 void readSensor()
{
  uint32_t v;
  v = CS.readSingle();
  Serial.print("Simple value = ");
  Serial.println(CS.readSingle());

}

void loop() 
{ 
  Serial.println("Start");
  myservo.write(0);
  delay(1000);
  myservo.write(90);
  delay(1000);
 readSensor();
  myservo.write(180);
  delay(1000);
} 
$\endgroup$
  • 1
    $\begingroup$ Some possible errors: "myservo.attach(11); // attaches the servo on pin 9 to the servo object " Comment says to pin 9, code says to pin 11. You have attached to the right pin. You have the right "freqcount.h" ?? Why you call contructor with minimum config "MD_TCS230 CS(S2_OUT, S3_OUT);" you sure you don't need the other pins? $\endgroup$ – TobiasK Oct 31 '14 at 7:04
  • $\begingroup$ Not related to the problem at hand, but why do you bother with setting v in readSensor() since you never use it? $\endgroup$ – apnorton Nov 1 '14 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.