Sabtu, 23 April 2016

RF 433 Push Button Led

RF 433 PUSH BUTTON LED
VIA ARDUINO 

Salam elektro,berjumpa lagi dengan aruselektronika,apa kalian pernah komunikasi data melalui kabel ? nah jika sudah pernah,rf ini tidak jauh cara kerjanya seperti itu,yang membedakan komunikasi rf yaitu melalui radio frekuensi yaitu 315 MHZ,330MHZ,433MHZ,komunikasi tersebut terjadi karena adanya module RX dan TX,rf module dapat berkomunikasi sejauh 100m,tanpa halangan dinding,tegangan yang dipakai untuk rx tx module 5v,untuk spesifikasi yang lainnya bisa kalian baca disini,nah pada tutorial kali ini,aruselektronika akan mencoba module tersebut dengan menggunakan 2 board arduino,untuk penjelasannya silahkan kalian simak.

TOLONG BACA DENGAN DETAIL !

Siapkan alat dan bahan :
  • Arduino Uno/Nano/Mega (sama saja)  (untuk module RX)
  • Arduino Uno/Nano/Mega (sama saja)  (untuk module TX)
  • RF module RX & TX
  • Breadboard 
  • Kabel jumper disesuaikan
  • Led (bebas)
  • Resistor 220 ohm
  • Push button (bebas)
  • Laptop
  • Software arduino ide
  • Kabel usb
  • Download Library <VirtualWire.h> (tutorial instal library klik disini)
  • Download skematik pdf
1. Sambungkan board arduino & module RF (radio frekuensi)

                           
CATATAN !
a. Sambungan pin RX TX module ke board arduino bisa kalian ganti contoh vw_set_tx_pin(12); pin 12 bisa kalian ganti 
b. Perhatikan sambungan pin data vcc gnd pada module rf 
c. Arduino 1 untuk transmiter,arduino 2 untk receiver

2. Copy paste satu persatu sketch/program di bawah ini  ke dalam software arduino 


Code untuk transmiter !
/*
 * RF Transmiter
 * By Fickry Muhammad 
 */
#include 
const char *message = "aruselektronika.blogspot.co.id";
int on = 2;
int off = 3;
int led = 13;


void setup() {
pinMode(on,INPUT_PULLUP);
pinMode(off,INPUT_PULLUP);
pinMode(led,OUTPUT);

vw_set_ptt_inverted(true); 
vw_set_tx_pin(12); 
vw_setup(4000);
}

void loop(){
  
  if (!digitalRead(on))
  {  
  message="X";
  digitalWrite(led,HIGH);
  vw_send((uint8_t *)message, strlen(message)); 
  vw_wait_tx(); 
  delay(100);
  }
  else
  {
  digitalWrite(led,LOW);  
  }

  if (!digitalRead(off))
  {  
  message="A";
  digitalWrite(led,HIGH);
  vw_send((uint8_t *)message, strlen(message)); 
  vw_wait_tx(); 
  delay(100);
  }
  else
  {
  digitalWrite(led,LOW);  
  }
}
Code untuk receiver
/*
 * RF Receivier
 * By Fickry Muhammad 
 */
#include 
int led = 13;     
void setup()
{
  pinMode(led,OUTPUT);
  vw_set_ptt_inverted(true);
  vw_set_rx_pin(12); 
  vw_setup(4000);  
  vw_rx_start();       
}
void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN]; 
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) 
  { 
    if(buf[0]=='X')
    {  
    digitalWrite(led,HIGH);
    }  
    if(buf[0]!='X' || buf[0]=='A')
    {
    digitalWrite(led,LOW);
    }
  }
}

3. Verify program arduino,apabila tidak terjadi error lanjut dengan proses upload

4. Upload program satu persatu ke masing masing board arduino,seperti biasa atur terlebih dahulu port,board yang kalian gunakan,apabila succes akan muncul tulisan done uploading,apabila ada yang belum tahu bagaimana cara upload code/sketch ke board arduino bisa baca disini

5. Sekarang kalian coba tekan tombol push button pada module arduino RF TX dan coba kalian lihat led pada module arduino RF RX,jika led nyala maka module rf kalian sudah benar benar berfunIgsi,tinggal kalian kembangkan untuk aplikasi lain,contohnya monitoring data dari jarak jauh

RECOMMENDATION UNTUK MENGGUNAKAN RF PT4304
Fungsi lebih stabil,jangkauan lebih luas


FUNGSI-FUNGSI DARI LIBRARY 

Configuration Functions

vw_set_tx_pin(transmit_pin)
Configure the transmit pin. Default is pin 12. Blah
vw_set_rx_pin(receive_pin)
Configure the receive pin, Default is pin 11. On Teensy 2.0, pin 11 should not be used because most receiver modules can not work correctly with the orange LED on that pin.
vw_set_ptt_pin(transmit_en_pin)
Configure the transmit enable pin, or "push to talk". Default is pin 10.
vw_set_ptt_inverted(true)
Configure the "push to talk" polarity.
vw_setup(2000)
Begin using all settings and initialize the library. This is similar to the "begin" function of other libraries. All pins should be configured before calling this function.

Transmission Functions
vw_send(message, length)
Transmit a message. "message" is an array of the bytes to send, and "length" is the number of bytes stored in the array. This function returns immediately and the message is sent slowly by an interrupt-based background process.
vw_tx_active()
Returns true if the message is being sent, or false if the transmitter is not active. You can use this after sending a message to test when it has finished being transmitted.
vw_wait_tx()
Wait for a message to be fully transmitted. Often the simplest approach is to call this after vw_send.

Reception Functions
vw_rx_start()
Activate the receiver process. You must call this function before any reception can occur. An interrupt-based background process is started which monitors the reception of data.
vw_have_message()
Returns true if message has been received. This is similar to the "available" function of most other libraries.
vw_wait_rx()
Wait for a message to be received. This will only return when a message has been received, otherwise it will wait forever.
vw_wait_rx_max(timeout_ms)
Wait for a message, but give up after "timeout_ms". Returns true if a message was received, or false if the timeout period elapsed.
vw_get_message(buf, &buflen))
Read the last received message. This should be called only when a message is known to be received with any of the 3 functions above. "buf" is an array where the message is copied. "buflen" should have the array's maximum size upon input, and upon return the number of bytes actually copied is retured. The function itself returns true if the message was verified correct, or false if a message was received but appears to have been corrupted.
vw_rx_stop()
Disable the receiver process.

Share:

1 komentar:

Copyright © FILAB | Powered by FILAB
Design by Fickry Muhammad | Technology by Filab.id