RF LCD issues

I have a ten button remote I built with an arduino mini which is used to control a model home with an arduino mega in it. I am using a cheap RF transmitter/receiver and virtual wire. Everything is working fine but when I add an lcd to the home it doesnt work right. The point is to push a button and increase the number on screen by one. Instead the number twitches and buttons do nothing. I can get the lcd to work on its own just fine, but it seems to pick up on the RF communications when the two are together. Can anyone help me, I have been at this for months and cant figure it out. I cut out some things in the middle to make it fit here, but nothing important.

//Transmitter//
#include <VirtualWire.h>
const int Lights1 = 2; //input pin 2 for pushbutton
const int Lights2 = 3; //input pin 3 for pushbutton
const int Lights3 = 4; //input pin 4 for pushbutton
const int Lights4 = 5; //input pin 5 for pushbutton
const int Air = 7; //choose pin 49 for pushbutton
const int Airup = 10;
const int Airdown = 11;
const int Alarm = 8; //Choose pin 48 for arm/disarm button

int Lights1State = 0; //will be used to store the state of the input pin
int oldLights1State = 0; //this variable stores the previous value of the button state
int led1State = 0; //0= LED Off and 1 = LED on
int Lights2State = 0; //will be used to store the state of the input pin
int oldLights2State = 0; //this variable stores the previous value of the button state
int led2State = 0; //will be used to store the state of the input pin
int Lights3State = 0; //will be used to store the state of the input pin
int oldLights3State = 0; //this variable stores the previous value of the button state
int led3State = 0; //0= LED Off and 1 = LED on
int Lights4State = 0; //will be used to store the state of the input pin
int oldLights4State = 0; //this variable stores the previous value of the button state
int led4State = 0; //0= LED Off and 1 = LED on
int AirState = 0; //will be used to store the state of the input pin
int oldAirState = 0; //this variable stores the previous value of the button state
int ACState = 0; //0= LED Off and 1 = LED on
int AirupState = 0; //will be used to store the state of the input pin
int oldAirupState = 0; //this variable stores the previous value of the button state
int ACupState = 0; //0= LED Off and 1 = LED on
int AirdownState = 0; //will be used to store the state of the input pin
int oldAirdownState = 0; //this variable stores the previous value of the button state
int ACdownState = 0; //0= LED Off and 1 = LED on
int AlarmState = 0; //will be used to store the state of the input pin
int oldAlarmState = 0; //this variable stores the previous value of the button state
int ArmedState = 0; //0= LED Off and 1 = LED on
char *mymessage;

void setup(){

pinMode(Lights1, INPUT); //declare switchA as input
pinMode(Lights2, INPUT); //declare switchB as input
pinMode(Lights3, INPUT); //declare switchC as input
pinMode(Lights4, INPUT); //declare switchD as input
pinMode(Air, INPUT); //declare pushbutton as input
pinMode(Airup, INPUT); //declare switchD as input
pinMode(Airdown, INPUT); //declare pushbutton as input
pinMode(Alarm, INPUT); //declare pushbutton as input

vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);} // Bits per sec
void loop(){

AirState = digitalRead(Air);{ //read and store the button state fresh
if ((AirState == HIGH) && (oldAirState == LOW)) {
ACState = 1 - ACState;
delay(10);}

oldAirState = AirState; //store this state for later
if(ACState == 1){
mymessage = “I”;}
else {
mymessage = “J”;}

vw_send((uint8_t *)mymessage, strlen(mymessage));
vw_wait_tx(); // Wait until the whole message is gone
delay(50);}

AirupState = digitalRead(Airup);{ //read and store the button state fresh
if ((AirupState == HIGH) && (oldAirupState == LOW)) {
delay(10);}

oldAirupState = AirupState; //store this state for later
if(AirdownState = 1){
mymessage = “K”;}

vw_send((uint8_t *)mymessage, strlen(mymessage));
vw_wait_tx(); // Wait until the whole message is gone
delay(50);}

AirdownState = digitalRead(Airdown);{ //read and store the button state fresh
if ((AirdownState == HIGH) && (oldAirdownState == LOW)) {
delay(10);}

oldAirdownState = AirdownState; //store this state for later
if(AirdownState = 1){
mymessage = “L”;}

vw_send((uint8_t *)mymessage, strlen(mymessage));
vw_wait_tx(); // Wait until the whole message is gone
delay(50);}

AlarmState = digitalRead(Alarm);{ //read and store the button state fresh
if ((AlarmState == HIGH) && (oldAlarmState == LOW)) {
ArmedState = 1 - ArmedState;
delay(10);}

oldAlarmState = AlarmState; //store this state for later
if(ArmedState == 1){
mymessage = “M”;}
else {
mymessage = “N”;}

digitalWrite(13, true);
vw_send((uint8_t *)mymessage, strlen(mymessage));
vw_wait_tx();
delay(50);}}

//Receiver//
#define LCD //compile NewSoftSerial LCD code
#ifdef LCD
#include <NewSoftSerial.h>
NewSoftSerial serLCD(255, 18); //tx only
#endif

#define lcdcmd 0xFE //command prefix
#define clrLCD 0x01 //Clear entire LCD screen

#include <VirtualWire.h>

char inString[32];
int inCount;
int buttonpress = 75;
const int LCDdelay=10;
const int ledAPin = 22; //choose pin 22 for led
const int ledBPin = 23; //choose pin 23 for led
const int ledCPin = 24; //choose pin 24 for led
const int ledDPin = 25; //choose pin 25 for led
const int fanAPin = 30; //output pin for fanA
const int fanBPin = 31; //output pin for fanB
const int speakerPin = 7; //Choose pin 7 for speaker
int ledPins = {26,27,28,29};
int sensorPin = {2,3,4};

