Friday, March 22, 2013

8*2 LCD & Arduino with Direct Serial Monitor

Connect a 8*2 LCD with Arduino. In Bangladesh NORduino Uno a clone of Arduino Uno is available at www.fb.com/OishiElectronicsSylhet . Then upload Following Code . Open Serial Monitor and Make Fun.
#include <LiquidCrystal.h>
//www.fb.com/OishiElectronicsSylhet
// Robi Kormokar (SUST Physics)
//www.fb.com/Nabilphysics(SUST Physics)
//Circuit : Connect a 8*2 LCD and Open Serial Monitor.Simply Type and See in LCD
LiquidCrystal lcd(2, 5, 6, 7, 9, 10);

char arr[16];
int j = 0;
int k = 0;

void setup() {
  Serial.begin(9600);
  lcd.begin(8, 2);
}

void loop() {

  if(Serial.available() > 0) {
    if(k == 0) {
      lcd.clear();
      k = 1;
    }
   
    if(j < 8) {
      arr[j] = Serial.read();
      lcd.setCursor(j, 0);
    }
    else if (j >= 8) {
      arr[j] = Serial.read();
      lcd.setCursor((j-8), 1);
    }
    lcd.print(arr[j]);
    j = j + 1;
  }
  delay(100);
  if(Serial.available() <= 0) {
   j = 0;
   k = 0;
  }
}

No comments:

Post a Comment