SlideShare a Scribd company logo
Analog Data Transmission on RF Module Using
Arduino
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. Name of component Required
quantity
1 RF Tx module(434Mhz) 1
2 RF Rx 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
Block Diagram -
Circuit Diagram -
Circuit Connections -
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.
LCD Arduino UNO
RS 3
RW 2
E GRND
D7,D6,D5,D4 7,6,5,4 respectively
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.
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;
char Sensor1CharMsg[4];
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.
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
}
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() {
// Read and store Sensor 1 data
Sensor1Data = analogRead(Sensor1Pin);
// Convert integer data to Char array directly
itoa(Sensor1Data,Sensor1CharMsg,10);
The readings stored in both the variable and the array are serially buffered
using Serial.print() function.
// DEBUG
Serial.print("Sensor1 Integer: ");
Serial.print(Sensor1Data);
Serial.print(" Sensor1 CharMsg: ");
Serial.print(Sensor1CharMsg);
Serial.println(" ");
delay(1000);
// END DEBUG
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.
digitalWrite(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...
At the receiver side, again VirtualWire library is imported to read analog data.
#include <VirtualWire.h>
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.
// LED's
int ledPin = 13;
// Sensors
int Sensor1Data;
// RF Transmission container
char Sensor1CharMsg[4];
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.
void setup() {
Serial.begin(9600);
// sets the digital pin as output
pinMode(ledPin, OUTPUT);
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.
// 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 setup
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.
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
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.
// 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]);
}
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.
// 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] = '0';
// Convert Sensor1CharMsg Char array to integer
Sensor1Data = atoi(Sensor1CharMsg);
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 visual
indication that data has been successfully read and displayed.
// DEBUG
Serial.print("Sensor 1: ");
Serial.println(Sensor1Data);
// END DEBUG
// Turn off light to and await next message
digitalWrite(13, false);
}
}
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, 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.
PROGRAMMING CODE
#include <VirtualWire.h>
// 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 DEBUG
digitalWrite(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 <VirtualWire.h>
// 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 setup
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]);
}
// 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] = '0';
// 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);
}
}

More Related Content

PPT
Attacks in MANET
PPTX
RFID BASED ATTENDANCE SYSTEM.pptx
PPTX
Flying ad hoc network
PPTX
OPTISYSTEM Research Project Ideas
PDF
Design and implementation of 32 bit alu using verilog
PDF
Serial Communication Interfaces
PPTX
Black hole attack
PPS
Attacks in MANET
RFID BASED ATTENDANCE SYSTEM.pptx
Flying ad hoc network
OPTISYSTEM Research Project Ideas
Design and implementation of 32 bit alu using verilog
Serial Communication Interfaces
Black hole attack

What's hot (20)

PPT
Introduction To Wireless Fading Channels
PPTX
localization in wsn
PPT
PDF
Device drivers and interrupt service mechanism
PPTX
Pcs ch1
PPTX
Signalling and telecommunication
PPT
Common protocols
PPTX
Wlan architecture
PPT
PPT
Logical channels
PPTX
Cw and fm cw radar
PPTX
Leo satellite networks
PPTX
Prediction of range performance
PPTX
IPv4 Addressing
PPTX
Wi-Fi Esp8266 nodemcu
PDF
Location Aided Routing (LAR)
PPTX
Computer networks - Channelization
PPT
Intrusion Detection System
PPT
Security issues and challenges in MANET,VANET and FANET: A Survey
PDF
Mobile Network Layer
Introduction To Wireless Fading Channels
localization in wsn
Device drivers and interrupt service mechanism
Pcs ch1
Signalling and telecommunication
Common protocols
Wlan architecture
Logical channels
Cw and fm cw radar
Leo satellite networks
Prediction of range performance
IPv4 Addressing
Wi-Fi Esp8266 nodemcu
Location Aided Routing (LAR)
Computer networks - Channelization
Intrusion Detection System
Security issues and challenges in MANET,VANET and FANET: A Survey
Mobile Network Layer
Ad

Viewers also liked (18)

PDF
Informatique verte des capteurs intelligents à la fouille de données - 2014-1...
PDF
Wireless humidity and temperature monitoring system
PDF
Fiche récapitulative des projets réalisés
PDF
Cours16 ressources pour arduino
PPTX
Présentation de projet de fin d’études
PDF
Présentation microprocesseur finale
PDF
ARDUINO + LABVIEW : CONTRÔLE DE LA TEMPÉRATURE
PPTX
présentation soutenance PFE 2016
PDF
Projet de fin d'etude :Control d’acces par empreintes digitale
ODP
Les systèmes embarqués arduino
PPTX
Présentation arduino
PPTX
Story Lab - Sensor Journalism [23-04-2015, Liège]
PDF
Exemple de-code-oop-avec-labview
PDF
« LabVIEW : programmation et applications » ou comment apprendre à utiliser L...
PDF
Techniques de programmation avancée LabVIEW : gestion des données de la local...
PDF
Introduction à l'IoT: du capteur à la donnée_Presentation Mix-IT2015
PDF
Yassine Otmane voiture commandée à distance (XBEE)
PDF
LabVIEW™ real time programing
Informatique verte des capteurs intelligents à la fouille de données - 2014-1...
Wireless humidity and temperature monitoring system
Fiche récapitulative des projets réalisés
Cours16 ressources pour arduino
Présentation de projet de fin d’études
Présentation microprocesseur finale
ARDUINO + LABVIEW : CONTRÔLE DE LA TEMPÉRATURE
présentation soutenance PFE 2016
Projet de fin d'etude :Control d’acces par empreintes digitale
Les systèmes embarqués arduino
Présentation arduino
Story Lab - Sensor Journalism [23-04-2015, Liège]
Exemple de-code-oop-avec-labview
« LabVIEW : programmation et applications » ou comment apprendre à utiliser L...
Techniques de programmation avancée LabVIEW : gestion des données de la local...
Introduction à l'IoT: du capteur à la donnée_Presentation Mix-IT2015
Yassine Otmane voiture commandée à distance (XBEE)
LabVIEW™ real time programing
Ad

