Home / How To / Use Arduino and a button to send an autoresponder to your phone !: 3 steps

Use Arduino and a button to send an autoresponder to your phone !: 3 steps



Now that your circuits are configured and your Arduino is connected to your phone via Bluetooth, it's time to change the code to send a message with your button! My code is included in a PDF for reference.

First define the pins for your LED, Buzzer and Button:

const int buttonPin = 11;

const int blueLED = 15;

const int BUZZ = 16;

Next, add a bool function for your button. Since the default position of the button is open, be sure to set the base logic to false:

bool-buttonPressed = false;

Next part of code in idle setting (), define your inputs (button) and buzzer output:

pinMode (buttonPin, INPUT);
pinMode (BUZZ, OUTPUT);

digitalWrite (BUZZ, HIGH);

noTone (BUZZ);

Below it is the code from the example HID_Keyboard sketch that instructs Serial Monitor to print user instructions AND the code that identifies your Arduino to the devices it connects to. You can change the name of your Arduino here, but otherwise leave it here. Then you see:

void startAdv (void)

This instructs your Arduino to announce its Bluetooth signal and allows it to connect to your phone. Leave this as well.

Now we come to the loop. This is where you call on the Bool function to make the button work. This part of the code instructs Arduino to send your message at the touch of a button when you press the button. It also instructs it to activate the LED and buzzer outputs when the button is pressed to provide feedback from users. The second part of the loop instructs Arduino to check if a button is pressed and then release the key to avoid sending repeated data. It also instructs LED and buzzer to stop. It is important to update the delay at the end of this code so that your button sends the message to your phone exactly.

You did it! You can change your message to whatever you want. The message appears in all text editing applications, such as notes, search, messenger, text or email address.


Source link