Circuit 1C: RGB: Parts Needed
Circuit 1C: RGB: Parts Needed
In circuit 1B, you got to use a potentiometer, which varies resistance based on the twisting of a knob.
In this circuit, you’ll be using a photoresistor, which changes resistance based on how much light the
Page | 1
sensor receives. Using this sensor you can make a simple night-light that turns on when the room
gets dark and turns off when it is bright.
Parts Needed
Grab the following quantities of each part listed to build this circuit:
NEW COMPONENTS
RGB LED: An RGB LED is actually three small LEDs — one red, one green and one blue — inside a
normal LED housing. This RGB LED has all the internal LEDs share the same ground wire, so there are
four legs in total. To turn on one color, ensure ground is connected, then power one of the legs just as
you would a regular LED. Don’t forget the current-limiting resistors. If you turn on more than one color at a
time, you will see the colors start to blend together to form a new color.
NEW CONCEPTS
ANALOG OUTPUT (PULSE-WIDTH MODULATION): The digitalWrite() command can turn pins on (5V)
or off (0V), but what if you want to output 2.5V? The analogWrite() command can output 2.5 volts by
quickly switching a pin on and off so that it is only on 50 percent of the time (50% of 5V is 2.5V). By doing
this, any voltage between 0 and 5V can be produced. This is what is known as Pulse-Width Modulation
(PWM). It can create many different colors on the RGB LED.
NEW IDEAS
Page | 2
Page | 3
SOURCE CODE:
void setup() {
Serial.begin(9600); //start a serial connection with the computer
void loop() {
Page | 4
photoresistor = analogRead(A0); //read the value of the photoresistor
potentiometer = analogRead(A1);
Serial.print("Photoresistor value:");
Serial.print(photoresistor); //print the photoresistor value to the serial monitor
Serial.print(" Potentiometer value:");
Serial.println(potentiometer); //print the potentiometer value to the serial monitor
Page | 5
}
void red () {