Part 3: Arduino Projects

In the arduino project book I will be doing project number 4 and 5. The 1st  project is called color mixing lamp. In the book it says this project take approximately 45 minutes to complete. For me it may have taken me about an hour because I would add another 15 minutes to set up and how i would like to wire the circuit. A new idea that I have tried when dealing with arduino is get piece of paper and pen and write out detail for detail how the curcuit board and arduino uno going to be wired. I have done this because with previous project I have encounter issues and i thought it was good idea for troubleshooting. Make sure on the arduino software in the tools tab the serial port is correct and board is correct.

The materials needs for this project would include:

220 OHM Resistors (3)                                        10 KILOHMS Resistors (3)

RGB LED has 4 legs                                            13 jumper wire

Photoresistors (3)                                                   Breadboard

Arduino Uno                                                             red green blue gels

rbg led  Photoresistorresistor

The purpose of this project is to use red green blue tri color led, photoresisor and red green or blue gels to fade the leds to the specific colors (color mixing lamp). For example, using an green gel on photoresistor the RGB led should display color green.

I will explain the role of each component on the circuit board to make this happen.On the arduino uno you can see next to pin number digital (PWM~).Pulse Width Modulation (PMW) can be used to fade leds. PMW turn the output pins high or low like change lights on and off. The percentage of time a pin is high in a period it called duty cycle. A lower duty cycle will give dimmer LED than higher duty cycle. The arduino uno has 6 pins set aside for PMW (digital pins 3,5,6,10,11). Notice the ~ symbol next to each pin. Photoresistors are sensors (input) they change resistance depending on the amount of light that hit the sensor. On the board 3 photoresistor connect one side  to power and another side to 10 kilohms resistor that would go to ground.

The resistor along with photoresistor form a voltage provider; the voltage at the point where they meet is proportional to the ratio of their resistance. when resistance change of the photoresistor changes when light it so would voltage, it is rule of ohm’s laws. In addition along side resistor are 3 jumper wire connected to analog in pins 0-2. Each analog is coded for a specific color like green over photoresistor connected to analog 1 or A1.

The most interesting component on the circuit board is 4 leg RGB LED. First I would like you to note that 3 220 ohms resistor are connected to 3 pwm pins 9-11 because they determine how much voltage the RGB led should receive out of 5 voltage. It has a red green and blue element inside plus a leg for ground (the cathode).

Color Mixing Lamp Code

//declare the RGB led, the value never change
const int greenLEDPin = 9;
const int redLEDPin = 11;
const int blueLEDPin = 10;

//link input and output
const int redSensorPin = A0;
const int greenSensorPin = A1;
const int blueSensorPin = A2;

//add variable for incoming sensor value and for the output of value when using fade
//declare variables
int redValue = 0;
int greenValue = 0;
int blueValue = 0;

int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;

//begins communication between board and pc
void setup (){
pinMode(greenLEDPin, OUTPUT); //define led pins as output
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
void loop(){
//read the value of each light sensor
//analogRead store the value in appropriate variable with ADC
redSensorValue = analogRead(redSensorPin);
delay(5); //take analog digital converter a millisecond to read each sensor
greenSensorValue = analogRead(greenSensorPin);
blueSensorValue = analogRead(blueSensorPin);

//print values onto serial monitor on pc
Serial.print(“Raw Sensor Value \t Red: “); //\t is like tab key on keyboard
Serial.print(“\t Green: “);
Serial.print(“\t Blue; “);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;
Serial.print(“mapped Sensor Value \t Red: “);
Serial.print(“\t Green: “);
Serial.print(“\t blue: “);
//the function to change 4 leg led brightness (pwm) is analogwrite
analogWrite (redLEDPin, redValue);
analogWrite (greenLEDPin, greenValue);
analogWrite (blueLEDPin, blueValue);


Part 2 Project 5 Mood Cue

This project uses a new component called servo motor. The objective is to design servo motor to rotate motor arm by turn the potentiometer. It is suppose to determine what would you are in today.I think it detect I was in bad mood because mines did not work completely.According to the book this project take a hour to complete. There are a lot of few new materials I will be using this project. The materials include:

Potentiometer                    100UF Capacitor (2)

Servo Motor                        Male header Pins (3)

Motor Arm                          Jumper wire (8)

all materialsP5

mini details of servo motor

Servo motors are special motors that only spin around 180 degree not a full circle. Servo motor has a certain number of pulses that tell them what angle to move to. The pulses always come at the same time intervals, but the width varies between 1000 to 2000 microseconds. Arduino software come with library that allow you easily control the motor.Servo only rotate 180 degrees and your analog input goes 0-1023. Use the function map() to change scale values coming from the potentiometer.

The set up process

The circuit board is first connected to jumper cables of 5 voltage and ground.  There is a 100uf capacitor in front of the potentiometer. Capacitor role is to store and release electrical energy in circuit. The potentiometer is a voltage divider. It has 3 pins, 1 pin connect to ground, middle pin connect to analog in and last pin connect to power. When turn the knob it will change the voltage between analog pin and power. NOTE: potentiometer is two piece component that has to be put together, the knob and 3 pin piece is separate.

The servo motor has 3 wires. red wire for power,black wire for ground and white wire for control or pin ~9. Note: the servo motor has female connectors and you would need to use 3 male connectors for this circuit. In addition the motor arm would have to be placed on the servo motor. When servo motor start to move it will draw more current than if it was in motion. Placing 100uf capacitor across power and ground next to male connectors it will balance out voltage on the circuit. The servo motor is using pwm pin and it is converted using analog digital converter A0.

The Mood cue code

#include <Servo.h>                      //new library because new feature and has to be declared

Servo myServo;                         //declare the object servo 

//declare variable

//set up named constant for the pin the potentiometer attached to and variable to hold the analog input value

int const potPin = A0;

int potVal;

int angle;
void setup(){                                      //servo is attach to pin 9
Serial.begin(9600);                    //serial connection the value can be checked on pc everytime turn potentimeter
void loop(){                                 //read analog input and print out the value to the serial monitor
potVal = analogRead(potPin);
Serial.print(“potVal: “);
angle = map(potVal, 0, 1023, 0, 179);
Serial.print(“, angle: “);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s