SEND ANALOG DATA VIA RF433

RF analog tr

#include <VirtualWire.h>
#define txPowerPin 8
// LED’s
const int ledPin = 13;

// Sensors
const int Sensor1Pin = A2;
// const int Sensor2Pin = 3;

int Sensor1Data;
//int Sensor2Data;
char Sensor1CharMsg[4];

void setup() {
pinMode(txPowerPin, OUTPUT);
pinMode(txPowerPin, LOW);
// PinModes
// LED
pinMode(ledPin,OUTPUT);
// Sensor(s)
pinMode(Sensor1Pin,INPUT);

// for debugging
Serial.begin(9600);

// VirtualWire setup
vw_setup(2000); // Bits per sec
vw_set_tx_pin(12); // VirtualWire transmit pin
}

void loop() {
digitalWrite(txPowerPin, HIGH);
// 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
digitalWrite(txPowerPin, LOW);
delay(2000);

} // END void loop…

 

RF analog rcv

RECEIVER

#include <VirtualWire.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
/*
For details about the LCD display with I2C support see
http://www.fasttech.com/reviews/1380909/22072
and
http://dx.com/p/funduino-iic-i2c-1602-lcd-adapter-board-w-2-5-lcd-screen-black-green-red-173588
The reviewer comments by docpayce and particularly JackWP associated with the two product pages above have been very useful.

Connect the LCD: VCC -> 5V, GND -> GND, SDA -> A4 (PortC4, ADC4), SCL -> A5 (PortC5, SDA)

The LiquidCrystal_I2C library needs to be downloaded and installed from here: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
*/

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;

// LED’s
int ledPin = 13;

// Sensors
int Sensor1Data;

// RF Transmission container
char Sensor1CharMsg[4];

void setup() {
Serial.begin(9600);
lcd.begin(16,2); // initialize the lcd
lcd.home ();
// 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();
vw_set_rx_pin(2);

} // 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);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“SensorData = “);
lcd.setCursor(0, 1);
lcd.print(Sensor1Data);

// END DEBUG

// Turn off light to and await next message
digitalWrite(13, false);
}
}