Control LED Using Serial Monitor

Posted on
Control Led Using Serial
Ilustration by Pixabay

Control A LED From Serial Monitor

How to Control Led Using Serial Monitor – Arduino Uno has several advantages, one of which is that we can communicate using a serial monitor.

This time we will learn to use the Arduino Serial Monitor to give orders to Arduino to turn on an LED and currently we don’t need an External LED but we use the internal LED on the Arduino. This LED is connected to pin 13.

Please enter the following code and upload it to your Arduino.

Basic Code

int led = 13;
char  i;

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    i = Serial.read();
    Serial.println(i);

    if (i == '1') {
      digitalWrite(led, HIGH);
      delay(10);
    }

    else if (i == '0'){
      digitalWrite(led, LOW);
      delay(10);
    }
  }
}

Now, open the serial monitor, type the number 1 then send. Then type the number 0 and send.

You can see the difference on the board. I hope this article is useful.

Leave a Reply

Your email address will not be published.