void setup(){

pinMode(ledAPin, OUTPUT); //declare ledA as ouput
pinMode(ledBPin, OUTPUT); //declare ledB as ouput
pinMode(ledCPin, OUTPUT); //declare ledC as ouput
pinMode(ledDPin, OUTPUT); //declare ledD as ouput
pinMode(fanAPin, OUTPUT); //declare fanA as ouput
pinMode(fanBPin, OUTPUT); //declare fanB as ouput
digitalWrite(fanAPin, OUTPUT);
for(int indexA = 0; indexA < 3; indexA++) {
pinMode(sensorPin[indexA], INPUT);} //declare sensor A as input
pinMode(speakerPin, OUTPUT); //declare speaker as output
for(int index = 0; index < 4; index++){
pinMode(ledPins[index], OUTPUT);}

#ifdef LCD //setup serial LCD
serLCD.begin(9600);
delay(1000);
serLCD.print(lcdcmd, BYTE);
serLCD.print(displayOn , BYTE);
serLCD.print(lcdcmd, BYTE);
serLCD.print(clrLCD, BYTE);
serLCD.print(“Hello”);
#endif

Serial1.begin(9600);
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(14);
vw_setup(2000); // Bits per sec
vw_rx_start();} // Start the receiver PLL running

void loop(){

char text [50];
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
inCount = 0;

if (vw_get_message(buf, &buflen)){ // Non-blocking
int i;
for (i = 0; i < buflen; i++){
inString[inCount] = buf*; // this fixed it !*

  • inCount++;}*

  • if (strcmp(inString, “I”) == 0){*

  • digitalWrite(30, LOW);*

  • digitalWrite(31, LOW);}*

  • if (strcmp(inString, “J”) == 0){*

  • digitalWrite(30, HIGH);*

  • digitalWrite(31, HIGH);}*

  • if (strcmp(inString, “K”) == 0){*

  • buttonpress++;*

  • #ifdef LCD*

  • serLCD.print(lcdcmd, BYTE);*

  • serLCD.print(clrLCD, BYTE);*

  • serLCD.print(“Temp:”);*

  • serLCD.print(buttonpress);*

  • #endif*

  • delay(10);}*

  • if (strcmp(inString, “L”) == 0){*

  • buttonpress–;*

  • #ifdef LCD*

  • serLCD.print(lcdcmd, BYTE);*

  • serLCD.print(clrLCD, BYTE);*

  • serLCD.print(“Temp:”);*

  • serLCD.print(buttonpress);*

  • #endif*

  • delay(10);}*

  • for(int indexA = 0; indexA < 3; indexA++){*

  • if (strcmp(inString, “M”) == 0){*

  • digitalWrite(sensorPin[indexA], LOW);}*

  • digitalWrite(speakerPin, LOW);}*

  • if (strcmp(inString, “N”) == 0){*

  • digitalWrite(sensorPin[indexA], HIGH);*

  • int valA = digitalRead(sensorPin[indexA]);*

  • if(valA == LOW){*

  • digitalWrite(speakerPin, HIGH);}*

  • for(int index = 0; index < 4; index++){*

  • int valB = digitalRead(speakerPin);*

  • if(valB == HIGH){*

  • digitalWrite(ledPins[index], HIGH); *

  • delay(50); *

  • digitalWrite(ledPins[index], LOW); *

  • delay(50);}}}}}}*

Please modify you post, select the code and press the # button to make code look like code.

Furthermore use the CTRL-T in the IDE to get automatic indentation, that makes the code better readable,

thanks, Rob

I'm sorry, I'm really new to this and I'm not sure what I need to change to make it look right. Would it make it easier to figure out whats wrong?? Thanks

Come on guys, PLEASE. I really need this to work. Any suggestions. I think it's in the serial communications, but I'm not sure. PLEASE PLEASE PLEASE any help is appreciated, thank you.

I found a little mistake on your code. You declared pin 7 as output but trying to read.

const int speakerPin = 7;   //Choose pin 7 for speaker

pinMode(speakerPin, OUTPUT);  //declare speaker as output

int valB = digitalRead(speakerPin);

It is not a mistake. The speaker is an output, and if it is on then led lights start flashing. If the speaker is off, the lights turn off.I am reading the output to turn on another output.

Ok, well it's starting to get down to the wire. I kinda need to get this completed soon, so $50.00 goes to whoever can fix my issue. I really am stumped and can't find anything online that helps. Transmit button press and display on receiver Serial LCD. I will mail check or paypal it. This is my last option....... Thank you.

I am using a cheap RF transmitter/receiver ...

... but it seems to pick up on the RF communications ...

It looks like the (serial) wires going to your LCD are acting like an antenna and the resulting interference is being interpreted as a command to the LCD controller or to the microprocessor on the serial LCD controller. You could start by rerouting and/or shielding the wires. A more drastic step would be to switch to an I2C interface or even a straight parallel interface if you have available pins.

Don

Did you manage to get this sorted? It seems like the same problem that I am having - I am trying to send various messages from one Arduino to another. I have set up one with four buttons, an LCD and a an RF transmitter. I'm using the Virtual Wire library. When an individual button is pressed, I want a corresponding message to appear on the LCD and the transmitter to transmit that message. I can get the messages to display on the LCD but when I add the code for the transmitter, the messages don't display (they are still sent via RF). By systematically commenting out code I have narrowed the problem down to this line :

vw_setup(2000);

This sets bits per second for transmitting. When this line is commented out, the LCD displays the messages. When not commented out, the messages don't appear on the LCD. I'm using a 16x2 LCD.

I think you forgot to differentiate the colon in line 37... or was it 38?..