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);}}}}}}*