Arduino Tutorials – Lesson 20 – Color Sensor Using Arduino UNO

Creating the reflected color when the light sensor shining a white light at an object program using Arduino UNO

Required Components

  1. Arduino UNO -1 no
  2. Color Sensor -1 no
  3. USB cable -1 no
  4. Jumper Wires -7 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Color Sensor S0, S1, S2, S3 &Out pins to the Arduino UNO board pins 4,5,6,7 &8 respectively.
  3. Connect the sensor vcc pin to the Arduino UNO 5V pin.
  4. Connect the ground connection respectively.
  5. Check the Arduino program.
  6. Check the Circuit Connections.
  7. Run the Arduino program.

Arduino Program

#define s0 4
#define s1 5
#define s2 6
#define s3 7
#define out 8
int data=0;

void setup()
{
  pinMode(s0,OUTPUT);
  pinMode(s1,OUTPUT);
  pinMode(s2,OUTPUT);
  pinMode(s3,OUTPUT);
  pinMode(out,INPUT);
  Serial.begin(9600);
  digitalWrite(s0,HIGH);
  digitalWrite(s1,HIGH);
}

void loop()
{
  digitalWrite(s2,HIGH);
  digitalWrite(s3,HIGH);
  Serial.print("Red value= ");
  GetData();
  digitalWrite(s2,LOW);
  digitalWrite(s3,HIGH);
  Serial.print("Blue value= ");
  GetData();
  digitalWrite(s2,LOW);
  digitalWrite(s3,LOW);
  Serial.print("Green value= ");
  GetData();
  Serial.println();
  delay(500);
}

void GetData()
{
  data=pulseIn(out,LOW);
  Serial.print(data
  Serial.print("\t");
  delay(20);
}

Usage

  1. Color temperature measurement
  2. RGB LED consistency control
  3. Medical diagnosis systems
  4. Health fitness systems
  5. Industrial process control

Leave a Reply

Your email address will not be published. Required fields are marked *