Arduino Beginner Series: Project 15: Using a slidy switch

Hello everyone!! Welcome to this post on Arduino LED Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE

So here I’ve just used a SPDT (like a slidy switch) switch to switch between turning a yellow or blue LED on.

Demo:

So here’s what this super simple project looks like:

Things Required:

  1. Arduino UNO
  2. Breadboard
  3. Jumper Wires
  4. SPDT Switch
  5. LEDs (x2)
  6. 100 ohm resistors (x2)
  7. Arduino IDE on computer

Functions used:

  1. digitalWrite()
  2. digitalRead()
  3. pinMode()

Reference Material:

Here (LINK) you can learn both about SPDT switches and the project.

Code:

View on/ Download from Github: (LINK)

int spdt=3;
int blueled=12;
int yellowled=11;
int switch_val;

void setup() {
  // put your setup code here, to run once:
  pinMode(spdt, INPUT);
  pinMode(blueled, OUTPUT);
  pinMode(yellowled, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  switch_val= digitalRead(spdt);

  if(switch_val==1){
    digitalWrite(blueled, LOW);
    digitalWrite(yellowled, HIGH);
  } else {
    digitalWrite(blueled, HIGH);
    digitalWrite(yellowled, LOW);
  }

}

Stay Tuned for upcoming posts on Arduino Projects! We’re on the basic newbie projects right now and slowly, gradually move on to those cool, ultra techy projects!! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

This image has an empty alt attribute; its file name is stay-tuned.gif

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close