Friday, 27 June 2014

Colour Mixing of RGB

I was unable to get the diffused common anode RGB led. So I put red, blue and green LEDs together using a tape. Now I could notice the colour mixing of intersection.

In the hex code of colours, each 2 characters represent the value of red, green and blue sequentially. To convert the hex code of a colour into its number form, 0x  is prefixed to the hex value.

For example the code for Deep pink is #FF1493 . So its red value is FF, green is 14, blue is 93.
So in my program, setcolour(0xFF, 0x93, 0x14) gives me deep pink

Breadboard Layout:


Code:

int red=11;
int blue=10;
int green=9;
void setup()
{
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop()
{
  setcolour(255,0,0);//red
  delay(2000);
  setcolour(0,255,0);//blue
  delay(2000);
  setcolour(0,0,255);//green
  delay(2000);
  // #FFFF66: yellow
  setcolour(0xFF, 0xFF, 0x66);
    delay(4000);
  setcolour(0xFF, 0x93, 0x14);//pink
     delay(4000);
  //spring green #00FA9A
  setcolour(0x00,0x9A, 0xFA);
  delay(4000);
}

void setcolour(int red_value, int blue_value, int green_value)
{
  analogWrite(red, red_value);
  analogWrite(blue, blue_value);
  analogWrite(green, green_value);
}

Fading using Pulse width modification

 Pulse Width Modification is a power controlling technique where we get analog results from digital means. In this we modify the on-off pattern of a digital clock to vary the analog values.
As we mix the colour paints on the palette, we can mix the colours of LEDs using PWM. This can be done using the command analogWrite.
analogWrite() takes the value from 0-255.
255=100% duty cycle;    127=50% duty cycle;

Fading of LED:

Circuit layout:



Code:


int led=11; int brightness=255; int fade=5;
void setup()
{
  pinMode(led, OUTPUT);
}
void loop()
{
 analogWrite(led, brightness);
 brightness=brightness-fade;
 if(brightness==255||brightness==0) //reversing effect
 !fade;
 delay(100);
}


Sunday, 22 June 2014

My First Project-BLINK

Being an ECE student having not gone to any intern, I thought of doing some projects while on my vacation. I found arduino as a good platform to start with. I downloaded the arduino IDE from this link   http://arduino.cc/en/Main/Software . After installing the software, we need to initialize the serial port to which arduino is connected..Here I begin :D :D

So What is Arduino?

From the Arduino.cc homepage:
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Blinking 5 LEDs in a row for a second each

This is the most basic arduino project. You can use the inbuilt L-LED connected to 13th pin of the arduino board or connect external led.

Arduino code consists of two parts basically:
1. setup() : it runs when the arduino is initialized(reset)
2. loop(): it runs till arduino is off.

  • pinMode is the command to assign a pin of arduino board to either input or output mode
  • digitalWrite is used to set a pin to digital High (on) or low (off)
  • delay( ) takes the value in milliseconds for delay

Breadboard Layout:


Code:


/* My First Program */

int pin2=2;
int pin3=3;
int pin4=4;
int pin5=5;
int pin6=6;

void setup()
{
  pinMode(pin2, OUTPUT);
   pinMode(pin3, OUTPUT);
    pinMode(pin4, OUTPUT);
     pinMode(pin5, OUTPUT);
      pinMode(pin6, OUTPUT);

}
void loop()
{
   digitalWrite(pin2, HIGH);
  delay(1000);
  digitalWrite(pin2, LOW);
  delay(1000);
     digitalWrite(pin3, HIGH);
  delay(1000);
  digitalWrite(pin3, LOW);
  delay(1000);
     digitalWrite(pin4, HIGH);
  delay(1000);
  digitalWrite(pin4, LOW);
  delay(1000);
     digitalWrite(pin5, HIGH);
  delay(1000);
  digitalWrite(pin5, LOW);
  delay(1000);
     digitalWrite(pin6, HIGH);
  delay(1000);
  digitalWrite(pin6, LOW);
  delay(1000);
}

Output: