본문 바로가기
만들기/아두이노

아두이노 LCD와 스텝모터 사용하기

by 훨훨날아 2022. 11. 16.

LCD 연결

https://kyoungin90.tistory.com/469

 

1602A LCD 디스플레이 가변저항 표시하기

아두이노에서 표시되는 데이터를 컴퓨터의 시리얼 통신으로 보지않고 외부 디스플레이를 이용하게 위해 다양한 방법을 이용할 수 있다. 그중 1602A LCD 디스플레이를 이용하면 I2C 통신을 이용하

kyoungin90.tistory.com

 

스텝모터 연결

https://gent.tistory.com/70

 

[Arduino|아두이노] 스텝모터 (28BYJ-48) 구동하기 (ULN2003 드라이브)

아두이노 스텝모터 (28BYJ-48) 구동하기 아래의 스텝모터는 인터넷에서 쉽게 구할 수 있으며 스텝모터(28BYJ-48)와 모터 드라이브(ULN2003)가 함께 판매되고 있다.아래의 예제는 모터가 한바퀴 회전하

gent.tistory.com

 

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LCD

#include <Stepper.h>      // 스테핑 모터 라이브러리 정의 

int stepsPerRev = 2048; // 한바퀴(360): 2048 , 반 바퀴(180) : 1024
int rpm = 0;
Stepper stepper (stepsPerRev, 11,9,10,8); // ( IN4,IN2,IN3,IN1)  스텝모터 연결


LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
// 연결 SDA = A4, SL = A5

void setup() 
{
  Serial.begin(9600);
  
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
  lcd.setCursor(0,1);
  lcd.print("Ready");
  stepper.setSpeed(rpm);   // 스텝모터의 스피드 설정
  lcd.init();
}


void loop()
{
    
  
  stepper.step(stepsPerRev);  // 한 바퀴 회전 명령
  
  lcd.setCursor(0,0);
  lcd.print("Current RPM");
  
  lcd.setCursor(0,1);
  lcd.print(rpm);
  Serial.println(rpm);
  
  
  
}

 

 

반응형