Arduino External Mouse Buttons

Arduino External Mouse Buttons © MIT

I built the right and left mouse buttons with wall switches.

  • 997 views
  • 4 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

Hi, I'm Francesco and I am 13 years old, in this article I review how I realized this prototype and how to build it!

Step 1: Get The Basic Materials

First you will need two switches and a watertight box to insert them. Depending on the size of the keys, the box should be slightly bigger than the Arduino (NANO, in this case) too:

Step 2: Connect The Switches

The switch connections are the same as those for the breadboard. The switches I have have two outputs: one for the data and one for 5V. Then the data cable is between the switch and the 10K Ohm grounded resistance to GND, and the other switch cable is connected to 5V. The connection is the same for the other switch, as well.

Step 3: Programming

The code is very simple, because it only sends serial data when a switch is pressed. To convert the serial signal to click I wrote a program, albeit very simple, which uses libraries (pyautogui, and pyserial). This program runs automatically when you start your computer (Windows, in this case). Every now and then has problems accessing the COM port of Arduino, but everything resolves by restarting the program.

The final work!

I hope you liked this project. At this time I can not put up the code, but I will update this post as soon as possible with the complete code.

Code

switches.inoC/C++
The Arduino Code
int pulsante1 = 2;
int pulsante2 = 9;
int button1stato = 0;
int button2stato = 0;
int valorepotenziometro = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(pulsante1, INPUT);
  pinMode(pulsante2, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {
  button1stato = digitalRead(pulsante1);
  button2stato = digitalRead(pulsante2);
  valorepotenziometro = analogRead(A7);
  
  if(button1stato == HIGH){
    Serial.println("sx");
    digitalWrite(LED_BUILTIN, HIGH);
    delay(200);
  }
  if(button2stato == HIGH){
    Serial.println("dx");
    digitalWrite(LED_BUILTIN, LOW);
    delay(200);
  }

}
commands.pyPython
The Python Code
import serial
import pyautogui
import time

arduino = "dx"
arduino2 = "sx"

ser = serial.Serial('COM45', 9600)
time.sleep(1)

while True:
    val = ser.readline().strip()
    if(val == arduino):
        pyautogui.click()
    if(val == arduino2):
        pyautogui.rightClick()

if __name__ == "__main__":
	main()


    

Comments

Similar projects you might like

Gesture Mouse

by Team ONYX

  • 7,923 views
  • 0 comments
  • 17 respects

Servo Tuning Buttons

Project in progress by Andrew Hillier

  • 1,627 views
  • 0 comments
  • 8 respects

Arduino Without External Clock Crystal on ATmega328

Project tutorial by Techmirtz

  • 9,474 views
  • 2 comments
  • 13 respects

Basic Arduino + JavaScript (Workshop)

by Alex Glow

  • 11,877 views
  • 1 comment
  • 27 respects

Button: Arduino Basics

by Alex Glow

  • 10,340 views
  • 0 comments
  • 10 respects
Add projectSign up / Login