Using Grove for Wireless Communication

Hi everyone,

I'm currently doing a project, where I using the following components:

  • Matrix Keypad(4x4) x 2
  • LCD panel (16,2) x 1
  • Arduino Uno x 2
  • Base shield x 2
  • Potentiometer 10k x 1
  • Grove buzzer v1.1b x 1
  • Grove transmitter 315MHz x 1
  • Grove receiver 315MHz x 1

My project is two devices.

Device A: Matrix Keypad (4x4), LCD panel (16,2), Arduino Uno, Base Shield, Potentiometer, Grove transmitter 315MHz

Device B: Matrix Keypad (4x4), Arduino Uno, Base Shield, Grove receiver 315MHz

Basically, I want my Device A to transmit the input from Keypad (e.g. 1234). And when Device B to receive the same input from Keypad (e.g. 1234). Once the Device B matched with Device A, the output for the Device B (Buzzer) will sound.

The problem I'm facing now is my wireless communication are unable to communicate with each another. And I couldn't solve the problems. I hope you can help me to solve my problem.

Here is my coding that I had done:

Device A

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <VirtualWire.h>

const byte Rows= 4;
const byte Cols= 4;
LiquidCrystal lcd (8, 9, 10, 11, 12, 13);
char keymap[Rows][Cols]=
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

char busnumber[4];
byte rowPins[Rows]= {7, 6, 5, 4};
byte rowCols[Cols]= {18, 17, 16, 15};
int i = 0;
boolean repeat = 0;
int RF_TX_PIN = 1;
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, rowCols, Rows, Cols);

void setup()
{
  //Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(4,0);
  lcd.print("Welcome");
  lcd.setCursor(2,1);
  lcd.print("Bus Captain");
  delay(500);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Drive Safely");
  lcd.setCursor(0,1);
  lcd.print("Have a nice day!");
  delay(500);
  lcd.clear();
  lcd.setCursor(1,0);
  lcd.print("Enter your bus");
  lcd.setCursor(14,1);
  lcd.print("]");
  lcd.setCursor(1,1);
  lcd.print("service [");
  vw_set_tx_pin(1);
  vw_setup(2000);
}

void loop()
{
  int j = 0;
  char key= myKeypad.getKey();
  {
    if (key != 0)
    {
      //Serial.print(key);
      
      switch(key)
      {
        case 'A':
        break;
        
        case 'B':
        i--;
        lcd.setCursor(10 + i,1);
        lcd.print(" ");
        lcd.setCursor(10 + i,1);
        break;
        
        case 'C':
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("Enter your bus");
        lcd.setCursor(14,1);
        lcd.print("]");
        lcd.setCursor(1,1);
        lcd.print("service [");

        while (j<4)
        {
          busnumber[j] = 0;
          lcd.print(busnumber[j]);
          j++;
        }
        lcd.setCursor(10,1);
        i = 0;
        break;
        
        case 'D':
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Transmitting bus");
        lcd.setCursor(4,1);
        lcd.print("[");
        lcd.setCursor(11,1);
        lcd.print("]");
        lcd.setCursor(5,1);
        lcd.print(busnumber);
        while (!repeat < 100)
        {
          vw_send((uint8_t *)busnumber, 1);
          delay(500);
          repeat++;
        }
        break;
        
        case '*':
        break;
        
        case '#':
        break;
        
        default:
        
        if (i > 3)
        {
          i = 0;
          lcd.setCursor(10,1);
        }
        busnumber[i] = key;
        lcd.print(busnumber[i]);
        i++;
        break;
      }
    }
  }
  vw_send((uint8_t *)busnumber, 1);
  delay(150);
}

Device B

#include <Keypad.h>
#include <VirtualWire.h>

const byte Rows = 4;
const byte Cols = 4;
char keymap[Rows][Cols]=
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

char busnumber[4];
byte rowPins[Rows]= {4,5,6,7};
byte rowCols[Cols]= {8,9,10,11};

int i = 0;
boolean repeat = 0;
int RF_RX_PIN = 0;
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, rowCols, Rows, Cols);

