Problems with Coding? Help! -Transmitter& Receiver

I have a transmitter and receiver sending signals to each other based on what the number the transmitter sends i want the lcd to print a different message. I want "0" to mean "Hi" and "1" to mean "O.O". I am worried about the way i'm writing it, any advice? I've tried writing it with a switch case, but it wasn't working.

LiquidCrystal lcd(12, 8, 5, 4, 3, 2);
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
const int threshold = 1;
int sensorReading= 0;
int sensorPin = 11;     //Try 11

void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
lcd.begin(16, 2);
  // Print a message to the LCD.
}
void loop()

{
if (vw_get_message(message, &messageLength)) // Non-blocking
{int sensorReading = analogRead(sensorPin);    //try digitalRead w/d11 or analogRead A0

if (sensorReading = threshold){
 lcd.setCursor(0, 1);
    lcd.print("O.O");
    delay(1);
    }
 if (sensorReading = sensorReading){
  lcd.setCursor(0, 1);
    lcd.print("Hi!");
    delay(1);
    } 
 }
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}}

Try changing "=" to "==" and see if that helps. They are not the same!!!!

Paul

thank you, but which one should i change? them all?

Sr654407:
thank you, but which one should i change? them all?

These ones:

if (sensorReading = threshold){
 if (sensorReading = sensorReading){

For information on the difference between = and == see http://www.arduino.cc/en/Reference/Assignment.

I tried it, and still no luck in recognizing the different messages :frowning:

#include <LiquidCrystal.h>
#include <VirtualWire.h>
LiquidCrystal lcd(12, 8, 5, 4, 3, 2);
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
const int threshold = 1;
int sensorReading = 0;
int sensorPin =11;     //Try 11

void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
lcd.begin(16, 2);
  // Print a message to the LCD.
}
void loop()

{
if (vw_get_message(message, &messageLength)) // Non-blocking
{int sensorReading = analogRead(sensorPin);    //try digitalRead w/d11 or analogRead A0

if (sensorReading == threshold){
 lcd.setCursor(0, 1);
    lcd.print("Hi");
    delay(1);
    }
 if (sensorReading == sensorReading){
  lcd.setCursor(0, 1);
    lcd.print("O.O");
    delay(1);
    } 
 }
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}}

What board are you using? Pin 11 is not an analog input on the UNO.

You aren't thinking that you can read the radio using analogRead, I hope? :slight_smile:

Arduino nano, and yeah I had it digital read before and on pin 11 but it wasn't working so i was trying different things based on examples.