Guillermo Perez Guillen
Published © MIT

Magnetic Mouse

Control your PC mouse with a 3D Magnetic Sensor. Useful for people with physical disabilities in their hands

IntermediateFull instructions provided8 hours109
Magnetic Mouse

Things used in this project

Hardware components

3D Magnetic Sensor 2Go
Infineon 3D Magnetic Sensor 2Go
×1
S2GO 2 HALL TLE4966K
Infineon S2GO 2 HALL TLE4966K
×1
Pro Micro - 5V/16MHz
SparkFun Pro Micro - 5V/16MHz
×1
Battery, 3.7 V
Battery, 3.7 V
×1
Neodymium Magnet
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic Diagram

Electrical diagram of the magnetic mouse

Code

pro_micro_interface.ino

C/C++
Code to be uploaded to the Arduino Pro Micro board
// AUTHOR: GUILLERMO PEREZ GUILLEN

#include <Mouse.h> // Special Library

void setup()
{
    Serial.begin(9600);    
    pinMode (6,INPUT_PULLUP);
    pinMode (7,INPUT_PULLUP);
    pinMode (8,INPUT_PULLUP);
    pinMode (9,INPUT_PULLUP);
    pinMode (10, INPUT_PULLUP);
}

void loop()
{
//char dato[1];
int SWITCH1 = digitalRead(6);
int SWITCH2 = digitalRead(7);
int SWITCH3 = digitalRead(8);
int SWITCH4 = digitalRead(9);
int SWITCH5 = digitalRead(10); // CLICK

     if (SWITCH5 == LOW) {   // CLICK      
      Serial.println("CLICK");
      Mouse.click();
     }

     if (SWITCH1 == HIGH) {   // UP      
      Serial.println("UP");
      Mouse.move(0, 5, 0);
     }

     if (SWITCH2 == HIGH) {   // RIGHT
      Serial.println("RIGHT");
      Mouse.move(-5, 0, 0);
     }

     if (SWITCH3 == HIGH) {   // RIGHT
      Serial.println("DOWN");     
      Mouse.move(0, -5, 0);
     }

     if (SWITCH4 == HIGH) {   // RIGHT
      Serial.println("LEFT");
      Mouse.move(5, 0, 0);
     }

     else {
      Serial.println("STOP");
      Mouse.move(0, 0, 0);
     }     
    delay(100);
}

magnetic_mouse.ino

C/C++
Code to be uploaded to the TLE5012B E1000 MS2GO magnetic angle sensor.
// AUTHOR: GUILLERMO PEREZ GUILLEN

#include <TLE5012-ino.hpp>

Tle5012Ino Tle5012Sensor = Tle5012Ino();
errorTypes checkError = NO_ERROR;
double positionReading = 0.0;
int input=0;

void setup() {
  // put your setup code here, to run once:
  delay(2000);
  Serial.begin(9600);
  pinMode (3,OUTPUT);
  pinMode (4,OUTPUT);
  pinMode (5,OUTPUT);
  pinMode (6,OUTPUT);
  while (!Serial) {};
  checkError = Tle5012Sensor.begin();
  Serial.print("checkError: ");
  Serial.println(checkError,HEX);
  delay(1000);
  Serial.println("Init done");
}

void loop() {
  // put your main code here, to run repeatedly:

Tle5012Sensor.getAngleValue(positionReading);

if (positionReading >= -25 && positionReading <= 25) {   
  Serial.println("Up");
  digitalWrite (3,LOW);
  digitalWrite (4,HIGH);
  digitalWrite (5,HIGH);
  digitalWrite (6,HIGH);  
   input=1;
}

else if (positionReading < -65 && positionReading >= -100) {
  Serial.println("Right");
  digitalWrite (3,HIGH);
  digitalWrite (4,LOW);
  digitalWrite (5,HIGH);
  digitalWrite (6,HIGH);
  input=2;
}

else if (positionReading < -140 || positionReading > 140) {
  Serial.println("Down");
  digitalWrite (3,HIGH);
  digitalWrite (4,HIGH);
  digitalWrite (5,LOW);
  digitalWrite (6,HIGH);  
  input=3;
}

else if (positionReading > 65 && positionReading <= 100) {
  Serial.println("Left");
  digitalWrite (3,HIGH);
  digitalWrite (4,HIGH);
  digitalWrite (5,HIGH);
  digitalWrite (6,LOW);  
  input=4;
}

else {
  Serial.println("Stop");
  digitalWrite (3,HIGH);
  digitalWrite (4,HIGH);
  digitalWrite (5,HIGH);
  digitalWrite (6,HIGH);  
  input=5;  
}
 
  delay(100);
}

magnetic-mouse

Repository

Credits

Guillermo Perez Guillen

Guillermo Perez Guillen

54 projects • 63 followers
Electronics and Communications Engineer (ECE): 12 prizes in Hackster / Hackaday Prize Finalist 2021-22-23 / 3 prizes in element14

Comments