Similar to Analog data transmission on rf module using arduino (20)

PPTX
WIRELESS GESTURED CONTROLLED ROBOT USING ACCELEROMETER
PDF
INT4073 L07(Sensors and AcutTORS).pdf
PDF
Internet of things laboratory
PPTX
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
PDF
Data Encoding for Wireless Transmission
PDF
Radio frequency identification system
PDF
ARDUINO (1).pdf
PDF
Ju2416921695
PDF
DOCX
Transmitting Digital Signal through Light Pulses
PDF
Arduino projects &amp; tutorials
PPTX
Monitoring temperature ruangan dengan display lcd
PPTX
Monitoring temperature rumah dengan display lcd dan recording
PPTX
Monitoring temperature rumah dengan display lcd dan recording
PPTX
Fire Fighter Robot with Night Vision Camera (1).pptx
PPTX
accelerometer based robot.pptx
PPTX
Monitoring temperature ruangan dengan display lcd
PPTX
Monitoring Temperature Room With Display LCD and Data Recording
PPT
Physical prototyping lab2-analog_digital
PPT
Physical prototyping lab2-analog_digital
WIRELESS GESTURED CONTROLLED ROBOT USING ACCELEROMETER
INT4073 L07(Sensors and AcutTORS).pdf
Internet of things laboratory
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
Data Encoding for Wireless Transmission
Radio frequency identification system
ARDUINO (1).pdf
Ju2416921695
Transmitting Digital Signal through Light Pulses
Arduino projects &amp; tutorials
Monitoring temperature ruangan dengan display lcd
Monitoring temperature rumah dengan display lcd dan recording
Monitoring temperature rumah dengan display lcd dan recording
Fire Fighter Robot with Night Vision Camera (1).pptx
accelerometer based robot.pptx
Monitoring temperature ruangan dengan display lcd
Monitoring Temperature Room With Display LCD and Data Recording
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital

Recently uploaded (20)

PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PDF
composite construction of structures.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Project quality management in manufacturing
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
DOCX
573137875-Attendance-Management-System-original
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ETO & MEO Certificate of Competency Questions and Answers
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
composite construction of structures.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Project quality management in manufacturing
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
OOP with Java - Java Introduction (Basics)
CH1 Production IntroductoryConcepts.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
573137875-Attendance-Management-System-original
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Road Safety tips for School Kids by a k maurya.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd

Analog data transmission on rf module using arduino

  • 1. Analog Data Transmission on RF Module Using Arduino 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. Name of component Required quantity 1 RF Tx module(434Mhz) 1 2 RF Rx 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
  • 2. Block Diagram - Circuit Diagram - Circuit Connections - 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.
  • 3. 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. LCD Arduino UNO RS 3 RW 2 E GRND D7,D6,D5,D4 7,6,5,4 respectively The standard code library for interfacing Arduino UNO and Arduino Pro Mini are used in the project to program LCD with the board.
  • 4. 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.
  • 5. 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. 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; char Sensor1CharMsg[4]; 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. void setup() { // PinModes // LED pinMode(ledPin,OUTPUT); // Sensor(s) pinMode(Sensor1Pin,INPUT); // for debugging
  • 6. Serial.begin(9600); // VirtualWire setup vw_setup(2000); // Bits per sec } 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() { // Read and store Sensor 1 data Sensor1Data = analogRead(Sensor1Pin); // Convert integer data to Char array directly itoa(Sensor1Data,Sensor1CharMsg,10); The readings stored in both the variable and the array are serially buffered using Serial.print() function. // DEBUG Serial.print("Sensor1 Integer: "); Serial.print(Sensor1Data); Serial.print(" Sensor1 CharMsg: "); Serial.print(Sensor1CharMsg); Serial.println(" "); delay(1000); // END DEBUG 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. digitalWrite(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);
  • 7. } // END void loop... At the receiver side, again VirtualWire library is imported to read analog data. #include <VirtualWire.h> 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. // LED's int ledPin = 13; // Sensors int Sensor1Data; // RF Transmission container char Sensor1CharMsg[4]; 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. void setup() { Serial.begin(9600); // sets the digital pin as output pinMode(ledPin, OUTPUT); 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. // 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();
  • 8. } // END void setup 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. void loop(){ uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; 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. // 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]); } 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. // 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] = '0'; // Convert Sensor1CharMsg Char array to integer
  • 9. Sensor1Data = atoi(Sensor1CharMsg); 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 visual indication that data has been successfully read and displayed. // DEBUG Serial.print("Sensor 1: "); Serial.println(Sensor1Data); // END DEBUG // Turn off light to and await next message digitalWrite(13, false); } } 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, 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. PROGRAMMING CODE #include <VirtualWire.h> // LED's const int ledPin = 13; // Sensors const int Sensor1Pin = A2; int Sensor1Data; char Sensor1CharMsg[4]; void setup() { // PinModes
  • 10. // 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 DEBUG digitalWrite(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 <VirtualWire.h> // LED's int ledPin = 13; // Sensors int Sensor1Data; // RF Transmission container char Sensor1CharMsg[4]; void setup() {
  • 11. 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 setup 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]); } // 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] = '0'; // Convert Sensor1CharMsg Char array to integer Sensor1Data = atoi(Sensor1CharMsg);
  • 12. // DEBUG Serial.print("Sensor 1: "); Serial.println(Sensor1Data); // END DEBUG // Turn off light to and await next message digitalWrite(13, false); } }