Arduino Projects

= Time and Gas Sensor with Display =



#include 
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) define CLK 2            //Arduino pins which are connected to  Display
 * 5) define DIO 3

const byte gas_sensor = 0; int gas_level; int redLed = 12; int buzzer = 10; int sensorThres = 400;              // Your threshold value int i = 0; TM1637 display(CLK,DIO);              //To work with the chip clock and indicator we use the library DS3231 rtc(SDA, SCL);                // Init the DS3231 using the hardware interface Time t;                               // Init a Time-data structure

void beeptone { for(i = 0; i < 255; i = i + 2) {    analogWrite(buzzer, i); delay(10); } for(i = 255; i > 1; i = i - 2) {    analogWrite(buzzer, i); delay(5); } for(i = 1; i <= 10; i++) {    analogWrite(buzzer, 200); delay(100); analogWrite(buzzer, 25); delay(100); } }

void setup { // Serial.begin(9600);                 // Setup Serial connection display.set;                     //Enable and configure the indicator display.init; rtc.begin;                     // Initialize the rtc object // The following lines can be uncommented to set the date and time //rtc.setDOW(WEDNESDAY);           // Set Day-of-Week to SUNDAY //rtc.setTime(12, 0, 0);           // Set the time to 12:00:00 (24hr format) //rtc.setDate(1, 1, 2014);         // Set the date to January 1st, 2014 }

void loop { int8_t timeDisp[4];                 //The values to be displayed on each of 4 bits t = rtc.getTime;                 //Get data from the DS3231 timeDisp[0] = t.hour / 10;         //We receive dozens of hours using integer division timeDisp[1] = t.hour % 10;         //Unit obtain hours using modulo timeDisp[2] = t.min / 10;          //We do the same with minutes timeDisp[3] = t.min % 10; display.point(POINT_ON);           //colon ON  display.display(timeDisp);          //output it to the screen delay (2000);

gas_level= analogRead(gas_sensor); //Gas Sensor get data display.point(POINT_OFF); display.DigitDisplayWrite(CLK,DIO,gas_level); // Serial.println(gas_level); if (gas_level > sensorThres) {   digitalWrite(redLed, HIGH); beeptone; } else {   digitalWrite(redLed, LOW); noTone(buzzer); } delay (2000); }

= Versatile Kitchen Timer =



 //This code is written by Amandeep Singh

const int outpin = 9;   // Buzzer Pin int pin1 = 2;           //Switch Pins int pin2 = 3;           //Switch Pins int pin3 = 4;           //Switch Pins int pin4 = 5;           //Switch Pins int button = 0;         //initial button state

void beeptone { tone(outpin, 500, 500); delay(100); tone(outpin, 1000, 500); delay(100); tone(outpin, 1500, 500); delay(100); tone(outpin, 2000, 500); delay(100); }

void setup { pinMode(pin1, INPUT_PULLUP); pinMode(pin2, INPUT_PULLUP); pinMode(pin3, INPUT_PULLUP); pinMode(pin4, INPUT_PULLUP); }

void loop { button = digitalRead(pin1); if (button == LOW) {     delay(5*60*1000);               // 5 Minute timer for (int i=0; i<= 50; i++){ beeptone; } }  button = digitalRead(pin2); if (button == LOW) {     delay(10*60*1000);               // 10 Minute timer for (int i=0; i<= 50; i++){ beeptone; } }    button = digitalRead(pin3); if (button == LOW) {     delay(30*60*1000);               // 30 Minute timer for (int i=0; i<= 50; i++){ beeptone; } }    button = digitalRead(pin4); if (button == LOW) {     delay(60*60*1000);               // 1 Hour timer for (int i=0; i<= 50; i++){ beeptone; } } }

= Light Controlled Relay Switch = int sensorPin = A0;  // select the input pin for ldr int sensorValue = 0; // variable to store the value coming from the sensor

void setup { pinMode(2, OUTPUT); //pin connected to the relay Serial.begin(9600); }

void loop { // read the value from the sensor: sensorValue = analogRead(sensorPin); Serial.println(sensorValue);      //prints the values coming from the sensor on the screen if(sensorValue < 700) //setting a threshold value digitalWrite(2,HIGH); //turn relay ON else digitalWrite(2,LOW); //turn relay OFF delay(100); }

=Game of Thrones= Source: [instructables.com]

 int sensorPin=6; int speakerPin=2; void GameOfThrones; void setup {   pinMode(speakerPin,OUTPUT); pinMode(sensorPin,INPUT); } void loop { //play when entering or leaving you thrones, chair etc.      //im using negative logic infrared sensor(if positive logic, use HIGH insted of LOW) if(digitalRead(sensorPin)==LOW) {    delay(50); if(digitalRead(sensorPin)==LOW) {      GameOfThrones; }    }   }
 * 1) define NOTE_B0 31
 * 2) define NOTE_C1 33
 * 3) define NOTE_CS1 35
 * 4) define NOTE_D1 37
 * 5) define NOTE_DS1 39
 * 6) define NOTE_E1 41
 * 7) define NOTE_F1 44
 * 8) define NOTE_FS1 46
 * 9) define NOTE_G1 49
 * 10) define NOTE_GS1 52
 * 11) define NOTE_A1 55
 * 12) define NOTE_AS1 58
 * 13) define NOTE_B1 62
 * 14) define NOTE_C2 65
 * 15) define NOTE_CS2 69
 * 16) define NOTE_D2 73
 * 17) define NOTE_DS2 78
 * 18) define NOTE_E2 82
 * 19) define NOTE_F2 87
 * 20) define NOTE_FS2 93
 * 21) define NOTE_G2 98
 * 22) define NOTE_GS2 104
 * 23) define NOTE_A2 110
 * 24) define NOTE_AS2 117
 * 25) define NOTE_B2 123
 * 26) define NOTE_C3 131
 * 27) define NOTE_CS3 139
 * 28) define NOTE_D3 147
 * 29) define NOTE_DS3 156
 * 30) define NOTE_E3 165
 * 31) define NOTE_F3 175
 * 32) define NOTE_FS3 185
 * 33) define NOTE_G3 196
 * 34) define NOTE_GS3 208
 * 35) define NOTE_A3 220
 * 36) define NOTE_AS3 233
 * 37) define NOTE_B3 247
 * 38) define NOTE_C4 262
 * 39) define NOTE_CS4 277
 * 40) define NOTE_D4 294
 * 41) define NOTE_DS4 311
 * 42) define NOTE_E4 330
 * 43) define NOTE_F4 349
 * 44) define NOTE_FS4 370
 * 45) define NOTE_G4 392
 * 46) define NOTE_GS4 415
 * 47) define NOTE_A4 440
 * 48) define NOTE_AS4 466
 * 49) define NOTE_B4 494
 * 50) define NOTE_C5 523
 * 51) define NOTE_CS5 554
 * 52) define NOTE_D5 587
 * 53) define NOTE_DS5 622
 * 54) define NOTE_E5 659
 * 55) define NOTE_F5 698
 * 56) define NOTE_FS5 740
 * 57) define NOTE_G5 784
 * 58) define NOTE_GS5 831
 * 59) define NOTE_A5 880
 * 60) define NOTE_AS5 932
 * 61) define NOTE_B5 988
 * 62) define NOTE_C6 1047
 * 63) define NOTE_CS6 1109
 * 64) define NOTE_D6 1175
 * 65) define NOTE_DS6 1245
 * 66) define NOTE_E6 1319
 * 67) define NOTE_F6 1397
 * 68) define NOTE_FS6 1480
 * 69) define NOTE_G6 1568
 * 70) define NOTE_GS6 1661
 * 71) define NOTE_A6 1760
 * 72) define NOTE_AS6 1865
 * 73) define NOTE_B6 1976
 * 74) define NOTE_C7 2093
 * 75) define NOTE_CS7 2217
 * 76) define NOTE_D7 2349
 * 77) define NOTE_DS7 2489
 * 78) define NOTE_E7 2637
 * 79) define NOTE_F7 2794
 * 80) define NOTE_FS7 2960
 * 81) define NOTE_G7 3136
 * 82) define NOTE_GS7 3322
 * 83) define NOTE_A7 3520
 * 84) define NOTE_AS7 3729
 * 85) define NOTE_B7 3951
 * 86) define NOTE_C8 4186
 * 87) define NOTE_CS8 4435
 * 88) define NOTE_D8 4699
 * 89) define NOTE_DS8 4978

