Leesounghoongledel
Published © GPL3+

Arduino (3) (FabLab)

I learned how to use the LCD display and ultrasonic sensor. And I made code to use them.

BeginnerProtip1 hour752
Arduino (3) (FabLab)

Things used in this project

Story

Read more

Schematics

control LCD

this code is that it increases by 1 every second

control LCD by use the Ultra Sonic Sensor

this code is that output the value of the Ultra Sonic Sensor and If value is less than 10, blink the LED.

Code

control LCD

Arduino
this code is that It increases by 1 every second
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 =4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6,d7);
void setup(){
  lcd.begin(16, 2);
  lcd.print("hellow, world");
  delay(2000);
  lcd.clear();
}
void loop(){
  lcd.setCursor(0,0);
  lcd.print("time : ");
  lcd.print(millis() / 1000);
  char second = 's';
  lcd.print(second);
}

control LCD by use the Ultra Sonic Sensor

Arduino
this code is that output the value of the Ultra Sonic Sensor and If value is less than 10, blink the LED.
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int trigPin = 9;
int echoPin = 8;
long distance;
long duration;

void setup() {
lcd.begin(16, 2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(13, OUTPUT);
}

void loop() {

   if(distance <=10){
    digitalWrite(13, HIGH);
  }
    digitalWrite(13, LOW);
  ultra();
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("UltraSonic");

  lcd.setCursor(0,1);
  lcd.print("distance : ");
  lcd.print(distance);
  lcd.print("cm");
  delay(200);
  
  if(distance <= 10){
    digitalWrite(13, HIGH);
    delay(500);
    digitalWrite(13, LOW);
  }
   if(distance > 10){
    digitalWrite(13, LOW);
   }
 
}

void ultra(){
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance= duration*0.034/2;
}

Credits

Leesounghoon
9 projects • 4 followers
Hi my name is sung hoon lee. I`m a student at Bongilcheon High School. I want to learn 3D Printing and how to use arduino code(+python code)
gledel
100 projects • 117 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"

Comments