http://labdegaragem.com/profiles/blogs/como-utilizar-os-modulos-rf-link-315mhz-434mhz
https://www.pjrc.com/teensy/td_libs_VirtualWire.html
Lista de Materiais:
IDE Arduino 1.0.6
1x Board Arduino UNO
1x Board Arduino NANO
2x Protoboard 830 furos
1x Cabo USB-A male to USB-B male
1x Cabo USB-A male to USB-Mini male
1x Conj. de fios jumper p/ protoboard
1x Módulo receptor 434MHz
1x Módulo transmissor 434MHz
2x Antena telescópica
4x Push Button
4x Led vermelho
4x Resistor 220R 1/4w
4x Resistor 10k 1/4w
Montagem:
Firmware:
RF Transmitter
#include <VirtualWire.h>
char *nibble = "0000";
int le_pino;
void setup(){
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(2);
for(int i=3; i<=6; i++){
pinMode(i, INPUT_PULLUP);
}
}
void loop(){
int j=0;
for(int i=3;i<=6;i++,j++){
le_pino = digitalRead(i);
if(le_pino == 1){
while(le_pino == 1) le_pino = digitalRead(i);
nibble[j] = '1';
}
else nibble[j] = '0';
}
vw_send((uint8_t *)nibble, strlen(nibble));
vw_wait_tx();
}
RF Receiver
#include <VirtualWire.h>
void setup(){
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(2);
vw_rx_start();
for(int i=3;i<=6;i++){
pinMode(i, OUTPUT);
}
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)){
int j=3;
for (int i = 0; i < buflen; i++,j++){
buf[i] = buf[i] - 48;
if(buf[i] == 1){
digitalWrite(j,!digitalRead(j));
}
}
}
}
Download: VirtualWire.h
Nenhum comentário:
Postar um comentário