Question: Write MatLab programming according to the given Arduino Building a simple color detector An objects color is created by the amount of light reflected back

""Write MatLab programming according to the given""

Arduino Building a simple color detector

An objects color is created by the amount of light reflected back to the eye. A red object reflects only red light and absorbs green and blue light. We can make use of this fact to create a simple color detector. Different colors of light are created as shown in the diagram below:

We will use the RGB led to shine each color onto an object and then using a photoresistor, we will determine which color or combination is reflected back the strongest. This process can be used in robotics to perform tasks such as follow a colored line from location to location.

We will need the following Arduino functions in MatLab:

a = arduino() create an Arduino object to use. This should be called one time unless the variable a is cleared at the end each time.

configurePin(a, pin, mode) pin can be A0-A5 or D0 D13 for the Uno. Mode can be DigitalInput, DigitalOutput, AnalogInput, Pullup or

Unset for this lab. readVoltage(a,pin) reads the voltage from an analog pin.

readDigitalPin(a,pin) writeDigitalPin(a, pin, value) value will be either 0 or 1. pause(amt) amt is in seconds. This will be necessary because it will take a very brief amount of time

for the photoresistor to settle after a change in light color.

The RGB LED has the following pins:

The Cathode should be connected to ground and the other three pins should be connected to digital pins on the Arduino. Be sure to place a 330 ohm resistor on each of the three color pins.

Place the LED so that each pin is in a different row and place the resistors across the center bridge so that one end is isolated from the other. You should connect the jumper wires to the isolated ends.

You should try to connect the photoresistor and the LED as close as possible in order to detect the reflected light from an object placed over them.

NOTE: As the light gets brighter, the voltage obtained on the analog pin will decrease.

We will eventually convert this voltage into an integer between 0 and 255.

Place a button across the channel so that you have room to make other connections. Connect the top side to a digital pin and the bottom to ground. We will use the Pullup mode to configure the digital pin so there is no need for a resistor. A resistor inside the Arduino will be used automatically.

When the button is pressed, readDigitalPin returns 0, you should perform the following steps:

turn on green LED record sensor reading G turn off green LED

turn on red LED record sensor reading R turn off red LED

turn on blue LED record sensor reading B turn off blue LED

The objects most prevalent color will be the lowest value. For example yellow may show as red or green since yellow is a mixture of the two colors. To make it easier for us to see, we will convert these numbers to a more standard range of 0 to 255. 0 means there is none of that color present and 255 means it is at the colors highest possible concentration.

You should store your three color values in a vector named inColor in this order [R, G, B] .

NOTE: Before we can continue we need some baseline values. We will use white to get the lowest possible voltage values because white light is made of all three colors evenly concentrated and all should be reflected. We will use black to get the highest possible voltage values because black absorbs all colors and there should be little reflection back to the photoresistor.

Store your values in the following vectors: W = [R, G, B] BL = [R, G, B]

This process should only be done one time and when finished, we are ready to process other colors:

  1. Read the color values and store them in the input vector.

  2. Use the find function to find any values in the input vector which are smaller than the

    values in W. Change those values to equal the corresponding location in W. This can

    happen because of changing light conditions as we work.

  3. Use find to locate any values larger than those in BL. Change those values to equal the

    corresponding value in BL.

  4. Once these corrected values have been obtained, the following line to your code to map

    the voltages into the 0 to 255 range.

color = round(255 (inColor-W).*255./(BL-W))

Your program should automatically compare the results and return the approximate color found.

You can use the diagram on the first page to determine the different combinations of light needed to form a particular color.

Ex: inColor = [0,0,178] The color was: Blue

inColor = [200, 255, 23] The color was: Yellow

""Write a MatLab programming according to the given""

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!