Servo is not working with TCS230

I'm working on a project where I have to use SG90 with TCS230. I have powered TCS230 with Arduino's 5V volt pin and I have powered SG 90 with a 9V 2A adapter. Both grounds were connected. In this project, if TCS230 detected value between 1 to 10, then the servo will run. But here, though my TCS230 caught value, my servo did not run and stayed still. Is the problem with my power supply or else?

#include<Servo.h>

#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8

// Variables for Color Pulse Width Measurements
Servo myservo;//set servo name, here servo name is "myservo"
int redPW = 0;
int greenPW = 0;
int bluePW = 0;

void setup() {

  // Set S0 - S3 as outputs
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);

  // Set Sensor output as input
  pinMode(sensorOut, INPUT);

  // Set Pulse Width scaling to 20%
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);

  // Setup Serial Monitor
  Serial.begin(9600);
  //set servo pin
  myservo.attach(9);
}

void loop() {

  // Read Red Pulse Width
  redPW = getRedPW();
  // Delay to stabilize sensor
  delay(2000);

  // Read Green Pulse Width
  greenPW = getGreenPW();
  // Delay to stabilize sensor
  delay(1000);

  // Read Blue Pulse Width
  bluePW = getBluePW();
  // Delay to stabilize sensor
  delay(1000);

  // Print output to Serial Monitor
  Serial.print("Red PW = ");
  Serial.print(redPW);
  Serial.print(" - Green PW = ");
  Serial.print(greenPW);
  Serial.print(" - Blue PW = ");
  Serial.println(bluePW);
  if (redPW >= 1 && redPW <= 10)
  {
    Serial.print("Red");
    myservo.write(45);
    delay(500);
    myservo.write(90);
    delay(500);
  }
  else
  {
    Serial.print("others");
  }
}


// Function to read Red Pulse Widths
int getRedPW() {

  // Set sensor to read Red only
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  // Define integer to represent Pulse Width
  int PW;
  // Read the output Pulse Width
  PW = pulseIn(sensorOut, LOW);
  // Return the value
  return PW;

}

// Function to read Green Pulse Widths
int getGreenPW() {

  // Set sensor to read Green only
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  // Define integer to represent Pulse Width
  int PW;
  // Read the output Pulse Width
  PW = pulseIn(sensorOut, LOW);
  // Return the value
  return PW;

}

// Function to read Blue Pulse Widths
int getBluePW() {

  // Set sensor to read Blue only
  digitalWrite(S2, LOW);
  digitalWrite(S3, HIGH);
  // Define integer to represent Pulse Width
  int PW;
  // Read the output Pulse Width
  PW = pulseIn(sensorOut, LOW);
  // Return the value
  return PW;

}


(I've used a 9V 2A adapter which gives almost 800 mA, but there is no figure for an adapter in fritzing so to create a diagram I've inserted a 9V battery figure)

What is the operating voltage of the SG90 servo ?

4.8-5V :heartbeat:

What voltage are you using to power the servo ?

I have used a 9V 2A power adapter that supplies almost 800 mA.

So the servo has an operating voltage of 4.8-5V and you are supplying 9V

Is that correct ?

yes, Oh my god. Is this why my motor is not running? Is my motor dead??

I've just checked my servo with Arduino 5V supply. It is working fine. But when I attach it to my project it doesn't work. This time I have supplied 5V from Arduino for servo and colour sensor.

That is generally not a good idea either because the Arduino can only supply a limited amount of current and should not be regarded as a power supply

Try the Servo Sweep example sketch. Does it work ?

A little hint here.

Since the Arduino runs from 5 V and the servo runs on 5 V, you need a 5 V power supply.

The Arduino runs from 5 V, you have to supply 5 V to it; it does not supply 5 V.

5 V regulated power supplies in the guise of USB "Phone chargers" are readily available.

So what is this "Arduino 5V supply" to which you refer? :thinking:

Hi, @Nahian_Mugdho
I'm sorry but this picture unfortunately is not going to tell us much, it is what is called a Fritzy and it does not show what you really have as hardware and power supply.

For example what is the component on the left of the picture, I guess its the TCS230.


You need to draw a proper schematic showing all your components.
A hand drawn image would be fine, please include component names and pin lables.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Whatever that is. :roll_eyes:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.