아두이노 6차시(릴레이, 블루투스, 실습)
2021. 6. 13. 23:42ㆍNEFUS_19/아두이노
#1 릴레이 모듈
릴레이 모듈은 낮은 전압으로 큰 전압을 제어 할수 있다.
일종의 자기장 성질을 이용햐여 막대 버튼을 움직여 전기가 흐른다.
아두이노 연결하는 곳의 반대쪽은
no, com, nc가 있다
nc는 아두이노가 신호를 주면 전기가 안통한다
no는 신호를 주면 전기가 통한다.
com은 항상 연결되어있는 공유 핀이다
아두이노 연결
vcc 5v
gnd : gnd
in : 디지털 핀
#2 불루투스 모듈
블루투스는 2.45GHz를 사용한다.
비교적 낮은 속도로 디지털 정보를 보낸다.
범위는 약 10m미터 정도 보낼수 있다.
vcc : 5v
gnd : gnd
TXD : 디지털 핀
RXD : 디지털 핀
#3 릴레이 모듈(실습)
int relay = 3;
#define cds A3
void setup() {
pinMode(relay, OUTPUT);
}
void loop() {
int a= analogRead(cds); //int a에 조도센서에서 읽은 값을 가져온다.
if(a>800) {
digitalWrite(relay, HIGH); //값이 800보다 커지면 relay 키기
delay(100); //0.1초 대기
} else{
digitalWrite(relay, LOW); //값이 800보다 작으면 relay 끄기
delay(100); //0.1초 대기
}
}
#4 블루투스
#include <SoftwareSerial.h>
#define BT_TXD 7
#define BT_RXD 8
SoftwareSerial bluetooth(BT_RXD,BT_TXD);
void setup() {
Serial.begin(9600); //시리얼 통신 시작
bluetooth.begin(9600); //블루투스 시작
}
void loop() {
if(bluetooth.available()){
Serial.write(bluetooth.read());
}
if(Serial.available()){
bletooth.write(Serial.read());
}
}
#5 lcd
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2);
void setup() {
lcd.init(); //lcd 키기
lcd.backlight(); //백라이트 키기 lcd.clear(); //lcd 초기화
}
void loop() {
int a = 0;
while(a<16) {
lcd.setCursor(a,0);
lcd.print("go");
lcd.setCursor(a, 1);
lcd.print("go");
if(a==15) {
lcd.setCursor(0,0);
lcd.print("o");
lcd.setCursor(0,1);
lcd.print("o");
}
delay(1000);
lcd.clear();
a++;
}
}
'NEFUS_19 > 아두이노' 카테고리의 다른 글
아두이노 AVRISP MK2(AVRISP MKII)를 이용하여 프로그램 업로드 (0) | 2024.09.13 |
---|---|
아두이노 7차시 (RTC, 아두이노 끼리 시리얼 통신); (0) | 2021.06.20 |
아두이노 5차시(서브 모터, 가변 저항, 12D lcd) (0) | 2021.06.07 |
아두이노 4-2차시(사운드 센서, 온습도 센서) (0) | 2021.06.06 |
아두이노 4-1차시 (문법정리, 세그먼트 배열, 시리얼 모니터) (0) | 2021.06.06 |