리모컨으로 음악 재생 제어하기: 심플한 아두이노 프로젝트
부품 및 소모품
| 부품 | 수량 |
| 아두이노 우노 (Arduino UNO) | 1 |
| 리모컨 (Remote control) | 1 |
| IR 수신기 (Generic) | 1 |
| 부저 (Buzzer) | 1 |
| Adafruit 표준 LCD - 16x2 화이트 온 블루 | 1 |
| 로터리 포텐셔미터 (Generic) | 1 |
| 저항 221옴 | 1 |
앱 및 온라인 서비스
프로젝트 소개
안녕하세요, Hackster 커뮤니티 여러분! 저는 Simone Adobs이며, 이 사이트에 두 번째로 공개하는 프로젝트입니다.
프로젝트 로직
이 프로젝트의 로직은 매우 간단합니다:
- 리모컨에서 원하는 멜로디를 선택합니다.
- 아두이노와 부저가 해당 멜로디를 재생합니다.
- LCD 화면에 재생 중인 음계가 표시됩니다.
코드 설명
모든 멜로디는 다음과 같은 방식으로 작성됩니다:
void melody_example() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Song title");
delay(1000);
lcd.clear();
nota_mi(duration, pause); // 음계
nota_do(duration, pause); // 음계
lcd.clear();
delay(100);
Reset_AVR(); // 버튼 없이 아두이노 리셋
}
Reset_AVR() 명령을 사용하려면 스케치 최상단에 다음 코드를 추가해야 합니다:
#include <avr/io.h>
#include <avr/wdt.h>
#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}
아두이노가 어떤 멜로디를 재생할지 판단하는 방식:
if (result == 12495) { // 버튼 1을 눌렀을 때 리모컨이 보내는 코드
melody_1();
} else if (result == 6375) { // 버튼 2
melody_2();
} else if (result == 31365) { // 버튼 3
melody_3();
} else if (result == 4335) { // 버튼 4
melody_4();
}
각 음계를 재생하는 함수 예시:
void nota_example(int duration, int pause) {
shut(); // 아래에서 설명할 함수 호출
lcd.setCursor(0, 0);
lcd.print("Example "); // 음계 이름 출력
NewTone(11, 262, duration); // 11번 핀(부저), 262Hz(도)
delay(pause);
}
연주 중인 멜로디를 멈추고 싶다면?
shut() 함수 덕분에 언제든 멜로디를 멈출 수 있습니다.
void shut() {
if (irrecv.decode(&results)) {
result = results.value, HEX;
Serial.println(result);
if (result == -23971) { // 내 리모컨의 전원 버튼
Reset_AVR(); // 아두이노 리셋
}
}
irrecv.resume(); // 다음 리모컨 신호 수신 대기
}
이 프로젝트가 마음에 드셨기를 바랍니다. 제 이전 프로젝트도 한번 살펴봐 주세요.
좋은 하루 되세요..
이탈리아에서 Simone <3
코드
Play Melody (C/C++)
아래 코드를 아두이노 IDE에 복사하세요:
#include <LiquidCrystal.h>
#include <IRremote.h>
#include <NewTone.h>
#include <avr/io.h>
#include <avr/wdt.h>
#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}
#define buzzer 11
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
int result;
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("-----Choose-----");
lcd.setCursor(0, 1);
lcd.print("----A Song!!----");
pinMode(buzzer, OUTPUT);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
result = results.value, HEX;
Serial.println(result);
if (result == 12495) { ode(); }
else if (result == 6375) { london(); }
else if (result == 31365) { fur(); }
else if (result == 4335) { pirate(); }
irrecv.resume();
}
delay(100);
}
// 각 멜로디 함수들 (fur, london, ode, pirate)은 생략 - 원본 참조
void shut() {
if (irrecv.decode(&results)) {
result = results.value, HEX;
Serial.println(result);
if (result == -23971) { Reset_AVR(); }
}
irrecv.resume();
}
// 음계별 함수들 (nota_do, nota_re, nota_mi 등) - 원본 참조
회로도
Fritzing 회로도 파일: canzoni_con_tastiera_fQS3978roa.fzz