Serial Communication with Arduino

Last Updated on March 24, 2024

Here this project shows how to communicate with arduino serial terminal? For an application we have chosen four LEDs to indicate direction.




In a bread board four LEDs are placed in different direction and the Arduino sketch composed to control those LEDs with computer numeric key by pressing particular key we can get output.

This Arduino code can be modified to get desired input and output.

serial-communication-arduino

Circuit diagram

serial-communication-led-circuit

Arduino serial communication sketch code

//theorycircuit.com
//Serial communication to arduino board through key board to control direction Indicators
const int right = 12;
const int left = 9;
const int top = 10;
const int bottom = 11;
char data;

void setup() {
  Serial.begin(9600);
  pinMode(right, OUTPUT);
  pinMode(left, OUTPUT);
  pinMode(top, OUTPUT);
  pinMode(bottom, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    data = Serial.read();
    if (data == '1') {
      digitalWrite(left, HIGH);
      digitalWrite(right, LOW);
      digitalWrite(top, LOW);
      digitalWrite(bottom, LOW);
      Serial.println("Left Indicator activated");
    } else if (data == '2') {
      digitalWrite(left, LOW);
      digitalWrite(right, LOW);
      digitalWrite(top, HIGH);
      digitalWrite(bottom, LOW);
      Serial.println("Top Indicator activated");
    } else if (data == '3') {
      digitalWrite(left, LOW);
      digitalWrite(right, LOW);
      digitalWrite(top, LOW);
      digitalWrite(bottom, HIGH);
      Serial.println("Bottom Indicator activated");
    } else if (data == '4') {
      digitalWrite(left, LOW);
      digitalWrite(right, HIGH);
      digitalWrite(top, LOW);
      digitalWrite(bottom, LOW);
      Serial.println("Right Indicator activated");
    }
  }
}


Components List

S.NoNameQuantity
1.Arduino uno1
2.LED4
3.Resistor-220Ω4
4.Connecting wiresas required

Prototype

serial-communication

Screen shot

serial-shot




Leave a Reply

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