Tuesday, May 28, 2019

Arduino Serial Data LED Control

Arduino Serial Data LED Control

Arduino is great platform for prototyping and commercial projects.its even worthy because it support easy serial communication between PC and Arduino Board.this capability can be used to communication between PC Desktop Application and a Arduino Board Control.

Here's a small Sketch that read serial data and do stuff accordingly.



byte LED = 13;

void setup() {
  Serial.begin(9600);
  delay(100);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (Serial.available()) {
    char inChar = (char)Serial.read();
    if (inChar == '\r' || inChar == '\n') {
    } else {
      if (inChar == '1') {
        digitalWrite(LED, HIGH);
      } else {
        digitalWrite(LED, LOW);
      }
    }
  }
}

When  character 1 is written to the serial data stream, the led connected to the pin 13 will light up.
any other character will turn it off.

in action : https://youtu.be/6N7fr1qJ5oA

github : https://github.com/stark9000/Arduino-Serial-Data-LED-Control



No comments:

Post a Comment