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!