Introduction: Control LED Using Serial Monitor

Picture of Control LED Using Serial Monitor

Hello everyone welcome to my first instructable.

In this instructables we are going to learn how to turn LEDs on and off using serial monitor.

Step 1: Gather the Parts

Picture of Gather the Parts

  • A breadboard
  • A LED
  • A 220 ohm resistor
  • An Arduino

Step 2: The Code

Picture of The Code

Upload the following code to your arduino:

void setup()

{

pinMode(13, OUTPUT);

Serial.begin(9600);

while (!Serial);

Serial.println("Input 1 to Turn LED on and 2 to off");

}

void loop() {

if (Serial.available())

{

int state = Serial.parseInt();

if (state == 1)

{

digitalWrite(13, HIGH);

Serial.println("Command completed LED turned ON");

}

if (state == 2)

{

digitalWrite(13, LOW);

Serial.println("Command completed LED turned OFF");

}

}

}

Step 3: Wiring

Picture of Wiring

Hookup all the components according to the circuit diagram above.

Step 4: Done

Picture of Done

Now just connect the arduino to your PC now open the serial monitor (To do so navigate through tools>Serial monitor).

Now when you send 1 the LED turns on and turns off when you send 2.

Thanks for viewing. Please write your questions or suggestions below.

Comments

DIY Hacks and How Tos (author)2016-07-01

Great intro to Arduino tutorial

Thanks.

khurram125 (author)Anshu AR2017-03-23

good job boy

About This Instructable

3,465views

6favorites

License:

Bio: So, I got a bunch of LEDs when I was 8 or 9 something.
More by Anshu AR:Scratch Built RC AirplaneH Bridge Motor Driver For Arduino Using TransistorsHow To Use A Piezo To Produce Tone : Basics
Add instructable to: