Arduino Button Mouse Control Code

Using the Mouse library, you can controls a computer’s onscreen cursor with an Arduino Leonardo, Micro, or Due. This particular example uses a five pushbuttons to move the onscreen cursor. Four of the buttons are directional (up, down, left, right) and one is for a left mouse click

Arduino Button Mouse Control

Cursor movement from the Arduino is always relative. Every time an input is read, the cursor’s position is updated relative to it’s current position.

Whenever one of the directional buttons is pressed, the Arduino will move the mouse, mapping a HIGH input to a range of 5 in the appropriate direction.

The fifth button is for controlling a left click from a mouse. When pressed, the board sends a press to the computer. When the button is released, the computer will recognize the event.

NB: When you use the Mouse.move() command, the Arduino takes over your computer’s cursor! To insure you don’t lose control of your computer while running a sketch with this function, make sure to set up a controller before you call Mouse.move(). This sketch only updates the cursor position when a button is pressed.

Software Required

  • none

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

 Arduino Button Mouse Control schematic

Code

/*
ButtonMouseControl

Controls the mouse from five pushbuttons on an Arduino Leonardo or Micro.

Hardware:
* 5 pushbuttons attached to D2, D3, D4, D5, D6

The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.

WARNING:  When you use the Mouse.move() command, the Arduino takes
over your mouse!  Make sure you have control before you use the mouse commands.

created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe

this code is in the public domain

*/

[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]

Hardware Required

  • Arduino Leonardo, Micr or Due board
  • 5 momentary pushbuttons
  • Five 10-kilohm resistors
  • hook up wire
  • breadboard

[/box]

For more detail: Arduino Button Mouse Control Code


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top