Need help on writing a receiver code

I’m new on Arduino community. I’m building a project that read’s temperature and transmit with 433rf and is suppose to receive and display on lcd.

The temperature is showing on serial monitor but I can’t receive it on the receiver part.

this is the code for the transmitting

#include <VirtualWire.h>
const int lm35_pin = A0;
const int transmit_pin = 12;
const int led_pin = 3;
const int analogInPin = A0; // Analog input pin that the temperature is connected to
int sensorValue = 0; // value read from the pot
char msg[6]; // set message character

void setup ()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second
vw_setup(2000) ; // Bits per sec
vw_set_tx_pin(12) ; // sets the transmitter pin as digital pin 3
pinMode(12, OUTPUT) ; //
}
void loop() {
int temp_adc_val;
float temp_val;
temp_adc_val = analogRead(lm35_pin);
temp_val = (temp_adc_val * 0.289);
temp_val = (temp_val/10);
digitalWrite(3, HIGH); // turns the LED on
delay(2000); // waits for a second
digitalWrite(3, LOW); // turn the LED off
delay(2000); // waits for a second
vw_send ((uint8_t)msg, strlen(msg)) ;
vw_wait_tx () ;
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print("Degree Celsius\n");
delay (2000);

}

i am having difficulty in writing the receiver code for it to display on the lcd.

i will be happy if anyone can put me through

this is the receiver code but i am not receiving anything and the lcd is not displaying anything

#include <Wire.h>
#include <VirtualWire.h> // calls the virtualwire library
#include <LiquidCrystal.h> // calls the lcd library
float temp; // declares float variable temp
int tempPin = A0; // declares input receiver data pin as pin 2
int i; // declares integer value i
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd (rs, en, d4,d5, d6, d7); // state the lcd pins used

void setup()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
lcd.begin(16,2); // set up LCD's number of columns and rows:
vw_setup(2000); //Bits per second
vw_rx_start () ; // starts the virtual wire
vw_set_rx_pin(A0); // sets the receiver pin as digital 2
}
void loop(){
int temp_adc_val;
float temp_val;
vw_rx_start () ;
vw_wait_rx ();
uint8_t buf[VW_MAX_MESSAGE_LEN]; // shows the mode/pattern which the received signal takes in the format "encode carrier[real message value]"
uint8_t buflen = VW_MAX_MESSAGE_LEN; //identifies the message from the encoded carrier and seperates the encoded carrier and real value
int fah = 0; //initializes the integer value of farenheit temperature value to zero
char fahStr[6];
temp_adc_val = analogRead(A0);
temp_val = (temp_adc_val * 0.289);
temp_val = (temp_val/10);
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print("Degree Celsius\n"); // declares the buffer length of the received farenheit temperature value
if(vw_get_message(buf, &buflen)) // begins the decryption process
{
lcd.clear(); // clear the lcd
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Temperature="); // Print a message to the LCD
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
for (i=0; i<buflen; i++); // begins the initialization of the serial transmission
{
lcd.write(buf[i]); // writes the temperature value in centrigade
fah = fah * 10 + (buf[i] - 48); // rewrites the centigrade value to the original volatage value gotten from the LM35DZ sensor

}{
  lcd.print((char)223); // prints the degree sysmbol from the ascii character code
  lcd.print("C"); // prints character 'C'
  fah = ((9 * fah) / 5) + 32; //formular for converting the centigrage value to farenheit 
  dtostrf (fah, 2,0, fahStr); // converts decimal to string function
  for (i=0; i < buflen; i++);
}
    {
      lcd.write(fahStr[i]); // prints the temperature in farenheit on the LCD display
    }{
lcd.print((char)223); // prints the degree symbol from the ascii character code
lcd.print("F"); // prints the character 'F'

}}}

pls change you posts and place every code between code tags

#include <VirtualWire.h> // calls the virtualwire library
#include <LiquidCrystal.h> // calls the lcd library
//float temp; // declares float variable temp
//int tempPin = A0; // declares input receiver data pin as pin 2
int i; // declares integer value i
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd (rs, en, d4, d5, d6, d7); // state the lcd pins used

void setup()
{
  //Serial.begin(9600); // initialize serial communication at 9600 bits per second:
  lcd.begin(16, 2); // set up LCD's number of columns and rows:
  vw_setup(2000); //Bits per second
  vw_rx_start () ; // starts the virtual wire
  vw_set_rx_pin(A0); // sets the receiver pin as digital 2
  lcd.clear(); // clear the lcd
  lcd.print("Temperature="); // Print a message to the LCD
}
void loop() {
  vw_wait_rx ();
  char buf[VW_MAX_MESSAGE_LEN]; // shows the mode/pattern which the received signal takes in the format "encode carrier[real message value]"
  uint8_t buflen = VW_MAX_MESSAGE_LEN; //identifies the message from the encoded carrier and seperates the encoded carrier and real value

  //float temp_val = (analogRead(A0) * 0.0289);
  //Serial.print("Temperature = ");
  //Serial.print(temp_val);
  //Serial.print("Degree Celsius\n"); // declares the buffer length of the received farenheit temperature value
  if (vw_get_message(buf, &buflen)) // begins the decryption process
  {
    lcd.setCursor(0, 1); // set the cursor to column 0, line 1
    lcd.print(buf); // writes the temperature value in centrigade
    lcd.print((char)223); // prints the degree sysmbol from the ascii character code
    lcd.print("C  "); // prints character 'C'
    delay(50);
  }
}

when bottom of LCD does not show the number and °C then it is nothing to receive

I moved your topic to an appropriate forum category @shadow49.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I thin you have to call the vw_set_rx_pin before calling vw_setup ( or your your pin will not be set as input ), poor library documentation/examples.
It seems you are using A0 as rx pin and analog input pin??

thank you.
i will try to be putting codes under tag

yes, i am using A0

i have been trying to rewrite the code but i am just stuck. if you can help make corrections, that will be great

thank you.

1 Like

1 click "Edit this post" mark all text in post, then:

You are using A0 for both functions ( rx and analog read )?

No

I’ve been able to get it right but I still can’t get the value of the temperature on the lcd

what doing you to reach this? it is 4 days ago, what did you done in this time?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.