Pages: [1]   Go Down
Author Topic: How to send data from VB application and arduino thru RF-433 module  (Read 1649 times)
0 Members and 1 Guest are viewing this topic.
INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello all.... I am confused a bit.I have wrote the vb code to make ON and OFF the LED connected to arduino. I am sending data from VB app over COM port (instead of serial monitor) and the data is '1' for LED ON and '0' for OFF. Here I want to send this signal thru RF-433 module. I have connected the TX pin of arduino to Data pin of RF module. On other hand, second arduino is connected to RF Receiver with LED on Pin 12. Now I am not getting how to write code for arduino of Tx side to send data thru RF...??? I want to send data which is coming from VB serial port, and send it by arduino's Tx pin to which the RF module is connected.

Here is my vb code:

Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1

    Shared _continue As Boolean
    Shared _serialPort As SerialPort

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close()
        SerialPort1.PortName = "com12" 'change com port to match your Arduino port
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
    End Sub

    Private Sub btnOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOn.Click
        picOn.Visible = True
        SerialPort1.Open()
        SerialPort1.Write("1")
        SerialPort1.Close()
    End Sub

    Private Sub btnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOff.Click
        picOn.Visible = False
        SerialPort1.Open()
        SerialPort1.Write("0")
        SerialPort1.Close()
    End Sub
End Class

NOTE: THE ABOVE VB CODE IS WORKING WELL.

So please guide me to write code for Transmitting the data thru RF module.
« Last Edit: July 04, 2013, 12:34:21 pm by ajinkya123 » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So please help me to write code for Transmitting the data thru RF module.

What have you tried?
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not tried any.... i am totally confused how to start with code....
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not tried any.... i am totally confused how to start with code....


Look at some of the examples for the RF modules.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49412
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and send it by arduino's Tx pin to which the RF module is connected.
Which pin, specifically, is that? The VB application is talking to the Arduino via pins 0 and 1, on all but the Leonardo and Micro.

Which RF module do you have, specifically?

Sending data via RF modules is generally the same as sending data via wires. The Arduino doesn't care that there are not wires involved.
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and send it by arduino's Tx pin to which the RF module is connected.
Which pin, specifically, is that? The VB application is talking to the Arduino via pins 0 and 1, on all but the Leonardo and Micro.

Which RF module do you have, specifically?

Sending data via RF modules is generally the same as sending data via wires. The Arduino doesn't care that there are not wires involved.

Thanx @PaulS.... I am totally agreed with you. But i am sending multiple data to control devices. I am using general ASK RF-433 MHz module. I am connecting RF's data pin to arduino's Digital 12 pin i.e. i want to send data via Digital Pin 12. (or in case i will connect it to Tx pin of arduino even.) From my VB app i am sending "0" and "1" for making LED OFF and ON respectively. Then how can i code my arduino to send specific data thru RF... as well as according to Tx code how reciever side arduino will recognize the incoming data...??? And this is my trial application in VB to control only one Device. After the program success of arduino Tx, i am going to add more devices. Then there will be some other data say numbers or characters to be sent.
« Last Edit: July 05, 2013, 06:15:35 am by ajinkya123 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49412
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are not going to use the hardware serial pins to communicate with the radio, and you can't because you are using them to communicate with the VB app on the PC, then you need to use SoftwareSerial to communicate with the radio. Sending data to the radio is a simple matter of sending serial data, using the write(), print(), or println() methods.
Logged

Sydney, Australia
Offline Offline
Sr. Member
****
Karma: 6
Posts: 397
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and send it by arduino's Tx pin to which the RF module is connected.
Which pin, specifically, is that? The VB application is talking to the Arduino via pins 0 and 1, on all but the Leonardo and Micro.

Which RF module do you have, specifically?

Sending data via RF modules is generally the same as sending data via wires. The Arduino doesn't care that there are not wires involved.

Thanx @PaulS.... I am totally agreed with you. But i am sending multiple data to control devices. I am using general ASK RF-433 MHz module. I am connecting RF's data pin to arduino's Digital 12 pin i.e. i want to send data via Digital Pin 12. (or in case i will connect it to Tx pin of arduino even.) From my VB app i am sending "0" and "1" for making LED OFF and ON respectively. Then how can i code my arduino to send specific data thru RF... as well as according to Tx code how reciever side arduino will recognize the incoming data...??? And this is my trial application in VB to control only one Device. After the program success of arduino Tx, i am going to add more devices. Then there will be some other data say numbers or characters to be sent.


You need to break this down into modules as such

1) I assume you have 2 x Arduino with RF433Mhz modules - which ones specifically - i.e. a web link would be good as to where you sourced them
2) Lets call the Far Arduino - the receiver - this will receive the commands to turn things on and off from the Near Arduino - which will be the transmitter
3) The transmitter Arduino will be connected to the Local PC serial port/USB and will be receiving data from your VB app - once it receives a command it will then go and Transmit that to the Far Arduino which will receive it and act on it

