Serial Output from Arduino Uno Board

Serial Output from Arduino Uno Board

Below code does the following:

  • Read the analog input over A5 pin
  • Output the read value to 16x2 LCD
  • Output the data on serial port @ baud of 9600

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int potValue = 0;

void setup() {   
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hi 4m Way2Know");

  Serial.begin(9600);
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  potValue = analogRead(A5);
  lcd.print(potValue);
  
  Serial.print(potValue); //default baud of 9600
  Serial.println(); //prints a carriage return

  delay(500);

  lcd.clear();
  lcd.print("Hi 4m Way2Know");
}

Serial output:



Get the explanation of the code from below video:

Post a Comment

0 Comments