Arduino lesson 003 Adding User Input to The LED

coolyou1A.I., Arduino, DIY, Future Computing Technology, Robotics, Tutorial

Today we are going to have a user input. Today we will be using a button in order to turn ON and OFF an LED. I will include the instruction on how to accomplish this feat. I will include the visual schematics of parts. I will include pictures of required materials. I will also include a challenge section. The only prerequisite is that you read my previous tutorials.

 

Today we are going to need the following

20130924_223014[1]

1. Arduino UNO

2. LED

3. 2 10K Resisters

4. Button

5. Wires

6. USBA to USBB cable

You can find all of these things in the Arduino Uno Ultimate Starter Kit.

First: (Read first tutorial)

Second: ( Rearranging)

 

The only thing we need to do now is place the button on the bread board

 

Wire one: 13 Arduino to 17F

Wire Two: GND to 17K

Resister: 21J to 19K

Button CNT: J17, 19; K17 19

20130925_174108[1]

Step three: delete previous code and add this

Code

int switchPin = 8;

int ledPin = 13;

 

void setup()

{

pinMode(switchPin, INPUT);

pinMode(ledPin,OUTPUT);

}

 

void loop()

{

if (digitalRead(switchPin) == HIGH)

{

digitalWrite(ledPin, HIGH);

}

else

{

digitalWrite(ledPin, LOW);

}

 

The challenge: See if you can have a digital LED count. Meaning when one LED is on the other is off. Allow the button to be the switch between the two LED’s