Personal computers are usually connected to each other using network cables in a LAN-based office network. Connecting two computers using USB cable or RS – 232 cable for data communication is a viable option when the two systems are placed close together. Furthermore, a single network cable connects one PC to only one other PC. If the computer systems in an office are designed to communicate data wirelessly, the cost of installing elaborate network cabling can be saved and the entire setup will appear more organized and clean. This way, any computer can be connected to any other computer without any hassle. A single computer can also be easily connected to any number of other computers at the same time.
This project illustrated wireless data communication between PCs using 434 MHz RF module. The RF module has a range of 50-60 meters and can be extended to 300-350 meters by using an antenna and increasing the transmit power of the module . Therefore, RF-based wireless data communication network can be installed in any small office or workplace. In the project, as PCs cannot directly interface with the RF module, they are interconnected using Arduino boards. The PC that is to function as a data server is connected to an RF transmitter through the Arduino board, while the PCs that are to function as data clients in the wireless local area network are connected to RF receivers through the Arduino. Data communication was illustrated using the serial monitor on both PCs.
Required components
Mr. No. | Required components | Amount |
---|---|---|
1 | RF Rx Module (434Mhz) | 1 |
two | RF Tx Module (434Mhz) | 1 |
3 | Arduino for mini | two |
4 | Desktop/Laptop Computer | two |
5 | Battery – 9V | two |
6 | Test board | two |
7 | Connecting wires |
Fig. 1: Block Diagram of Arduino-based PC for PC RF data communication Circuit Connections
In the project, one PC is configured as a data server and another PC is configured as a data client. Many PCs can be turned into data clients, but only one PC was turned into a client in the project for demonstration purposes. The PC-made server is connected to an Arduino board using USB cable and an RF transmitter interfaces with the Arduino board for RF transmission. To interface the RF transmitter with Arduino, its serial input pin (pin 2) is connected to pin 12 of the Arduino board and an antenna is attached to pin 4 of the RF transmitter module for range extension.
On the client PC, the PC is again connected to the Arduino using the USB cable and the Arduino board is further connected to an RF receiver for client-like operation. To interface the RF receiver with Arduino, the serial output pin (pin 2) of the receiver module is connected to pin 11 of the client-side Arduino board and an antenna is connected to pin 8 of the RF receiver for range extension . VCC and ground are provided on the respective pins of the Arduino and RF modules as indicated in their datasheets.
Fig. 2: Arduino-based PC-to-PC RF data communications prototype
How does the circuit work?
In the project, data is transferred from the Server PC to the Client PC. The server PC transfers the data to be transmitted to the Arduino board connected via the USB cable. The serial monitor program is used to transfer data from the PC to the Arduino board. The Arduino has the program code to read the character transferred to its buffer and transmit it serially to the RF module using the VirtualWire Library functions. Since the RF module transmits only one character at a time, the character buffer received from the PC must be stored in an array in the server-side Arduino program code.
On the client-side PC, the RF-transmitted character buffer is detected by the RF receiver and passed serially to the client-side Arduino board. The program code on the client-side Arduino board reads the character buffer and stores it in an array. The matrix elements are subsequently transferred serially via a USB cable to the client PC. On the Client PC, the received character matrix is displayed using the Serial Monitor program. A java based program can also be developed to transmit and receive data from USB ports.
Fig. 3: Image showing Arduino boards used for PC to PC RF data transfer
Programming Guide
On the server-side Arduino, first, the VirtualWire library is imported to facilitate interfacing with the RF module.
#include
An LED is connected to pin 13 to indicate serial transmission in progress. Thus, a variable “ledpin” is declared and assigned to pin 13 of the Arduino. The variable “MsgData” is declared to store reading characters and the array “MsgcharAR” is declared to store multiple characters before serial transmission. Some global variables – “length” to store the message length, “data_available” to check data availability and a counter “i” are initialized.
A setup function is called, where ledpin is set to output mode using the pinMode function, the system baud rate is set to 9600 bits per second using the Serial.begin function, and the vw_setup function is used to set the baud rate. RF serial transmission transmission to 2,000 bits per second.
A loop function is called, within which the first length variable is initialized to 0 and the serial data is checked if available using the Serial.available function. If serial data is available, it is read using the Serial.read function and stored in the MsgcharAR array. The length counter is incremented and data_available is set to 1 for boolean logic. The code block is repeated in a While loop until serial data is available.
If data is available, the data_available flag variable is left with a Boolean setting of 1, then the message stored in the MsgcharAR array is serially sent to the buffer using the Serial.print function.
The message stored in the buffer must be sent serially in RF. The led that indicates transmission in progress is turned on by sending a HIGH logic to the ledpin. The message is sent serially in RF using the vw_send function, where the message characters are first converted to unsigned character format. vw_wait_tx is used to wait until the entire message is transmitted. When the transmission ends, the ledpin receives a logic LOW to turn off the LED of the ongoing transmission.
The data_available is set to 0 and each element of the MsgcharAR array is set to 0 as the default value.
available_data = 0;
This ends the server-side Arduino code.
In client-side Arduino, the program code first imports the required standard libraries. The VirtualWire library is imported to allow reception of serial data from the RF module.
The pin 13 where the transmission progress indicator LED is connected is assigned to the ledpin variable and two variables – “Sensor1Data” to capture the message in entire form and “Sensor1CharMsg” to store the character representation of the message to be displayed are declared.
A setup function is called where the Arduino baud rate is set to 9600 bits per second using the Serial.begin function. The ledpin is set to output using the pinMode function.
The RF transmitter and receiver module does not have a Push To Talk pin. They are inactive when no data is present to transmit or receive respectively. Therefore, vw_set_ptt_inverted(true) is used to set the push to talk polarity and request the receiver to continue receiving data after fetching the first character. The baud rate for serial input is set to 2000 bits per second using the vw_setup function. Data reception is started using vw_rx_start .
A loop function is called within which the “buf” array to read the serial buffer and the “buflen” variable to store the buffer length are declared.
The character buffer is stored in the Sensor1CharMsg array using the for loop with the counter initialized.
The data_available is set to 0 and each element of the MsgcharAR array is set to 0 as the default value.
Project source code
###
#include// LED's const int ledPin = 13; int MsgData; //int Sensor2Data; char MsgcharAR(40); int length,data_available; int i; void setup { // PinModes // LED pinMode(ledPin,OUTPUT); // for debugging Serial.begin(9600); // VirtualWire setup vw_setup(2000); // Bits per sec }void loop { length = 0; while(Serial.available) { MsgcharAR(length) = Serial.read ; length++; delay(100); data_available = 1; }// Convert integer data to Char array directly // itoa(data,Sensor1CharMsg,10); if(data_available == 1) { // DEBUG Serial.print(" Sending data : "); Serial.println(MsgcharAR); //Serial.println(" "); delay(1000); // END DEBUGdigitalWrite(13, true); // Turn on a light to show transmitting vw_send((uint8_t *) MsgcharAR, length); vw_wait_tx ; // Wait until the entire message is gone digitalWrite(13, false); // Turn off a light after transmission delay(200); for(i = 0 ; i < 40 ; i++) { MsgcharAR (i) = 0; }} } // END void loop... #include// LED's int ledPin = 13; // Sensors int Sensor1Data; // RF Transmission container char Sensor1CharMsg(4); void setup { Serial.begin(9600); // sets the digital pin as output pinMode(ledPin, OUTPUT); //VirtualWire // Initialize the IO and ISR // Required for DR3100 vw_set_ptt_inverted(true); // Bits per sec vw_setup(2000); // Start the receiver PLL running vw_rx_start ; } // END void setupvoid loop { uint8_t buf(VW_MAX_MESSAGE_LEN); uint8_t buflen = VW_MAX_MESSAGE_LEN; void loop { uint8_t buf(VW_MAX_MESSAGE_LEN); uint8_t buflen = VW_MAX_MESSAGE_LEN; // Non-blocking if (vw_get_message(buf, &buflen)) {int i; // Turn on a light to show received good message digitalWrite(13, true); // Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { // Fill Sensor1CharMsg Char array with corresponding // chars from buffer. Sensor1CharMsg(i) = char(buf(i)); }data_available = 0; for(i = 0 ; i < 40 ; i++) { MsgcharAR (i) = 0; } } } // END void loop...
###
Circuit diagrams
RF22_0 |
Project video