답변 : 아두이노 RF 통신
페이지 정보
작성자 master 작성일18-06-08 09:08 조회4,291회 댓글0건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-08 오전 9:10:53
// by Ok-Hyun Park
//
스위치 두개의 값을 입력받아 safe 변수가 결정되고
safe 변수를 RF통신으로 내보낸다.
//
1.먼저 송신하는 스위치 센서부분
//
// 파워레벨,가까우면 최소 // RF24_PA_MIN/RF24_PA_LOW/RF24_PA_HIGH/RF24_PA_MAX
//
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); // SPI,CE,CSN
char address[6]="12345"; // 5문자열,송신기와 수신기 동일한 주소
char safe;
//
void setup(){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address); radio.setPALevel(RF24_PA_LOW);
radio.stopListening(); // 송신기로 설정
}
//
void loop(){
int right=digitalRead(3);
int left=digitalRead(4);
if(right&&left){ safe=1; Serial.println("DANGER"); }
else { safe=0; Serial.println("SAFE"); }
radio.write(&safe,sizeof(safe));
delay(100);
}
//
2.수신하는 솔레노이드 작동부분(릴레이 이용)
받은 safe 변수로 릴레이를 작동 정지 시킨다.
//
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); // SPI,CE,CSN
char address[6]="12345"; // 송신기 수신기 동일한 주소
char safe;
//
void setup(){
pinMode(10,OUTPUT); // 릴레이
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,address); radio.setPALevel(RF24_PA_HIGH);
radio.startListening(); // 수신기로 설정
}
//
void loop(){
if(radio.available()){
radio.read(&safe,sizeof(safe));
if(safe==1){ Serial.println("BRAKE"); digitalWrite(10,HIGH); }
else { Serial.println("MOVE"); digitalWrite(10,LOW ); }
}
}
동작시켜보고 문제가 있을 때 질문해주세요
댓글 : 0
조회수 : 4,291
등록된 댓글이 없습니다.