void setup()
{
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  Serial.println("SETUP IN PROGRESS...");
  delay(1000);
  Serial.println("SETUP COMPLETE!");
  Serial.println("ENTER YOUR BUS NUMBER");
  vw_set_rx_pin(0);
  vw_setup(2000);
  vw_rx_start();
}

void loop()
{
  int j = 0;
  char key= myKeypad.getKey();
  if (key != 0)
  {
    switch (key)
    {
      case 'A':
      Serial.println("-");
      break;
      
      case 'B':
      Serial.println("-");
      break;
      
      case 'C':
      while (j < 4)
      {
      busnumber[j] = 0;
      Serial.print(busnumber[j]);
      Serial.println("CLEAR");
      j++;
      }
      i = 0;
      break;
      
      case 'D':
      while (!repeat < 5)
      {
        Serial.println("RECEIVING...");
        delay(3000);
        uint8_t buf[VW_MAX_MESSAGE_LEN];
        uint8_t buflen = VW_MAX_MESSAGE_LEN;
        if(vw_get_message(buf, &buflen))
        {
          digitalWrite(4, HIGH);
          delay(1000);
          digitalWrite(4, LOW);
          delay(1000);
          digitalWrite(4, HIGH);
          delay(1000);
          digitalWrite(4, LOW);
          delay(1000);
          digitalWrite(4, HIGH);
          delay(1000);
          digitalWrite(4,LOW);
          Serial.println("BUS IS ARRIVING");
        }
        else
        {
          digitalWrite(4, LOW);
        }
        int i;
        for (i = 0; i < buflen; i++);
        repeat++;
      }
        break;
      
      case '*':
      Serial.println("-");
      break;
      
      case '#':
      Serial.println("-");
      break;
      
      default:
      if (i > 3)
      {
        Serial.println("/");
        i = 0;
      }
      
      busnumber[i] = key;
      Serial.print(busnumber[i]);
      i++;
      break;
    }
  }
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if(vw_get_message(buf, &buflen))
  {
    digitalWrite(4, HIGH);
    delay(1000);
    digitalWrite(4, LOW);
    delay(1000);
    digitalWrite(4, HIGH);
    delay(1000);
    digitalWrite(4, LOW);
    delay(1000);
    digitalWrite(4, HIGH);
    delay(1000);
    digitalWrite(4, LOW);
    Serial.print("BUS IS ARRIVING");
  }
  else
  {
    digitalWrite(4, LOW);
  }
  int i;
  for (i = 0; i < buflen; i++);
}

Post a link to the datasheets for your wireless devices.

Was there a demo program with them?
Have you tried it?
Did it work?

...R

Hi Robin2,

Thank you for the response.
315MHz Simple RF Link Kit - 315MHz Simple RF Link Kit | Seeed Studio Wiki

I got the datasheet for wireless communications from here.

Yes, I did tried and tested it out. It's not working. I not sure is it my Device A, Device B or both having problems with it.

junchenggg:
Yes, I did tried and tested it out. It's not working.

There is no point trying anything else until you get the demo program working.

Post the code for it.

...R

Yes. I did tried the demo program first.
However, when I open Serial Monitor from Device A, it appear weird characters. And from Device B, it did not appear anything but Serial.print("setup")

Hi
Have you got your monitor speed set at 9600baud?

Tom... :slight_smile:

Hi Tom,

Please ignore the previous post as I didn't read properly.
Yes, as for now, I had set my monitor 9600 baud. Also, I did set Serial.println when transmitting.
So in Serial Monitor, I see my key beside there is a box.

How do I remove it?

junchenggg:
How do I remove it?

How many times is it necessary to ask you to post your code ?

Also post the output that appears in the Serial Monitor

...R

Hi Robin2,

What you do mean? Post my code as in the coding or?

junchenggg:
What you do mean? Post my code as in the coding or?

I mean post the program code that gave rise to this statement in Reply #4

Yes. I did tried the demo program first.
However, when I open Serial Monitor from Device A, it appear weird characters. And from Device B, it did not appear anything but Serial.print("setup")

And, in asking for the code I am assuming that the sentence starting "However..." relates to the demo program. If not, post BOTH the demo program AND the program that the "However" relates to.

I can't help without seeing what you are seeing.

...R