BASIC4MCU | 질문게시판 | 도와주세요!!!!ㅜㅜ
페이지 정보
작성자 A반장 작성일2019-01-06 17:54 조회2,968회 댓글0건본문
안녕하세요ㅠ 도움을 청하고자 이렇게 올립니다.
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
}
//
void loop(){
//send("0"); delay(1000); // 진동모터 OFF
send("1"); delay(1000); // 진동모터 ON
}
//
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();
digitalWrite(relay,HIGH);
time=millis(); // 수신받은 시간 저장
}
}
댓글 0
조회수 2,968등록된 댓글이 없습니다.