Survo motor doesn't work with Color Sensor RGB TCS230/TCS3200

My RGB can work but I want to use RGB scan red colour, If it red colour servor motor will write to 90' and back but my servo doesn't work and I don't know enough about it. How to fix it ?

This is my code

#include <Servo.h> 
Servo myservo;

const int outputEnabled = 2; // write LOW to turn on Note, may not be hooked up.
const int s0 = 3; // sensor pins
const int s1 = 4;
const int s2 = 5;
const int s3 = 6;
const int nLED = 7; // illuminating LED
const int out = 8; // TCS230 output

// variables to store color values
int pos = 0; 
int red = 0 ;
int green = 0;
int blue = 0;
void setup() {
pinMode(outputEnabled, OUTPUT);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(nLED, OUTPUT);
pinMode(out, INPUT);
Serial.begin(9600);
//This pin may be set to ground and not available on the breakout
//If not available don't worry about it.
digitalWrite(outputEnabled, LOW);
//Set Frequency scaling to largest value
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(nLED, LOW);
myservo.attach(9);
}

void loop() {
color();
Serial.print("R");
Serial.print(red, DEC);
Serial.print(" G");
Serial.print(green, DEC);
Serial.print(" B");
Serial.print(blue, DEC);
Serial.println();
//Simple logic to test for color
if (red < blue && red < green) 
{ Serial.println("Red");
 myservo.write(0); 
  myservo.write(90); 
        delay(1000); 

}
else if (blue < red && blue < green) Serial.println("blue");
else Serial.println("green");
delay(1000);
}

void color() {
digitalWrite(nLED,1);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
// count OUT, pRed, RED
red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s3, HIGH);
//count OUT, pBLUE, BLUE
blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s2, HIGH);
// count OUT, pGreen, GREEN
green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(nLED,0);
}

Thank you.

 myservo.write(0); 
  myservo.write(90); 
        delay(1000);

You are not giving the servo time to move there. Add a few hundred millisecond delay between the servo writes.

I changed it but is the same.

When you make changes to your code, please post your latest version.

this is my last code.

#include <Servo.h> 
Servo myservo;

const int outputEnabled = 2; // write LOW to turn on Note, may not be hooked up.
const int s0 = 3; // sensor pins
const int s1 = 4;
const int s2 = 5;
const int s3 = 6;
const int nLED = 7; // illuminating LED
const int out = 8; // TCS230 output

// variables to store color values
int pos = 0; 
int red = 0 ;
int green = 0;
int blue = 0;
void setup() {
pinMode(outputEnabled, OUTPUT);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(nLED, OUTPUT);
pinMode(out, INPUT);
Serial.begin(9600);
//This pin may be set to ground and not available on the breakout
//If not available don't worry about it.
digitalWrite(outputEnabled, LOW);
//Set Frequency scaling to largest value
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(nLED, LOW);
myservo.attach(9);
}

void loop() {
color();
Serial.print("R");
Serial.print(red, DEC);
Serial.print(" G");
Serial.print(green, DEC);
Serial.print(" B");
Serial.print(blue, DEC);
Serial.println();
//Simple logic to test for color
if (red < blue && red < green) 
{ Serial.println("Red");
 myservo.write(0); 
 delay(1000);
  myservo.write(90); 
        delay(1000); 

}
else if (blue < red && blue < green) Serial.println("blue");
else Serial.println("green");
delay(1000);
}

void color() {
digitalWrite(nLED,1);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
// count OUT, pRed, RED
red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s3, HIGH);
//count OUT, pBLUE, BLUE
blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s2, HIGH);
// count OUT, pGreen, GREEN
green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(nLED,0);
}

So you are saying that you get the RGB values and the word "Red" printed on the serial monitor but the servo never moves? Then it is wired up wrong, the servo itself is bad or you don't have enough power for it.

What type of servo is it and how exactly is it connected?

Steve

Hi,
Have you written some code that just controls the servo, with out any other code.
If not, please write some code to sweep your servo, to prove it is working.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Including power supply.

Tom... :slight_smile: