Tech Story

Menu
  • Home
  • Programing
    • Delphi
      • Database
    • Arduino
    • Android
    • Unix Socket
    • Database
  • Network
    • Mikrotik
  • software
    • File Recovery
    • Driver software
    • backup
    • download
    • Drivers
    • format converter
    • programing tools
    • internet
    • phone apps
    • Network
    • graphics
    • professional
    • DISK AND PARTITION
    • OPTIMIZER
    • utility
    • programming tools
  • Digital Coin
    • Bitcoin
    • Blockchain
  • Free Proxy
  • Privacy Policy
  • contact us
  • news
  • Health and Fitness
  • General
  • Computer
  • Games
    • android games
    • computer games
    • ps4
  • Management skills
  • Monuments
  • Series and Movies
  • electrical and electronics
  • YouTube watch
Home
Programing
Arduino
Arduino – Keyboard Message
Arduino

Arduino – Keyboard Message

April 25, 2017

In this example, when the button is pressed, a text string is sent to the computer as keyboard input. The string reports the number of times the button is pressed. Once you have the Leonardo programmed and wired up, open your favorite text editor to see the results.

Warning − When you use the Keyboard.print() command, the Arduino takes over your computer's keyboard. To ensure you do not lose control of your computer while running a sketch with this function, set up a reliable control system before you call Keyboard.print(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after the button is pressed.

Components Required

You will need the following components −

  • 1 × Breadboard
  • 1 × Arduino Leonardo, Micro, or Due board
  • 1 × momentary pushbutton
  • 1 × 10k ohm resistor

Procedure

Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.

Sketch

Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.

Arduino Code

/*
   Keyboard Message test For the Arduino Leonardo and Micro,
      Sends a text string when a button is pressed.
   The circuit:
   * pushbutton attached from pin 4 to +5V
   * 10-kilohm resistor attached from pin 4 to ground
*/

#include "Keyboard.h"
const int buttonPin = 4; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
int counter = 0; // button push counter

void setup() {
   pinMode(buttonPin, INPUT); // make the pushButton pin an input:
   Keyboard.begin(); // initialize control over the keyboard:
}

void loop() {
   int buttonState = digitalRead(buttonPin); // read the pushbutton:
   if ((buttonState != previousButtonState)&& (buttonState == HIGH)) // and it's currently pressed: {
      // increment the button counter
      counter++;
      // type out a message
      Keyboard.print("You pressed the button ");
      Keyboard.print(counter);
      Keyboard.println(" times.");
   }
   // save the current button state for comparison next time:
   previousButtonState = buttonState;
}

Code to Note

Attach one terminal of the pushbutton to pin 4 on Arduino. Attach the other pin to 5V. Use the resistor as a pull-down, providing a reference to the ground, by attaching it from pin 4 to the ground.

Once you have programmed your board, unplug the USB cable, open a text editor and put the text cursor in the typing area. Connect the board to your computer through USB again and press the button to write in the document.

Result

By using any text editor, it will display the text sent via Arduino.

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Finished Crystal Reports can be exported to a number of formats …

Crystal Reports – Data Export Overview

Open the windows explorer and show the specified folder uses …

Open the windows explorer and show the specified folder

Leave a Reply

Cancel reply

Recent Posts

  • The 7 main protein sources
  • 4- Best electric cars
  • Adobe Master Collection 2021 v2.0 Free download
  • Dr.Web Security Space 12.0.3.12280 Free Download
  • RizomUV Real / Virtual Space 2020.1.111 x64 Free Download

Categories

  • Advertisement
  • Android
  • android games
  • antivirus
  • Arduino
  • audio video editor
  • backup
  • Bitcoin
  • Blockchain
  • Chinese medicine
  • Computer
  • computer games
  • Database
  • Database
  • Delphi
  • DISK AND PARTITION
  • download
  • Driver software
  • Drivers
  • electrical and electronics
  • Fashion and beauty
  • File Recovery
  • Forex Trading
  • format converter
  • General
  • general
  • graphics
  • Health and Fitness
  • Healthy Eating
  • internet
  • Management skills
  • Mikrotik
  • Monuments
  • Network
  • News
  • Nutrition
  • Operating System
  • OPTIMIZER
  • passwords
  • phone apps
  • phone software
  • professional
  • Programing
  • programing tools
  • programming tools
  • ps4
  • Raspberry Pi
  • Series and Movies
  • software
  • Sport
  • thems
  • Uncategorized
  • Unix Socket
  • utility
  • Videos
  • YouTube watch

Tech Story

Copyright © 2021 Tech Story
Theme by MyThemeShop.com

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh