Day 3 RGB LED , Seven Segment, Relay Module

Arudino Tutorial Day 3

1) Control 3v RGB LED using Switch

2) Control 12 v RGB LED strip using Arudino

3) Generate Multi color on 12 volt RGB strip

4) Seven segment digit Counter

5) Control 7 segment using push button

6) Tp223 capacitive Touch switch

7) Control Relay using Arduino,

8) Control 220 volt Bulb using touch switch


How to Control RGB LED using Arduino


int RedLED=11;

int BlueLED=10;

int GreenLED=9;


void setup() {


  pinMode(RedLED, OUTPUT);

  pinMode(BlueLED, OUTPUT);

  pinMode(GreenLED, OUTPUT);

}

void loop() {

  digitalWrite(RedLED, HIGH); 

  delay(1000);                

  digitalWrite(RedLED, LOW);  

  delay(1000);     

  digitalWrite(GreenLED, HIGH); 

  delay(1000);                

  digitalWrite(GreenLED, LOW);  

  delay(1000); 

  digitalWrite(BlueLED, HIGH); 

  delay(1000);                

  digitalWrite(BlueLED, LOW);  

  delay(1000); 

}



int LEDred=11;
int LEDblue=10;
int LEDgreen=9;

int btn=2;
int mode=0;

void setup()

{
  pinMode(LEDred, OUTPUT);
  pinMode(LEDblue, OUTPUT);
  pinMode(LEDgreen, OUTPUT);
  pinMode(btn,INPUT);
  Serial.begin(9600);
}

void loop()

{

  byte sw=digitalRead(btn);

  if (sw==0){ mode=mode+1; delay(1000); Serial.println(mode);}

  if (mode==1){digitalWrite(LEDred, HIGH); delay(500);}
  if (mode==2){digitalWrite(LEDred, LOW); delay(500);}
  if (mode==3){digitalWrite(LEDblue, HIGH); delay(500);}
  if (mode==4){digitalWrite(LEDblue, LOW); delay(500);}
  if (mode==5){digitalWrite(LEDgreen, HIGH); delay(500);}
  if (mode==6){digitalWrite(LEDgreen, LOW); delay(500);}
}

------------------------------------------------------------------------
RGB LED with 3 Push button

const int buttonRedPin = 2;  // the number of the pushbutton pin
const int buttonGreenPin = 3;
const int buttonBluePin = 4;

const int ledRedPin = 14;
const int ledGreenPin = 15;
const int ledBluePin = 16;


// variables will change:
int buttonRedState = 0;  // variable for reading the pushbutton status
int buttonGreenState = 0;
int buttonBlueState = 0;

void setup() {
 
  pinMode(ledRedPin, OUTPUT);
  pinMode(ledGreenPin, OUTPUT);
  pinMode(ledBluePin, OUTPUT);

  pinMode(buttonRedPin, INPUT);
  pinMode(buttonGreenPin, INPUT);
  pinMode(buttonBluePin, INPUT);

  digitalWrite(buttonRedPin,HIGH);
  digitalWrite(buttonGreenPin,HIGH);
  digitalWrite(buttonBluePin,HIGH);
}

void loop() {

 byte sw1 = digitalRead(buttonRedPin);
  byte sw2 = digitalRead(buttonGreenPin);
   byte sw3 = digitalRead(buttonBluePin);

  if (sw1 == LOW) { buttonRedState=!buttonRedState;digitalWrite(ledRedPin, buttonRedState); delay(500);}
  if (sw2 == LOW) { buttonGreenState=!buttonGreenState;digitalWrite(ledGreenPin, buttonGreenState); delay(500);}
  if (sw3 == LOW) { buttonBlueState=!buttonBlueState;digitalWrite(ledBluePin, buttonBlueState); delay(500);}
 
}

--------------------------------------------------------------------------------------------------------

Ardiuno 1 digit Seven segment driver


-----------------------------------------------------------------------------------------------------------------

Seven segment driving using 2 push button 

int x=0;

int segA = 2; //Display pin A
int segB = 3; //Display pin b
int segC = 4; //Display pin c
int segD = 5; //Display pin d
int segE = 6; //Display pin e
int segF = 7; //Display pin f
int segG = 8; //Display pin g

byte SW0 = A0;
byte SW1 = A1;

void setup() {
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);

Serial.begin(9600);

  pinMode(SW0, INPUT);  
  pinMode(SW1, INPUT);  

  digitalWrite(SW0, HIGH);
  digitalWrite(SW1, HIGH);
}

void loop() {

  int plus=digitalRead(SW0);
  int minus=digitalRead(SW1);
 
  if (plus==LOW){x=x+1;  delay(200);}
  if (minus==LOW){x=x-1; delay(200);}
 
 lightNumber(x);
 delay(100);
}

void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  }}

--------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------------------------------


---------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------


No comments:

Post a Comment

Arduion Uno pin out