Using Arduino as a Bluetooth "Keyboard"


I am inquiring to see if an idea I have for a project is possible or not. What I am looking to do is connect an Arduino Nano via bluetooth (these to be exact: & to a PC and have it send a number based on whatever button I press. I've searched on a bunch of forums but haven't found anything similar. Here is an example of code I have written:

const int pin1 = 2;
const int pin2 = 3;

int button1 = 0;
int button2 = 0;

void setup()  
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);
void loop()  
  button1 = digitalRead(buttonPin);
  button2 = digitalRead(buttonPin);

    if (button1 == HIGH)  
       blueTooth.write (0);

    if (button2 == HIGH)  
       blueTooth.write (1);


Would something like this work or am I way off? Thank you very much!

Side note: I've used the Adafruit EZ-Key in the past for this, but they've been out of stock on them for quite awhile. Really wanting to finish this up. :sweat_smile:

That looks like it could work, but don't forget to add pulldown resistors to the button inputs to stop them floating at an unknown voltage. Better still, use INPUT_PULLUP in the pinMode()s to activate the built in pullup resistors, take the pins LOW when the buttons are pressed and reverse the logic checks