Home Forums General Discussion Send button sign from Arduino to pc via bluetooth

This topic contains 2 replies, has 2 voices, and was last updated by  Pankaj Verma 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6007

    Hi everyone, I have som trouble with Arduino code,

    I have multikeys 12 button which is connect to my Arduino on pin 2,3,4,5, 6,7,8

    I need to send every button click (sign) from my Arduino to my PC via bluetooth module HC06

    Here is my code which i tried to use but it not working

    Is someone who can help me with my issue?

    #include <Keyboard.h>
    #include <Keypad.h>
    #include <SoftwareSerial.h>

    // Declaration of bluetooth RX and TX
    SoftwareSerial Bluetooth(9, 10);

    char button;

    //Declarera array
    const byte ROWS = 4; //four rows
    const byte COLS = 3; //three columns
    char keys[ROWS][COLS] = {
    {‘1’, ‘2’, ‘3’},
    {‘4’, ‘5’, ‘6’},
    {‘7’, ‘8’, ‘9’},
    {‘*’, ‘0’, ‘#’}
    };

    byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
    byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

    Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

    void setup() {
    Serial.begin(9600);
    Bluetooth.begin(9600);

    }

    void loop() {
    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (kpd.getKeys())
    {
    for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
    {
    if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
    {
    // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
    switch (kpd.key[i].kstate) {
    case PRESSED:

    //write keys via USB
    //Keyboard.write(kpd.key[i].kchar);

    //send button to bluetooth
    button = kpd.key[i].kchar;
    bluetoothFunc(button);

    break;
    }
    }
    }
    }
    } // End loop

    void bluetoothFunc(char button)
    {
    if (Bluetooth.available()) {
    Bluetooth.write(Keyboard.write(button));
    }
    }

     

    #6008

    here is my hardwarehardware

    #6025

    Pankaj Verma
    Keymaster

    Hi George Kalandarishvili,

    I have identified the problem. In the function declaration,

    void bluetoothFunc(char button)
    {
    if (Bluetooth.available()) {
    Bluetooth.write(Keyboard.write(button));
    }
    }

    What you are doing here is wrong. You are sending button data if and only if there is bytes available on the Bluetooth. You just have to send the data, when button is pressed. Please try this code and it may work for you.

    void bluetoothFunc(char button)
    {
    Bluetooth.write(Keyboard.write(button));
    }

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.