So to make this happen

a) Far Arduino - needs the following code

Library to talk to RF433Mhz modules
Routine to listen to the module and when it receives a particular code (lets say D1) it will turn on Digital pin 1, when it receives D0 it will turn off Digital Pin 0

b) Near Arduino - needs the following code

Library to talk to RF433Mhz modules
Routine to listen to USB interface to receive commands from the PC VB App,
Routine to take those commands received from the PC VB App and then transmit them out to the Far Arduino through the 433Mhz network


break this down into steps

Write the code on the Far Arduino to turn on an off a LED on D0 (or whatever pin) - once you have this then write code to talk to the 433mhz modules - have a look at the VirtualWire library for this

Get the Two Arduinos talking over 433Mhz

Then get the transmitting Arduino to send a hello to the Far Arduino

etc etc etc

Craig
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are not going to use the hardware serial pins to communicate with the radio, and you can't because you are using them to communicate with the VB app on the PC, then you need to use SoftwareSerial to communicate with the radio. Sending data to the radio is a simple matter of sending serial data, using the write(), print(), or println() methods.

hey,

will this code work..??
TRANSMITTER:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(10,11); //RX & TX
int ch=0;

void setup()
{
  pinMode(rxPin,INPUT);
  pinMode(txPin,OUTPUT);
  Serial.begin(9600);
  //Serial.println("Hi");
  
  mySerial.begin(1200);
  //mySerial.println("Hello");
}
void loop()
{
  if(Serial.available()>0)
  {
    ch=Serial.read();
    mySerial.write(ch);
  }
}


RECEIVER:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(10,11); //RX & TX
int ch=0;

void setup()
{
  pinMode(rxPin,INPUT);
  pinMode(13,OUTPUT);
  //pinMode(txPin,OUTPUT);
  Serial.begin(9600);
  //Serial.println("Hi");
  
  mySerial.begin(1200);
  //mySerial.println("Hello");
}
void loop()
{
  if(mySerial.available()>0)
  {
    ch=mySerial.read();
    //Serial.write(ch);
    switch(ch)
    {
      case '0':
          digitalWrite(13,HIGH);
          break;
      case '1':
          digitalWrite(13,LOW);
          break;
      default:
          break;
    }
  }
}

« Last Edit: July 06, 2013, 01:55:01 am by ajinkya123 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49412
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will this code work..??
Well, did it?
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will this code work..??
Well, did it?

Not experimented yet, only wrote this code.... Will this work..??
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will this code work..??
Well, did it?

Not experimented yet, only wrote this code.... Will this work..??

You tell us, you got the hardware to test it.
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will this code work..??
Well, did it?

Not experimented yet, only wrote this code.... Will this work..??

You tell us, you got the hardware to test it.

Sure Sure... i will post my result once it succeed.... btw thanx a lot for the help till the time... smiley
Logged

INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Huh.... Finally did it... Following code is working successfully. I used SoftwareSerial library. The Tx code is simple and can be implemented without any library. I just took data from VB app on RX pin of arduino and sent it to the TX of arduino to which the RF module is connected. The receiver requires software serial library.

Tx Code :

1. WITHOUT LIBRARY.

int inByte;
void setup()
{
  Serial.begin(2400);
}
void loop()
{
  if(Serial.available()>0)
  {
    inByte=Serial.read();
    switch(inByte)
    {
      case '0':
          Serial.write(inByte);
          break;

      case '1':
          Serial.write(inByte);
          break;
  
       default:
          break;
    delay(100);
    }
  }
}


2. WITH LIBRARY.

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(10,11); //RX & TX
int ch;

void setup()
{
  pinMode(rxPin,INPUT);
  pinMode(txPin,OUTPUT);
  Serial.begin(9600);
  //Serial.println("Hi");
  
  mySerial.begin(2400);
  //mySerial.println("Hello");
}
void loop()
{
  if(Serial.available()>0)
  {
    ch=Serial.read();
    mySerial.write(ch);
  }
}



RX CODE:

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(10,11); //RX & TX
int ch=0;

void setup()
{
  pinMode(rxPin,INPUT);
  pinMode(13,OUTPUT);
  //pinMode(txPin,OUTPUT);
  Serial.begin(9600);
  //Serial.println("Hi");
  
  mySerial.begin(2400);
  //mySerial.println("Hello");
}
void loop()
{
  if(mySerial.available()>0)
  {
    ch=mySerial.read();
    //Serial.write(ch);
    switch(ch)
    {
      case '0':
          digitalWrite(13,LOW);
          break;
      case '1':
          digitalWrite(13,HIGH);
          break;
      
      default:
          break;
    }
  }
}


Btw Thanx a lot to everyone who led me towards proper implementation of the code.
« Last Edit: July 08, 2013, 04:26:59 am by ajinkya123 » Logged

Pages: [1]   Go Up
Jump to: