ooTFw 2:03 PM 79% New content added: Arduino RGB LED An objects color is created
ID: 2084849 • Letter: O
Question
ooTFw 2:03 PM 79% New content added: Arduino RGB LED 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 creabed as shown in the diagram below Cyan White We wil use the RGB led to shine each color ento an object and then using a photoresise, we wll 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.aruro0-create an Ardunoobject to use Ths should be caledene time uess the variable is cleared at the configurePina, pin, mode)-pin can be AD AS oF DO-D3 for the Una Mode can be Diguliput'·'DetalOutpur,'Analogingut, wulup, or readVoltagela,pin)-reads the voltage from an analog pin writeretaPm(a, pin, vauel-value w be ether 0 or 1. pauselamt)-amt is in seconds This will be necessary because it will take a very briel amount of time for the photoresistor to settle after a change in light olor. The ROB LED has the following pins: Red The Cathode should be connected to ground and the other three pins should be connected to digital pins on the Anduio Be sure to place3300hmresistor on each ofthe three color prs Place the LED so that each pin is in a diflerent row and place the resistors acress the cener bridge se is isolated from the You should connect jumper wires to the isolated endsExplanation / Answer
RGB lighting code using MATLAB-Arduino serial interface:
a = arduino('COM8');
a.pinMode(9,'output');
a.pinMode(10,'output');
a.pinMode(11,'output');
% Read analog input from analog pin 0
% The value returned is between 0 and 1023
sensorValue = a.analogRead(0);
%% For the Voltage value from 0 to 511, Fading LED from red to green and keeping blue at constant 0.
if 0 <= sensorValue && sensorValue < 512
Intens_GREEN = floor(sensorValue/2.0);
Intens_RED = 255-Intens_GREEN;
Intens_BLUE = 0;
else
%% ForVoltage value from 511 to 1023, Fading LED from green to blue and keeping red at constant 0.
Intens_BLUE = floor(sensorValue/2.0) - 256;
Intens_GREEN = 255 - Intens_BLUE;
Intens_RED = 0;
end
% Write the intensity values to analog output pins
a.analogWrite(9,Intens_RED);
a.analogWrite(10,Intens_GREEN);
a.analogWrite(11,Intens_BLUE);
end
% Close session
delete(a);
clear a;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.