void GameOfThrones {   for(int i=0; i<4; i++) {   tone(speakerPin, NOTE_G4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(250); noTone(speakerPin); }   for(int i=0; i<4; i++) {   tone(speakerPin, NOTE_G4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_E4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(250); noTone(speakerPin); }       tone(speakerPin, NOTE_G4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(500); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(500); noTone(speakerPin); for(int i=0; i<3; i++) {   tone(speakerPin, NOTE_G3); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(500); noTone(speakerPin); }//       tone(speakerPin, NOTE_G3); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(500); noTone(speakerPin); for(int i=0; i<3; i++) {   tone(speakerPin, NOTE_GS3); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_F3); delay(500); noTone(speakerPin); }         tone(speakerPin, NOTE_G4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_G4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(1000); noTone(speakerPin); tone(speakerPin, NOTE_DS4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_F4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(500); noTone(speakerPin); for(int i=0; i<4; i++) {   tone(speakerPin, NOTE_G3); delay(500); noTone(speakerPin); tone(speakerPin, NOTE_AS3); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_C4); delay(250); noTone(speakerPin); tone(speakerPin, NOTE_D4); delay(500); noTone(speakerPin); } } =Led Cube 3x3x3= http://circuitdigest.com/microcontroller-projects/making-3X3X3-led-cube-with-arduino

= Bluetooth Controlled RC Car = Source: instructables.com, instructables.com



const int motor1Pin1 = 10; const int motor1Pin2 = 11; const int motor2Pin1 = 6; const int motor2Pin2 = 5; const int led = 8; const int buzzer = 12; int i = 0;

byte serialA;

void setup { Serial.begin(9600);

pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(led, OUTPUT); pinMode(buzzer, OUTPUT); }

void alarm { for (int i=0; i<2; i++)                   //alarm will ring for 2 seconds once triggered { digitalWrite(buzzer, HIGH); delay(500); digitalWrite(buzzer, LOW); delay(100); } }

void loop { if (Serial.available > 0) { serialA = Serial.read; Serial.println(serialA); }  switch (serialA) { // forward case 'F': digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); break; // left case 'L': digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); break; // right case 'R': digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); break; // forward left case 'G': digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); break; // forward right case 'I': digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); break;

// backward left case 'H': digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); break; // backward right case 'J': digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); break; // backward case 'B': digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); break; // Stop case 'S': digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); break; case 'W': digitalWrite(led, HIGH); break; case 'w': digitalWrite(led, LOW); break; case 'V': alarm; break; } }

=Bluetooth RC Car with Speed Control=

 const int motorA1  = 11;         //  L293 Connection   Pin  2 of L293 const int motorA2 = 10;       // Pin  7 of L293 const int motorB1 = 6;        // Pin 10 of L293 const int motorB2 = 5;        // Pin 14 of L293

const int lights = 13;        //Leds connected to Arduino UNO Pin 12 const int buzzer = 8 ;        //Buzzer,Speaker to Arduino UNO Pin 3 const int BTState = 7;        //Bluetooth (HC-06 JY-MCU) State pin on pin 2 of Arduino //Calculate Battery Level const float maxBattery = 8.0; // Change value to your max battery voltage level! int perVolt;                  // Percentage variable float voltage = 0.0;          // Read battery voltage int level; // Use it to make a delay... without delay function! long previousMillis = -1000*10;// -1000*10=-10sec. to read the first value. If you use 0 then you will take the first value after 10sec. long interval = 1000*10;      // interval at which to read battery voltage, change it if you want! (10*1000=10sec) unsigned long currentMillis;  //unsigned long currentMillis;

int i=0;                      //Useful Variables int j=0; int state; int vSpeed=200;               // Default speed, from 0 to 255

void setup { pinMode(motorA1, OUTPUT);   // Set pins as outputs: pinMode(motorA2, OUTPUT); pinMode(motorB1, OUTPUT); pinMode(motorB2, OUTPUT); pinMode(lights, OUTPUT); pinMode(BTState, INPUT); Serial.begin(9600);        // Initialize serial communication at 9600 bits per second: } void loop { if(digitalRead(BTState)==LOW) { state='S'; }  //Stop car when connection lost or bluetooth disconnected if(Serial.available > 0){      //Save income data to variable 'state' state = Serial.read; }     if (state == '0'){              //Change speed if state is equal from 0 to 4. Values must be from 0 to 255 (PWM) vSpeed=0;} else if (state == '1'){ vSpeed=100;} else if (state == '2'){ vSpeed=200;} else if (state == '3'){ vSpeed=300;} else if (state == '4'){ vSpeed=400;} else if (state == '5'){ vSpeed=500;} else if (state == '6'){ vSpeed=600;} else if (state == '7'){ vSpeed=700;} else if (state == '8'){ vSpeed=800;} else if (state == '9'){ vSpeed=900;} else if (state == 'q'){ vSpeed=1000;} Serial.println(vSpeed); Serial.println(state); /***********************Forward****************************/ //If state is equal with letter 'F', car will go forward! if (state == 'F') { analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); analogWrite(motorB1, 0); analogWrite(motorB2, 0); } /**********************Forward Left************************/ //If state is equal with letter 'G', car will go forward left else if (state == 'G') { analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); analogWrite(motorB1, 200); analogWrite(motorB2, 0); } /**********************Forward Right************************/ //If state is equal with letter 'I', car will go forward right else if (state == 'I') { analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); analogWrite(motorB1, 0); analogWrite(motorB2, 200); } /***********************Backward****************************/ //If state is equal with letter 'B', car will go backward else if (state == 'B') { analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); analogWrite(motorB1, 0); analogWrite(motorB2, 0); } /**********************Backward Left************************/ //If state is equal with letter 'H', car will go backward left else if (state == 'H') { analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); analogWrite(motorB1, 200); analogWrite(motorB2, 0); } /**********************Backward Right************************/ //If state is equal with letter 'J', car will go backward right else if (state == 'J') { analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); analogWrite(motorB1, 0); analogWrite(motorB2, 200); } /***************************Left*****************************/ //If state is equal with letter 'L', wheels will turn left else if (state == 'L') { analogWrite(motorA1, 0); analogWrite(motorA2, 0); analogWrite(motorB1, 200); analogWrite(motorB2, 0); } /***************************Right*****************************/ //If state is equal with letter 'R', wheels will turn right else if (state == 'R') { analogWrite(motorA1, 0); analogWrite(motorA2, 0); analogWrite(motorB1, 0); analogWrite(motorB2, 200); } /************************Lights*****************************/ //If state is equal with letter 'W', turn leds on or of off else if (state == 'W') { if (i==0){ digitalWrite(lights, HIGH); i=1; }     else if (i==1){ digitalWrite(lights, LOW); i=0; }     state='n'; } /**********************Horn sound***************************/ //If state is equal with letter 'V', play (or stop) horn sound else if (state == 'V'){ if (j==0){ tone(buzzer, 1000);//Speaker on         j=1; }     else if (j==1){ noTone(buzzer);   //Speaker off j=0; }     state='n'; } /************************Stop*****************************/ //If state is equal with letter 'S', stop the car else if (state == 'S'){ analogWrite(motorA1, 0); analogWrite(motorA2, 0); analogWrite(motorB1, 0); analogWrite(motorB2, 0); } /***********************Battery*****************************/ currentMillis = millis;                              //Read battery voltage every 10sec. if(currentMillis - (previousMillis) > (interval)) { previousMillis = currentMillis; voltage = (analogRead(A0)*5.015 / 1024.0)*11.132;   //Read voltage from analog pin A0 and make calibration //Calculate percentage... perVolt = (voltage*100)/ maxBattery; if     (perVolt<=75)               { level=0; } else if (perVolt>75 && perVolt<=80) { level=1; }   //        Battery level else if (perVolt>80 && perVolt<=85) { level=2; }   //Min    Max else if (perVolt>85 && perVolt<=90) { level=3; }   //    | 0 | 1 | 2 | 3 | 4 | 5 | > else if (perVolt>90 && perVolt<=95) { level=4; }   // else if (perVolt>95)               { level=5; } Serial.println(level); } }

= Obstacle Avoiding Robot =



= Bluetooth Controlled RGB LED Strip = Source: arduino.cc,

Download the AndroidunoBt App from: play.google.com




 * Reading a serial ASCII-encoded string.

This sketch demonstrates the Serial parseInt function. It looks for an ASCII string of comma-separated values. It parses them into ints, and uses those to fade an RGB LED.

Circuit: Common-Cathode RGB LED wired like so: * Red anode: digital pin 3 * Green anode: digital pin 5 * Blue anode: digital pin 6

// pins for the LEDs: const int redPin = 3; const int greenPin = 5; const int bluePin = 6; void setup { // initialize serial: Serial.begin(9600); // make the pins outputs: pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); }

void loop { while (Serial.available > 0) { // look for the next valid integer in the incoming serial stream: int red = Serial.parseInt; // do it again: int green = Serial.parseInt; // do it again: int blue = Serial.parseInt;

// look for the newline. That's the end of your sentence: if (Serial.read == '\n') { // constrain the values to 0 - 255 and invert // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" red = constrain(red, 0, 255); green = constrain(green, 0, 255); blue = constrain(blue, 0, 255);

// fade the red, green, and blue legs of the LED: analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue);

// print the three numbers in one string as hexadecimal: Serial.print(red, HEX); Serial.print(green, HEX); Serial.println(blue, HEX); } } }

= IR Controlled RGB LED Strip = Source: [arduino-cool.blogspot.in]

#include 

int RECV_PIN = 8; int R_PIN = 10; int G_PIN = 6; int B_PIN = 9; unsigned long rgb = 0; byte r,g,b; IRrecv irrecv(RECV_PIN); decode_results results; void setup { irrecv.enableIRIn; // Inicializamos el receptor Serial.begin(9600); pinMode(R_PIN, OUTPUT); pinMode(G_PIN, OUTPUT); pinMode(B_PIN, OUTPUT); }
 * 1) define ON               0XFFB04F
 * 2) define OFF              0xFFF807
 * 3) define BRIGHTNESS_UP    0xFF906F
 * 4) define BRIGHTNESS_DOWN  0xFFB847
 * 5) define FLASH            0xFFB24D
 * 6) define STROBE           0xFF00FF
 * 7) define FADE             0xFF58A7
 * 8) define SMOOTH           0xFF30CF
 * 1) define RED              0xFF9867
 * 2) define GREEN            0XFFD827
 * 3) define BLUE             0xFF8877
 * 4) define WHITE            0xFFA857
 * 1) define ORANGE           0xFFE817
 * 2) define YELLOW_DARK      0xFF02FD
 * 3) define YELLOW_MEDIUM    0xFF50AF
 * 4) define YELLOW_LIGHT     0xFF38C7
 * 1) define GREEN_LIGHT      0XFF48B7
 * 2) define GREEN_BLUE1      0XFF32CD
 * 3) define GREEN_BLUE2      0XFF7887
 * 4) define GREEN_BLUE3      0XFF28D7
 * 1) define BLUE_RED         0XFF6897
 * 2) define PURPLE_DARK      0XFF20DF
 * 3) define PURPLE_LIGHT     0XFF708F
 * 4) define PINK             0XFFF00F
 * 1) define INCREMENTO 10

