The transmission of digital data over an RF module is quite common. The 434 RF modules are capable of transmitting 4-bit data along with the address byte. The circuits using RF modules for digital data transmission are simple and uses HT12E encoder and HT12D decoder ICs for parallel to serial and serial to parallel data conversion respectively. In real-life situations, the source of digital data are only the computers, microcomputers or digital ICs. The real world isn’t the digital, it is analog. Like, the most sensors actually are analog sensors and they are capable of transmitting the analog data to a digital form only when a microcomputer process it from analog to digital form.
The Arduino microcontrollers which are most commonly used in hardware projects are also capable of reading the analog data and representing it to digital form. The digitization of analog data to a digital form can be performed using the open-source virtualWire library of the Arduino. The read analog data can be serially out to an RF transmitter from any digital input/output pin.
This project demonstrates reading the analog data from LDR sensor by an Arduino board and its transmission to another Arduino board which display the data in digitized form on an LCD screen.
Components Required
Sr. No | Components Required | Quantity |
---|---|---|
1 | RF Rx Module(434Mhz) | 1 |
2 | RF Tx Module(434Mhz) | 1 |
3 | LDR | 1 |
4 | LCD | 1 |
5 | 1 k Pot | 1 |
6 | 10 k Resistor | 1 |
7 | Arduino pro mini development board | 2 |
8 | Battery – 9V | 2 |
9 | Bread Board | 2 |
10 | Connecting wires |
Fig. 1: Block Diagram of Arduino based Analog RF Data Transmitter
Circuit Connections
At the display side, the serially transmitted data is fetched by an RF receiver. The pin 2 of receiver is connected to pin 11 of the second Arduino board. An LCD is interfaced to the Arduino board for displaying the received sensor reading. The 16X2 LCD display is connected to the Arduino board by connecting its data pins to pins 7 to 4 of the Arduino board. The RS and E pin of LCD is connected to pins 3 and 2 of the Arduino ProMini respectively. The RW pin of the LCD is grounded.
Fig. 2: Table listing circuit connections between Arduino Uno and Character LCD
The standard code library for interfacing Arduino UNO and Arduino Pro Mini are used in the project to program LCD with the board.
Fig. 3: Prototype of Receiver Side of Arduino based Analog RF Data Transmitter
How the Circuit Works
The LDR sensor works on the principle of photo-conductivity. Its resistance is reduced when light falls on it as the resistivity of the sensor is reduced on exposure to the light. The LDR sensor is connected in pull-up configuration. The voltage is first dropped by the LDR and then is dropped by the output junction and pull-up resistor. When light falls on LDR, its resistance is reduced and so the voltage dropped by the pull-up resistor at the analog data pin is greater. While when the LDR is covered to restrict its exposure to light, the resistance value is increased so the voltage dropped by the pull-up resistor at the analog data pin is reduced. The analog reading is carried out at A2 pin of the Arduino Pro Mini. It can be done at any pin from A0 to A7 of the Arduino Pro Mini.
The read analog data is stored digitally in a variable in the program code which is converted to a digitized decimal form using the program logic. The digitized reading is serially out from pin 12 of the transmitter-side Arduino board to the RF transmitter.
The digitized reading is detected by the RF receiver and serially out from pin 2 of the receiver to pin 11 of receiver side Arduino board. The reading is displayed on an LCD screen using the standard library functions of lcd.h in the program code. The main execution of the project is software oriented so the program code is the one that needs to be carefully understood.
Fig. 4: Prototype of Transmitter side of Arduino based Analog RF Data Transmitter
Programming Guide
At the transmitter side, Arduino board has to read the analog reading in the form of voltage dropped at the sensor interfaced pin. For the same, VirtualWire library is imported.
#include <VirtualWire.h>
An LED has been connected to pin 13 for visual hint of data transmission. A variable “ledPin” is declared and assigned to pin 13. The LDR sensor is connected at pin A2, so a variable “Sensor1Pin” is declared and mapped to pin A2 of Arduino. A variable “Sensor1Data” is declared to fetch analog reading digitally and “Sensor1CharMsg” array is created for 3-digit precise decimal representation of the reading.
// LED’s
const int ledPin = 13;
// Sensors
const int Sensor1Pin = A2;
int Sensor1Data;
A setup() function is called, inside which, LED interfaced pin is set digital out and sensor interfaced pin is set to input mode using pinMode() function. The baud rate of the Arduino is set to 9600 bits per second using Serial.begin function. The baud rate for serial output is set to 2000 bits per second using vw_setup() function of the VirtualWire library.
A loop function is called where the analog data from pin A2 is read using analogRead() function and assigned to Sensor1Data variable. The Seria1Data value is converted to decimal form representation and stored in Sensor1CharMsg array using itoa() integer to character conversion function.
void loop()
The readings stored in both the variable and the array are serially buffered using Serial.print() function.
The LED interfaced pin is set to HIGH to glow LED as indication of data transmission. The reading stored in Sensor1Char array is converted to unsigned characters till all the four elements of the array are converted to unsigned char format. The characters are serially out using vw_send function and vw_wait_tx() function is used to continue transmission until all the data (all four characters) are serially out from the buffer. The LED is switched OFF as an indication of data transmission completed.
At the receiver side, again VirtualWire library is imported to read analog data.
A ledPin variable is assigned to pin 13 where LED indicating reception of data is connected. A variable Sensor1Data is declared to read data reading as integer and Sensor1CharMsg array is created to map the decimal form of data reading.
A setup function is called, where, baud rate of the receiver side Arduino is set to 9600 bits per second using the Serial.begin() function. The LED connected pin is set to digital out.
The RF transmitter and receiver module does not have Push To Talk pin. They go inactive when no data is present to transmit or receive respectively. Therefore vw_set_ptt_inverted(true) is used to configure push to talk polarity and prompt 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 vw_setup() function. The reception of the data is initiated using vw_rx_start() function.
A loop function is called where the data in the microcontroller’s buffer is read and displayed on the LCD screen. A “buf” array is declared of unsigned char type to fetch received char bytes and variable “buflen” is declared to store the length of received buffer data.
The received character buffer is read using vw_get_message() function and a counter “i” is initialized. The LED interfaced pin is set to HIGH to indicate that data has been received and received character buffer is converted to character data type and stored in Sensor1Msg array.
The last character in the array is set to Null character so that if the read buffer has less than four digits it does not display a garbage value on LCD screen. The Sensor1Msg array elements are converted to integers and stored in Sensor1Data array. The Sensor1Data array integers are displayed on LCD using Serial.print() function and LED interfaced pin is set to LOW to switch LED off as a visual indication that data has been successfully read and displayed. The analog reading has been read in the project as the voltage reading at the analog pin of Arduino Pro Mini.
The sensor reading has not been calibrated to show any real physical quantity like light intensity or luminosity in case of light based sensor. However, the actual reading of a physical quantity can be displayed through the project by judging the calibration of the sensor with respect to the physical quantity under measurement. The logic to convert the voltage reading to the measurement of the physical quantity under observation can be embedded in the program logic based on the calibration of the sensor.
You may also like:
Project Source Code
###
#include// LED's const int ledPin = 13; // Sensors const int Sensor1Pin = A2; int Sensor1Data; char Sensor1CharMsg[4]; void setup() { // PinModes // LED pinMode(ledPin,OUTPUT); // Sensor(s) pinMode(Sensor1Pin,INPUT); // for debugging Serial.begin(9600); // VirtualWire setup vw_setup(2000); // Bits per sec }// Read and store Sensor 1 data Sensor1Data = analogRead(Sensor1Pin); // Convert integer data to Char array directly itoa(Sensor1Data,Sensor1CharMsg,10);// DEBUG Serial.print("Sensor1 Integer: "); Serial.print(Sensor1Data); Serial.print(" Sensor1 CharMsg: "); Serial.print(Sensor1CharMsg); Serial.println(" "); delay(1000); // END DEBUGdigitalWrite(13, true); // Turn on a light to show transmitting vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, false); // Turn off a light after transmission delay(200); } // 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 // Initialise 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; // 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]); }// Null terminate the char array // This needs to be done otherwise problems will occur // when the incoming messages has less digits than the // one before. Sensor1CharMsg[buflen] = ''; // Convert Sensor1CharMsg Char array to integer Sensor1Data = atoi(Sensor1CharMsg);// DEBUG Serial.print("Sensor 1: "); Serial.println(Sensor1Data); // END DEBUG // Turn off light to and await next message digitalWrite(13, false); } }###
Circuit Diagrams
Project Video
Filed Under: Tutorials
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.