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.
|Sr. No||Components Required||Quantity|
|1||RF Rx Module(434Mhz)||1|
|2||RF Tx Module(434Mhz)||1|
|5||1 k Pot||1|
|6||10 k Resistor||1|
|7||Arduino pro mini development board||2|
|8||Battery - 9V||2|
|10||Connecting wires|| |
The analog sensor used in this project is an LDR (Light Dependent Resistor). The LDR is connected to pin A2 of the Arduino Pro Mini. The LDR sensor is connected in a pull-up configuration. In this configuration, the LDR is connected between VCC and the output (A2 pin of Arduino) and a pull-up resistor of suitable value is connected between output and ground. The read analog data at pin A2 is serially out from pin 12 (digital I/O pin) of Arduino, so pin 12 is connected to pin 2 of the RF transmitter. The RF transmitter has an antenna attached to pin 4 for longer operational range.
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 RW pin of LCD is connected to pins 3 and 2 of the Arduino ProMini respectively. The E pin of the LCD is grounded.
The standard code library for interfacing Arduino UNO and Arduino Pro Mini are used in the project to program LCD with the board.
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.
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.
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.
const int ledPin = 13;
const int Sensor1Pin = A2;
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.
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.