답변 : 아두이노 rf433 + 스위치 내부 풀업저항 질문
페이지 정보
작성자 master 작성일19-01-06 18:35 조회5,679회 댓글1건본문
//
rf433을 이용하여 송신기쪽에 전원이 들어오면 수신기쪽에서 릴레이를 통해 전기가 통할 수 있게 하고 싶은데
성공은 하였으나 전원이 들어오고 나서 송신기쪽에서 전원이 꺼져도 계속 릴레이에 전원이 들어오는데
이부분을 수정하고자 이렇게 도움을 청하게 되었습니다.
그리고 송신기 쪽에 스위치를 달려고 하는데 내부 저항을 이용하여 하고 싶은데 스케치를 어떻게 수정하면 될 지 도움을 청하고 싶습니다.
//---------------------------------송신기
#include <VirtualWire.h>
const int TX_DIO_Pin=6; // default 6
//
void setup(){
vw_set_tx_pin(TX_DIO_Pin); // Initialize TX pin
vw_setup(2000); // Transfer speed: 2000 bits per sec
pinMode(2,INPUT_PULLUP); // 2번핀에 스위치 연결, 내부 풀업저항 사용
}
//
void loop(){
if(digitalRead(2))send("0"); // 스위치 OFF면 진동모터 OFF
else send("1"); // 스위치 ON이면 진동모터 ON
delay(500); // 0.5초마다 전송
}
//
void send(char *message){
vw_send((uint8_t*)message,strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}
//---------------------------------수신기
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength=VW_MAX_MESSAGE_LEN; // the size of the message
const int RX_DIO_Pin=8; // default8
int relay=12;
//
int i;
long time;
//
void setup(){
pinMode(relay,OUTPUT); // 진동모터
Serial.begin(9600);
Serial.println("Ready to receive: ");
vw_set_rx_pin(RX_DIO_Pin); // Initialize RX pin
vw_setup(2000); // Transfer speed: 2000 bits per sec
vw_rx_start(); // Start the receiver
time=millis();
}
//
void loop(){
if(vw_get_message(message,&messageLength)){ // Non-blocking
Serial.print("Received: ");
for(i=0; i<messageLength; i++)Serial.write(message[i]);
Serial.println();
if(message[0]=='1')digitalWrite(relay,HIGH); // '1'이면 Relay ON
if(message[0]=='0')digitalWrite(relay,LOW ); // '0'이면 Relay OFF
time=millis(); // 수신받은 시간 저장
}
}
댓글 : 1
조회수 : 5,679
A반장님의 댓글
A반장 작성일
스위치를 계속 눌러야 되네요ㅠㅠㅠ
제가 말씀드린건 한번누르면 켜지고 다시한번 누르면 꺼지는 형식이였어요..ㅠㅠ