Interface RF Module

download Interface RF Module

of 22

Transcript of Interface RF Module

  • 8/12/2019 Interface RF Module

    1/22

    Interface RF Module with ArduinoPosted on December 10, 2012b y torongooo2

    3 Votes

    What is RF module? An RF Module (Radio Frequency Module) is a small electronic circuit used to transmit and/orreceive radio signals on one of a number of carrier frequencies. RF Modules are widely used inelectronic design owing to the difficulty of designing radio circuitry. RF Modules are most oftenused in medium and low volume products for consumer applications such as garage door

    openers, wireless alarm systems, industrial remote controls, smart sensor applications, andwireless home automation systems.The operating frequency of RF module can be varied. But we offer two kinds of, one of them is433 MHz and another is 315 MHZ. The transmission occurs at the rate of 600bps 10Kbps.Thetransmitted data is received by an RF receiver operating at the same frequency as that of thetransmitter.

    Specification Frequency: 433 MHz Modulation: ASK Receiver Data Output: High 1/2 VCC, Low 0.7v

    Transmitter Input Voltage: 3-12V (high voltage = more transmitting power). Receiver Input Voltage : 3.3-6V (high voltage = more receiving power) For total specification you can visit this link: Address

    Pin Diagram

    Rx module Pin description:

    Pin No Function Name

    1 Ground(0V) Ground

    http://emguide.wordpress.com/2012/12/10/15/http://emguide.wordpress.com/2012/12/10/15/http://emguide.wordpress.com/author/torongooo2/http://www.seeedstudio.com/wiki/index.php?title=433Mhz_RF_link_kithttp://www.seeedstudio.com/wiki/index.php?title=433Mhz_RF_link_kithttp://emguide.wordpress.com/2012/12/10/15/pindiagram/http://www.seeedstudio.com/wiki/index.php?title=433Mhz_RF_link_kithttp://emguide.wordpress.com/author/torongooo2/http://emguide.wordpress.com/2012/12/10/15/http://emguide.wordpress.com/2012/12/10/15/
  • 8/12/2019 Interface RF Module

    2/22

    2-3 Serial data output pin Input

    4 Supply voltage(3.3V-6V) Vcc

    5 Antenna Ant

    Tx Module Pin description:

    Pin No Function Name

    1 Antenna ANT

    2 Serial data input pin Output

    3 Ground(0V) Ground

    4 Supply voltage(3V-12V) Vcc

    Arduino Compatibility with RF module Now we are coming to our main point. The question, is how can we connect a Arduino with RF

    module?What would be the circuit diagram? You dont need to be worried. Here I have presented a tutorial so that you can easily understand what you need to do .Its so simple toconnect your Arduino with RF module. We have already developed Transmitter and Receivershields which are fully compatible with Arduino board. Just plug and play, nothing else. So itwould be very easy for you to connect a Transmitter or Receiver shield with Arduino and workwith it. In our shield we also provide a connector system so that you can also connect other Tx orRx modules to this shield. So it is a wide open door for everyone who really wants to work withRF.

    Working procedure First you need to connect your Transmitter shield with an Arduino board and also a Receiver

    shield with another Arduino Board. Plug 12V Dc with both of the Arduino Boards so that Arduino can start working. If you think, you dont want to use our Rx, Tx module then you need to connect wire

    properly between Tx, Rx module and also shield. You dont need to be wor ried about this.By shield you also can connect other Tx, Rx module with Arduino. For Schematic pleasecheck the link:

    Now your circuit setup is complete. For coding you need to plug Usb cable with your Arduino.

  • 8/12/2019 Interface RF Module

    3/22

    Now start your code and debug. Enjoy!!!Coding technique:

    I believe that you know something about Arduino coding. Now I start the coding technique forTx and Rx module. To send data you need to synchronize your Tx and Rx module . For thisyou need to send 0b01010101 or U which has a binary value 01010101. This is called pre-

    amble . This pre-amble byte is usually sent 2 to 5 times in a row to synchronize sender andreceiver , BUT NOT ALWAYS! Once you have synchronized your chip to the RF receiver youcan sample the bits in the middle of your data line. In your data you also need to attach starting

    bit and ending bit, without these two bits you cant understand when the main data is started andwhen finished. Data pattern can be like this: UUU/PiLabs,Rock#@ . In this data pattern youcan notice that at first I have sent U 3 times for synchronization and after that I have put thestart bit by / and then sent data which is PiLabs,Rock and finally sending finish bit by#@ . Here I will attach the full code for receiver and transmitter also . In my code I use someArduinos special function which is: findUntil readBytesUntil

    For details about these two functions you need to click here, findUntil and readBytesUntil . ForArduinos function you need to visit this link Libaries . To complete the project you need to senddata according to my data pattern and then receive it by another Arduino. Here I have attachedmy code and also library which is shown below. You can easily debug your code by Arduinosserial port. In my code you can find a scan() function which I have built for scanning data from / to #@. Yo u can easily use it in your code also. This scan() function would be very helpful.By using this function you can sort out your main data.

    Schematic of Receiver module

    In schematic you can find Arduino board which is U1, RF receiver connector which is mentionas RF RECEIVER. Here I have connected two relays for other works. Suppose you want to

    control two electrical loads by RF transmitter (Ex: RF Remote control). Here you can notice thatD9 & D10 are mentioned as Relay1 and Relay2. By these two pins you can control the relays.The main theme is you get data from RF receiver then you need to check it with your predefineddata. If it matches, then you can do anything you want.

    Code for Receiver module

    http://arduino.cc/en/Reference/StreamFindUntilhttp://arduino.cc/en/Reference/StreamFindUntilhttp://arduino.cc/en/Reference/StreamFindUntilhttp://arduino.cc/en/Reference/StreamReadBytesUntilhttp://arduino.cc/en/Reference/StreamReadBytesUntilhttp://arduino.cc/en/Reference/StreamReadBytesUntilhttp://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Reference/Librarieshttp://emguide.wordpress.com/2012/12/10/15/reveiver/http://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Reference/StreamReadBytesUntilhttp://arduino.cc/en/Reference/StreamFindUntil
  • 8/12/2019 Interface RF Module

    4/22

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    #include // Include Software Serial libary

    SoftwareSerial mySerial(4,6); // Rx,Tx

    //===========Scan function=================================

    void scan()

    {

    //=================Variable Initialization================//

    char tmp[20];

    char data[20];

    for(int i=0;i

  • 8/12/2019 Interface RF Module

    5/22

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    tmp[i]=0;

    }

    byte len=0;

    //========================================================//

    //===============Algorithm Start=========================//

    if(mySerial.available()) // If Software Serial detect any data in it's buffer

    {

    mySerial.setTimeout(10000);// Set timeout for 10 sec

    mySerial.flush(); // Flush MySerial buffer

    // This is build in function of Software serial

  • 8/12/2019 Interface RF Module

    6/22

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    // findUntil() reads data from the stream until the target string

    // of given length or terminator string is found.

    // The function returns true if target string is found, false if timed out

    // Syntax: stream.findUntil(target, terminal)

    // Sending Data pattern would be in this example: UUU/PiLabs*@

    // Sending Data pattern must be: /USER DEFGINED DATA*@

    if(mySerial.findUntil("@","@"))//checking the condition

    {

    // readBytesUntil() read characters from a stream into a buffer. The function

    // terminates if the terminator character is detected, the determined length has

  • 8/12/2019 Interface RF Module

    7/22

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    76

    77

    78

    79

    80

    // or it times out.

    // readBytesUntil() returns the number of characters placed in the buffer. A 0 me

    // Syntax: stream.readBytesUntil(character, buffer, length)

    len= mySerial.readBytesUntil('@',tmp,50);// From this instruction we can get leng

    // Also saved the string in tmp

    Serial.println(tmp); // For Debugging we print tmp string in s

    Serial.println(len); // For debugging we print the length of s

    int i=0; // Initialize variable i

    for(i=0;i

  • 8/12/2019 Interface RF Module

    8/22

    81

    82

    83

    84

    85

    86

    87

    88

    89

    90

    91

    92

    93

    94

    95

    96

    97

    98

    99

    100

    data[i]=0;

    }

    // ===Algorithm for Sorting main data from Total String======

    while(tmp[i]!='*') // Searching for * Because Main data star

    {

    i++; // Increamented index by 1

    }

    i++; // When * is found index increase 1 bcoz

    // after *

    int j=0; // Initialize j by 0

  • 8/12/2019 Interface RF Module

    9/22

    101

    102

    103

    104

    105

    106

    107

    108

    109

    110

    111

    112

    113

    114

    115

    116

    117

    118

    119

    120

    while(tmp[i]!='/') // Now its searching for '/' And till '/'

    {

    data[j]=tmp[i]; // Stored data in data variable from string

    i++; // Increament index

    j++; // Increament index

    }

    Serial.println(data); // Serial data print in serial terminal

    // strcmp is a function which return 0 when two string match

    if(strcmp("PiLabs,Rock",data)==0)

    { // And in here it checked by strcmp function

    Serial.println("GOTCHA"); // Serial Printout

  • 8/12/2019 Interface RF Module

    10/22

    121

    122

    123

    124

    125

    126

    127

    128

    129

    130

    131

    132

    133

    134

    135

    136

    137

    138

    139

    140

    }

    }

    }

    }

    //================Setup function=============================================

    void setup()

    {

    Serial.begin(9600); // Serial Port initialization by 9600 Bps

    mySerial.begin(1200);//SoftwareSerial port initialization by 1200 bps

    mySerial.setTimeout(10000); // Set time out 10 sec

  • 8/12/2019 Interface RF Module

    11/22

    141

    142

    143

    144

    145

    146

    147

    148

    149

    150

    151

    152

    153

    154

    mySerial.flush(); // Software serial buffer flush

    }

    //=================loop Function====================================

    void loop()

    {

    scan(); // Called scan function

    }

    Schematic of Transmitter Module

    http://emguide.wordpress.com/2012/12/10/15/transmitter/
  • 8/12/2019 Interface RF Module

    12/22

    In schematic you can find Arduino Board, which is denoted by U1. You can see some buttons atthe right side of the Schematic. This button is used for general purpose. In this RF shield we havetried to give you some kind of gaming flavor. But the question is, how?? There are 5 switches,you can use it like up, down, left, right and enter. And according to these buttons you need tosend data through Tx module. Here Tx module connector is denoted by TX. At the upper left

    side of the schematic you can notice that we have put a seven segment display which isCC(Common Cathode)type. When a switch is pressed,the corresponding switch number(1,2,3,4,5) will be shown in seven segment display. For controlling seven segment displays wehave used 7447 BCD to Seven segment drivers IC. For 7447 datasheet you can click thislink. Datasheet of 7447 .

    Code for Transmitter module

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    #include // Include Software Serial libary

    SoftwareSerial mySerial(6,7); // Rx,Tx

    //=======================================================

    //============show__segment function =========================

    //=======================================================

    void show__segment(int button__no)// Show__segment function start

    {

    if(button__no==0)// if button no 0 is pressed

    http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&sqi=2&ved=0CGYQFjAJ&url=http%3A%2F%2Fwww.eng.uwo.ca%2Fpeople%2Fkmcisaac%2FCoursepages%2FECE339a%2FDatasheets%2F7447.pdf&ei=5VDAUNPiKIOE2gXexIGYDA&usg=AFQjCNFwZLkgdAwJ7htnhpFxkXh9v8YR5Ahttp://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&sqi=2&ved=0CGYQFjAJ&url=http%3A%2F%2Fwww.eng.uwo.ca%2Fpeople%2Fkmcisaac%2FCoursepages%2FECE339a%2FDatasheets%2F7447.pdf&ei=5VDAUNPiKIOE2gXexIGYDA&usg=AFQjCNFwZLkgdAwJ7htnhpFxkXh9v8YR5Ahttp://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&sqi=2&ved=0CGYQFjAJ&url=http%3A%2F%2Fwww.eng.uwo.ca%2Fpeople%2Fkmcisaac%2FCoursepages%2FECE339a%2FDatasheets%2F7447.pdf&ei=5VDAUNPiKIOE2gXexIGYDA&usg=AFQjCNFwZLkgdAwJ7htnhpFxkXh9v8YR5Ahttp://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&sqi=2&ved=0CGYQFjAJ&url=http%3A%2F%2Fwww.eng.uwo.ca%2Fpeople%2Fkmcisaac%2FCoursepages%2FECE339a%2FDatasheets%2F7447.pdf&ei=5VDAUNPiKIOE2gXexIGYDA&usg=AFQjCNFwZLkgdAwJ7htnhpFxkXh9v8YR5A
  • 8/12/2019 Interface RF Module

    13/22

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    {

    digitalWrite(2,LOW);// 0|

    digitalWrite(3,LOW);// 0|

    digitalWrite(4,LOW);// 0|so no is 0

    digitalWrite(5,LOW);// 0|

    mySerial.println("UUU/PiLabsON0*@");// Data send via mySerial

    }

    else if(button__no==1) //if button no 1 is pressed

    {

    digitalWrite(2,HIGH);// 1|

  • 8/12/2019 Interface RF Module

    14/22

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    digitalWrite(3,LOW);// 0|

    digitalWrite(4,LOW);// 0|so no is 1

    digitalWrite(5,LOW);// 0|

    mySerial.println("UUU/PiLabsON1*@");// Data send via mySerial

    }

    else if(button__no==2)//if button no 2 is pressed

    {

    digitalWrite(2,LOW);// 0|

    digitalWrite(3,HIGH);// 1|

    digitalWrite(4,LOW);// 0|so no is 2

  • 8/12/2019 Interface RF Module

    15/22

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    digitalWrite(5,LOW);// 0|

    mySerial.println("UUU/PiLabsON2*@");// Data send via mySerial

    }

    else if(button__no==3)//if button no 3 is pressed

    {

    digitalWrite(2,HIGH);// 1

    digitalWrite(3,HIGH);// 1

    digitalWrite(4,LOW);// 0 So no is 3

    digitalWrite(5,LOW);// 0

    mySerial.println("UUU/PiLabsON3*@");// Data send via mySerial

  • 8/12/2019 Interface RF Module

    16/22

    76

    77

    78

    79

    80

    81

    82

    83

    84

    85

    86

    87

    88

    89

    90

    91

    92

    93

    94

    95

    }

    else if(button__no==4)//if button no 4 is pressed

    {

    digitalWrite(2,LOW);// 0|

    digitalWrite(3,LOW);// 0|

    digitalWrite(4,HIGH);// 1|so no is 4

    digitalWrite(5,LOW);// 0|

    mySerial.println("UUU/PiLabsON4*@");// Data send via mySerial

    }

    }

  • 8/12/2019 Interface RF Module

    17/22

    96

    97

    98

    99

    100

    101

    102

    103

    104

    105

    106

    107

    108

    109

    110

    111

    112

    113

    114

    115

    //=======================================================

    //=============== Scan__button function =======================

    //=======================================================

    void scan__button()// Scan__button function start

    {

    if(digitalRead(12)== LOW)// Checking 12 no pin for button press

    {

    show__segment(1); // show__segment function call for no:1

    }

    else if(digitalRead(10)== LOW)// Checking 10 no pin for button press

  • 8/12/2019 Interface RF Module

    18/22

    116

    117

    118

    119

    120

    121

    122

    123

    124

    125

    126

    127

    128

    129

    130

    131

    132

    133

    134

    135

    {

    show__segment(2);// show__segment function call for no:2

    }

    else if(digitalRead(9)== LOW)// Checking 9 no pin for button press

    {

    show__segment(3);// show__segment function call for no:3

    }

    else if(digitalRead(8)== LOW)// Checking 8 no pin for button press

    {

    show__segment(4); // show__segment function call for no:4

  • 8/12/2019 Interface RF Module

    19/22

    136

    137

    138

    139

    140

    141

    142

    143

    144

    145

    146

    147

    148

    149

    150

    151

    152

    153

    154

    155

    }

    }

    //=========================================================

    //=================== Setup==================================

    //============================================================

    void setup()

    {

    pinMode(2,OUTPUT);//Define output, this pin is for A of 7447

    pinMode(3,OUTPUT);//Define output, this pin is for B of 7447

    pinMode(4,OUTPUT);//Define output, this pin is for C of 7447

  • 8/12/2019 Interface RF Module

    20/22

    156

    157

    158

    159

    160

    161

    162

    163

    164

    165

    166

    167

    168

    169

    170

    171

    172

    173

    174

    175

    pinMode(5,OUTPUT);//Define output, this pin is for D of 7447

    pinMode(8,INPUT);//Define input

    digitalWrite(8, HIGH);// Pull Up enable

    pinMode(9,INPUT);//Define input

    digitalWrite(9, HIGH);//Pull Up enable

    pinMode(10,INPUT);//Define input

    digitalWrite(10, HIGH);//Pull Up enable

    pinMode(11,INPUT);//Define input

    digitalWrite(11, HIGH);//Pull Up enable

    pinMode(12,INPUT);//Define input

  • 8/12/2019 Interface RF Module

    21/22

    176

    177

    178

    179

    180

    181

    182

    183

    184

    185

    186

    187

    188

    189

    190

    191

    192

    193

    194

    195

    digitalWrite(12, HIGH);//Pull Up enable

    Serial.begin(9600); // Serial Port initialization by 9600

    mySerial.begin(1200); // Software Serial port initialization

    mySerial.setTimeout(10000); // Set time out 10 sec

    mySerial.flush(); // Software serial buffer flush

    show__segment(0); // By default it shows 0

    }

    //========================================================

    //==================== loop=================================

    //========================================================

  • 8/12/2019 Interface RF Module

    22/22

    196

    197

    198

    199

    200

    201

    202

    203

    void loop()

    {

    scan__button();// scan__button function call

    }

    To buy or see details, click RF Shield and RF Transmitter Receiver pair. About these ads

    http://www.techshopbd.com/index.php/product-categories/shields/shields/rf-shieldhttp://www.techshopbd.com/index.php/product-categories/shields/shields/rf-shieldhttp://www.techshopbd.com/index.php/product-categories/rf/rf/rf-transmitter-receiver-pairhttp://www.techshopbd.com/index.php/product-categories/rf/rf/rf-transmitter-receiver-pairhttp://www.techshopbd.com/index.php/product-categories/rf/rf/rf-transmitter-receiver-pairhttp://en.wordpress.com/about-these-ads/http://en.wordpress.com/about-these-ads/http://en.wordpress.com/about-these-ads/http://www.techshopbd.com/index.php/product-categories/rf/rf/rf-transmitter-receiver-pairhttp://www.techshopbd.com/index.php/product-categories/shields/shields/rf-shield