void variar (byte* color, char valor) { if (valor > 0) { if ( *color + valor <= 255) { *color += valor; } else { *color = 255; }   } else { if (*color + valor >= 0) { *color += valor; } else { *color = 0; } } } void RGB(unsigned long valor) { r = valor >> 16; g = (valor >> 8) & 0xFF; b = valor & 0xFF; } void loop { if (irrecv.decode(&results)) { if ( results.value != 0xFFFFFFFF) { switch (results.value) { case BRIGHTNESS_UP : variar (&r, INCREMENTO); variar (&g, INCREMENTO); variar (&b, INCREMENTO); break; case BRIGHTNESS_DOWN : variar (&r, -INCREMENTO); variar (&g, -INCREMENTO); variar (&b, -INCREMENTO); break; case OFF : r = g = b = 0; break; case RED          : RGB(0x00FF0000); break; case GREEN        : RGB(0x0000FF00); break; case BLUE         : RGB(0x000000FF); break; case WHITE        : RGB(0x00FFFFFF); break; case ORANGE       : RGB(0x00FF7F00); break; case YELLOW_DARK  : RGB(0x00FFAA00); break; case YELLOW_MEDIUM : RGB(0x00FFD400); break; case YELLOW_LIGHT : RGB(0x00FFFF00); break; case GREEN_LIGHT  : RGB(0x0000FFAA); break; case GREEN_BLUE1  : RGB(0x0000FFFF); break; case GREEN_BLUE2  : RGB(0x0000AAFF); break; case GREEN_BLUE3  : RGB(0x000055FF); break; case BLUE_RED     : RGB(0x00000080); break; case PURPLE_DARK  : RGB(0x003F0080); break; case PURPLE_LIGHT : RGB(0x007A00BF); break; case PINK         : RGB(0x00FF00FF); break; }     Serial.println(results.value, HEX); Serial.println(r,DEC); Serial.println(g, DEC); Serial.println(b, DEC); analogWrite(R_PIN,r); analogWrite(G_PIN,g); analogWrite(B_PIN,b); }   irrecv.resume; // Receive the next value } }

=Running Lights= http://www.14core.com/led-running-light-or-chasing-light-effect/

=Running Lights with Speed Control using Potentiometer=

Source: stackexchange.com



 // Sketch re: http://arduino.stackexchange.com/questions/19605/running-light-without-delay-and-a-potentiometer // Set constants for pins with LEDs enum { led1 = 13, led2 = 12, led3 = 11, led4 = 10, led5 = 9, led6 = 8, led7 = 7, led8 = 6, led9 = 5, led10 = 4};

// Make an array with the LED pin numbers byte ledPins[] = { led1, led2, led3, led4, led5, led6, led7, led8, led9, led10 };

// # of entries in ledPins: enum { numLeds = sizeof(ledPins) / sizeof ledPins[0]};

//count to track which LEDs are HIGH and which are LOW int count = numLeds-1;     // Will roll over to 0

// To store last time LED was updated unsigned long previousMillis = 0;

void setup { // initialize digital pin outputs for (byte i=0; i<numLeds; ++i) pinMode(ledPins[i], OUTPUT);

// initialize serial communication at 9600 bits per second: Serial.begin(9600); }

// loop runs over and over again forever: void loop { unsigned long currentMillis = millis; // read input on analog pin 0: int deli = analogRead(A0); float voltage = deli * (5.0 / 1023.0);

// Print out the value and corresponding voltage you read: // Serial.println("Value: %d and Voltage: %f", pause, voltage); Serial.print("Value: "); Serial.println(deli); Serial.print("Volts: "); Serial.println(voltage);

if (currentMillis - previousMillis >= deli) { // Save the last time we blinked the LED previousMillis = currentMillis;

// Turn off current LED, turn on next one digitalWrite(ledPins[count], LOW); count = (count+1) % numLeds; digitalWrite(ledPins[count], HIGH); } }

= LED Matrix Clock = https://123led.wordpress.com/mini-led-clock/