I have interfaced 433Mhz rf module and custom 5x5 button matrix with arduino. Keeping Keypad matrix at transmitter side and an LED on the reciever side as long as i hold down the button the led should glow, this is what i have in mind.
Using Keypad.h library i am able to send signal with all 25 buttons, the issue is that it is sending signal only once and not continuously even if i keep pressing the button and hence the led is not glowing while pressing the button down it just turns on and does not go off
Is 433Mhz rf module capable of doing so or do i have to change module and try something else?
I want to do two things
- Sending continuous signal with buttons kept pressed
- Multiple button press
Can anyone help me?
for the reference i'll share the code
Transmitter Code
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
//Include Keypad matrix Library
#include <Keypad.h>
// int push = 13;
const byte ROWS = 5; //four rows
const byte COLS = 5; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'A','B','C','D','E'},
{'F','G','H','I','J'},
{'K','L','M','N','O'},
{'P','Q','R','S','T'},
{'U','V','W','X','Y'}
};
byte rowPins[ROWS] = {2,3,4,5,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,8,9,10,11}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
char holdKey;
unsigned long t_hold;
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
Serial.begin(9600);
// Initialize ASK Object
rf_driver.init();
//pinMode(push, INPUT);
}
void loop()
{
char key = customKeypad.getKey();
if (key){
holdKey = key;
Serial.println(key);
}
if (customKeypad.getState() == HOLD) {
if ((millis() - t_hold) > 100 ) {
if (holdKey == 'A'){
Serial.println("A");
const char *msg = "A";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
Serial.print("released");
}
if (holdKey == 'B'){
Serial.println("B");
const char *msg = "B";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'C'){
Serial.println("C");
const char *msg = "C";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'D'){
Serial.println("D");
const char *msg = "D";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'E'){
Serial.println("E");
const char *msg = "E";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'F'){
Serial.println("F");
const char *msg = "F";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'G'){
Serial.println("G");
const char *msg = "G";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'H'){
Serial.println("H");
const char *msg = "H";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'I'){
Serial.println("I");
const char *msg = "I";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'J'){
Serial.println("J");
const char *msg = "J";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'K'){
Serial.println("K");
const char *msg = "K";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'L'){
Serial.println("L");
const char *msg = "L";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'M'){
Serial.println("M");
const char *msg = "M";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'N'){
Serial.println("N");
const char *msg = "N";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'O'){
Serial.println("O");
const char *msg = "O";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'P'){
Serial.println("P");
const char *msg = "P";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'Q'){
Serial.println("Q");
const char *msg = "Q";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'R'){
Serial.println("R");
const char *msg = "R";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'S'){
Serial.println("S");
const char *msg = "S";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'T'){
Serial.println("T");
const char *msg = "T";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'U'){
Serial.println("U");
const char *msg = "U";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'V'){
Serial.println("V");
const char *msg = "V";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'W'){
Serial.println("W");
const char *msg = "W";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'X'){
Serial.println("X");
const char *msg = "X";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
if (holdKey == 'Y'){
Serial.println("Y");
const char *msg = "Y";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
}
}Serial.println("1");
}
const char *msg = "0";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
Serial.println("2");
}
Reciever code
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
pinMode(8, OUTPUT);
}
void loop()
{
//digitalWrite(12, HIGH);
// Set buffer to size of expected message
uint8_t buf[24];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{
// Message received with valid checksum
//Serial.print("Message Received: ");
//Serial.println((char*)buf);
for (int i; i < buflen; i++){
// switch(buf[i]){
//
// case 'A':
// digitalWrite(8, HIGH);
// break;
//
// case 'B':
// digitalWrite(8, LOW);
// break;
//
// //default:
// //digitalWrite(8, LOW);
// //Serial.println("This is default");
//
// }
//Serial.print("my data=");
Serial.write(buf[0]);
if(buf[i]=='A'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='B'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='C'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='D'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='E'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='F'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if(buf[i]=='G'){
//Serial.println("Forward");
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
else if(buf[i]=='0'){
//Serial.println("123");
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
}
}}
````