RF 433MHz RX, TX & IR breakbeam circuit.

Howdy all,

My project is a footfall counter. I have an IR break beam sensor at the front of the shop, when a person passes thorough, itll detect it and send it to a monitor device at the back of the shop. At the start of the day, a sales assistant enters the expected amount of customers - like a target - and each time the a customer passes through, the number entered at opening time is deducted. There’s gonna be two sensors sending data at a later stage but for now the IR one is the most important.

Currently, I have both my devices working individually. I have my IR circuit detecting when a person comes in and lights an LED on my monitor device. This was for testing the RF worked.

My question is, can anyone recommend the best way to go about the deduction once the info is passed to the monitor device? An interrupt maybe? currently I have a section of code written where I ‘deduct’ from the input number when the message is received, but it doesn’t seem to be working. My coding is still a work in progress so please excuse that.

Monitor device:

//Libraries Included in sketch
#include <VirtualWire.h>
#include<Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>


//LCD Display Declarations
const int rows = 4;
const int cols= 20;
//test LED
int ledR = 13;

//Keypad Declarations
const byte keyRows = 4;
const byte keyCols= 3;

//Define i2c address
#define I2C_ADD 0x27
#define B_light 3

//Display Variables
#define d4  4
#define d5  5
#define d6  6
#define d7  7
#define EN  2
#define RW  1
#define RS  0

//Initlize LCD
LiquidCrystal_I2C  lcd(I2C_ADD, EN, RW, RS, d4, d5, d6, d7);

//Array for keypad
char keys[keyRows][keyCols] = 

  {{'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'},};


//Battery variable Declarations
int voltDiv = A0;
int divider;
int vRef=10;
int valNew = 0;
int percentVolt=0;
float voltage;

//LCD battery display
byte battery[8] = 
{
0b00100,
0b01110,
0b01110,
0b01110,
0b01110,
0b01110,
0b01110,
0b01110
};


//Arduino pins keypad is connected to
byte rowPins[keyRows] = {5,6,7,8};
byte colPins[keyCols] = {2,3,4};

Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,keyRows,keyCols);

int count = 0;
char keyNew[3];
int amount;

void setup()
{
  pinMode(ledR, OUTPUT);
  //LCD settings
  lcd.setBacklightPin(B_light,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.begin(20,4);
  lcd.print( "WELCOME");
  delay(2000);
  lcd.clear();
 
  //RX setup
 vw_set_ptt_inverted(true);
 vw_set_rx_pin(12);
 vw_setup(4000);
 
 vw_rx_start();
 
 
 
}

void loop()
{
 //Battery Function call 
 batteryDisplay();
 
//RX code
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;


//Message recieved 
 if(vw_get_message(buf, &buflen))
  {
    if(buf[0] == '1')
    {
      //Turn on LED
      digitalWrite(ledR, HIGH);

//Subtract when a person passes
      amount = amount - 1;
      lcd.print(amount);*/
    }
  
 if(buf[0] == '0')
 {
 digitalWrite(ledR, LOW);
 }
  }
 //Setup Display code
  lcd.setCursor(0,1);
  lcd.print("Plese Enter");
  lcd.setCursor(0,2);
  lcd.print("expected count:");
  amount = GetCust();
  lcd.print(amount);
  
  

  
}

int GetCust()
{
  char key=keypad.getKey();
  int n;
  int count = 0;
  
  for(n=0;n<3;n++)
  {
    keyNew[n] = keypad.waitForKey();
    lcd.print(keyNew[n]);
    count++;
  }
  
  while(count==3)
  {
    char key= keypad.getKey();
    if (key == '#')
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("******************");
      lcd.setCursor(0,1);
      lcd.print("***** Stored *****");
      lcd.setCursor(0,2);
      lcd.print("******************");
      lcd.setCursor(0,3);
      lcd.print("******************");
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Customers Left:");
      lcd.setCursor(10,1);
      lcd.print(keyNew);
     
    
    
    }
  }
}
  
void batteryDisplay(void)
{
  
  lcd.createChar(0, battery);
  lcd.setCursor(15, 0);
  lcd.write((uint8_t)0);
  divider = analogRead(voltDiv);
  voltage = (divider*vRef)/1023;
  percentVolt = voltage/5*100;
  lcd.setCursor(16,0);
  lcd.print(percentVolt);
  lcd.print("%");
  delay(1000);
}

IR ckt:

//RF library
#include <VirtualWire.h>

//Varible Declarations
int ledBlu = 13;
int sensor_IR = 4;

int sensorValue = 0;
int lastState = 0;

char *msg;


//Set up functions
void setup ()
{
  
  pinMode(ledBlu, OUTPUT);
  pinMode(sensor_IR, INPUT_PULLUP);
  Serial.begin(9600);
  
  vw_set_ptt_inverted(true); //Push to talk protocol
  vw_set_tx_pin(12);    //set tx pin 12
  vw_setup(000);      //speed of data transfer

}

void loop ()
{
 sensorValue = digitalRead(sensor_IR);

//Check if the beam is broken
if(sensorValue == LOW)
{
  digitalWrite(ledBlu, HIGH);
  
  //this is the message
  msg = "1";
  //send the message
  vw_send((uint8_t *)msg, strlen(msg));
  //wait until all message is sent
  vw_wait_tx();
 
 msg = "0";
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx();
  
}
  
  


else
{
  
  digitalWrite(ledBlu, LOW);
}
}