# Ultrasonic Sensor-Transmitting & Receiving Data wirelessly

**URL:** <https://community.sparkfun.com/t/ultrasonic-sensor-transmitting-receiving-data-wirelessly/30958>\
**Category:** Wireless & IoT\
**Created:** [May 25, 2015, 9:10am UTC](https://community.sparkfun.com/t/ultrasonic-sensor-transmitting-receiving-data-wirelessly/30958 "2015-05-25T09:10:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siyath](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Siyath](https://community.sparkfun.com/u/Siyath)\
**Post date:** [May 25, 2015, 9:10am UTC](https://community.sparkfun.com/t/ultrasonic-sensor-transmitting-receiving-data-wirelessly/30958/1 "2015-05-25T09:10:00Z")

</div>

Hey,

I want to show the measured distance wirelessly from Ultrasonic Sensor (HC-SR04) which is connected to a Arduino Uno to another Arduino board which is connected to a LCD . I’m using a 433MHz Transmitter and Receiver.

I’m not getting the distance data on my LCD.

_My Transmitter is connected to the Arduino+Ultrasonic Sensor, Receiver is connected to the Arduino+LCD_

TX

// Ground Station Code

#include\<VirtualWire.h\>

#define trigPin 12

#define echoPin 13

const int transmit\_pin = 11;

const int receive\_pin = 0;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

// Initialise the IO and ISR

vw\_set\_tx\_pin(transmit\_pin);

vw\_set\_rx\_pin(receive\_pin);

//vw\_set\_ptt\_pin(transmit\_en\_pin);

vw\_set\_ptt\_inverted(true); // Require

vw\_setup(2000); // Bits per sec

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration / 2) / 29.1;

if (distance \>= 400 || distance \<= 2) {

Serial.println(“Out of range”);

}

else {

Serial.print(distance);

Serial.println(" cm");

}

delay(500);

char msg = ‘h’;

vw\_send((uint8\_t \*)msg, 1);

vw\_wait\_tx(); // Wait until the whole message is gone

}

RX

// Aircraft Code-RX

#include\<VirtualWire.h\>

#include \<LiquidCrystal.h\>

const int transmit\_pin = 11;

const int receive\_pin = 12;

//const int transmit\_en\_pin = 3;

byte message[VW\_MAX\_MESSAGE\_LEN]; // a buffer to store the incoming messages

byte messageLength = VW\_MAX\_MESSAGE\_LEN; // the size of the message

LiquidCrystal lcd(10,9,5,4,3,2); //create liquid crystal object called LCD

// Variables globales:

char cad[100];

int pos = 0;

void setup()

{

lcd.begin(20, 4); // LCD Configuration, 4 línes 20 characters cada una.

lcd.setCursor(0, 0);

lcd.write(“Booting”);

delay(1000);

pos=0;

lcd.clear();

lcd.write(“Loading code”);

delay(1000);

pos=0;

lcd.clear();

lcd.write(“.”);

delay(900);

lcd.write(“.”);

delay(900);

lcd.write(“.”);

delay(900);

pos=0;

lcd.clear();

lcd.write(“Instructables”);

delay(900);

Serial.begin(9600);

Serial.println(“Device is ready”);

// Initialize the IO and ISR

vw\_set\_tx\_pin(transmit\_pin);

vw\_set\_rx\_pin(receive\_pin);

//vw\_set\_ptt\_pin(transmit\_en\_pin);

vw\_set\_ptt\_inverted(true); // Required for DR3100

vw\_setup(2000); // Bits per sec

vw\_rx\_start(); // Start the receiver PLL running

}

void loop()

{

uint8\_t buf[VW\_MAX\_MESSAGE\_LEN];

uint8\_t buflen = VW\_MAX\_MESSAGE\_LEN;

int i;

int k= VW\_MAX\_MESSAGE\_LEN;

if (vw\_get\_message(buf, &buflen)) // Non-blocking

{

Serial.print("Received: ");

for (int i = 0; i \< buflen; i++)

{

Serial.write(buf\*);\*  
_}_  
_Serial.println();_  
_}_  
_if( vw\_get\_message(buf, &buflen) )_  
_{_  
_if(pos \< 4)_  
_lcd.setCursor(0, pos);_  
_else_  
_{_  
_pos=0;_  
_lcd.clear();_  
_}_  
_lcd.write(“Distance:”);_  
_for (i = 0; i \< buflen; i++)_  
_{_  
_lcd.write(buf);_  
 _pos++;  
 }  
 lcd.write(“cm”);// CM  
 }  
 }  
 PLEASE Help me… and advice me what is wrong with my code… Thank you!_
