마지막으로 알아볼 녀석은 LCD1602 모듈입니다.




우선 datasheet를 먼저 보려고.. 했으나... ㅎㄷㄷ


http://www.elecrow.com/download/LCD1602.pdf



PIN map을 확인하여 arduino에 연결을 적절히(?) 해주세요. Ground를 특히 주의하셔야 합니다.


다행히 LCD library가 Arduino에서 제공되고 있어, Datasheet의 Initialization Sequence 정도 참고로 보시면 될듯합니다.





가난한 S/W 쟁이라 아무생각 없이 우선 cable들만 연결해서 동작이 되는지 확인해 보았습니다.



하지만 접지에 문제가 있는지 제대로 동작하지 않는 ㅠ.ㅠ

접지가 제대로 되지 않아 글자도 깨져 출력 되어 전원 인가된 상태만 확인하였습니다.

아래 사진에 하얀색으로 빵처럼 납작하게 생긴 판은 일명 빵판(bread-board)입니다.




결국 H/W 랩실에 들어가서 정상적으로 PIN head로 납땜을 해주었습니다.


S*-H사에서 갈고 닦은 납땜 실력으로 겨우 겨우 ^^:








/*

  LiquidCrystal Library - Hello World


 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal

 library works with all LCD displays that are compatible with the

 Hitachi HD44780 driver. There are many of them out there, and you

 can usually tell them by the 16-pin interface.


 This sketch prints "Hello World!" to the LCD

 and shows the time.


  The circuit:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 5

 * LCD D5 pin to digital pin 4

 * LCD D6 pin to digital pin 3

 * LCD D7 pin to digital pin 2

 * LCD R/W pin to ground

 * LCD VSS pin to ground

 * LCD VCC pin to 5V

 * 10K resistor:

 * ends to +5V and ground

 * wiper to LCD VO pin (pin 3)


 Library originally added 18 Apr 2008

 by David A. Mellis

 library modified 5 Jul 2009

 by Limor Fried (http://www.ladyada.net)

 example added 9 Jul 2009

 by Tom Igoe

 modified 22 Nov 2010

 by Tom Igoe


 This example code is in the public domain.


 http://www.arduino.cc/en/Tutorial/LiquidCrystal

 */


// include the library code:

#include <LiquidCrystal.h>


// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup() {

  // set up the LCD's number of columns and rows:

  lcd.begin(16, 2);

  // Print a message to the LCD.

  lcd.print("hello, world!");

}


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);

  // print the number of seconds since reset:

  lcd.print(millis() / 1000);

}


References :

https://www.arduino.cc/en/Tutorial/HelloWorld?from=Tutorial.LiquidCrystal

http://cafe.naver.com/mpucafe/2863

https://learn.adafruit.com/character-lcds/wiring-a-character-lcd

http://blog.naver.com/q19891204/220605172716

반응형

이번에 알아볼 센서는 거리를 측정할 수 있는 초음파 센서인 HC-SR04입니다.



상세 Datasheet는 아래 문서에서 확인 할 수 있습니다.

http://www.micropik.com/PDF/HCSR04.pdf


Specifications


           - Power Supply :+5V DC

           - Quiescent Current : <2mA

           - Working Currnt: 15mA

           - Effectual Angle: <15°

           - Ranging Distance : 2cm – 400 cm/1" - 13ft

           - Resolution : 0.3 cm

           - Measuring Angle: 30 degree

           - Trigger Input Pulse width: 10uS

           - Dimension: 45mm x 20mm x 15mm


Pins

  • VCC: +5VDC
  • Trig : Trigger (INPUT)
  • Echo: Echo (OUTPUT)
  • GND: GND



앞선 포스트들을 보셨다면 이제 시그널들에 조금 익숙해 지셨을 텐데요.

아래 diagram을 보면 10us동안 HIGH를 INPUT으로 넣어주면, 센서 내부에서 8개의 40kHz의 시그널을 송출합니다. 

그리고 반사된 신호가 들어오면 그 시간동안 OUTPUT pin을 High로 올려주게 됩니다.




예제 코드를 돌려보면... 잘 동작하네요 ^^::






/*      sedew810225@gmail.com

 *      Ultrasonic sensor Pins:        

 *      VCC: +5VDC        

 *      Trig : Trigger (INPUT) - Pin 4       

 *      Echo: Echo (OUTPUT) - Pin 5       

 *      GND: GND

 */


unsigned int trigPin = 4;

unsigned int echoPin = 5;

long duration, cm, inches;


void setup() {

  Serial.begin (9600);


  pinMode(trigPin, OUTPUT);

  pinMode(echoPin, INPUT);

}


void loop() {

  // start by a High pulse of 10 microseconds

   digitalWrite(trigPin, LOW);

  delayMicroseconds(5);

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);


  //read data from echoPIN for the duration of HIGH signal

  pinMode(echoPin, INPUT);

  duration = pulseIn(echoPin, HIGH);


  //convert time to distance

  cm = (duration/2) / 29.1;

  inches = (duration/2) / 74; 


  Serial.print(inches);

  Serial.print("in, ");

  Serial.print(cm);

  Serial.print("cm");

  Serial.println();

  

  delay(250);

}


References :

http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/

http://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/

https://www.arduino.cc/en/Reference/PulseIn

반응형

'TinyProjects' 카테고리의 다른 글

Beautiful KiWi with Python and OpenCV  (0) 2016.03.17
LCD1602 모듈과 아두이노  (0) 2016.03.13
SEN0018 적외선 감지 센서  (0) 2016.03.10
DHT-11 Sensor 아두이노 테스트  (13) 2016.03.10
ARDUINO/GENUINO 개발 환경 세팅하기  (0) 2016.03.10

+ Recent posts