Arduino Mouse Wiggler

6,331

18

27

Introduction: Arduino Mouse Wiggler

It is kind of annoying every time when the computer goes into sleep, especially when you are in the middle of a PowerPoint presentation, or working from home but supposed to appear available online all the time. This simple device will wiggle (jiggle) your mouse for you every 30 seconds or so and keep your computer always awake. This device simply simulates the physical mouse movement, there's no App or driver to be installed, so it is 'stealth' and won't violate the company IT policy or expose yourself to dangerous software.

Step 1: Make the Device

The entire mouse wiggler is 3D printed. The files are attached. Print the parts with your favorite color.

Step 2: Hardware and Assembly

The mouse wiggler uses parts that are available from many retailers. Following hardware are needed:

  • Arduino Nano (or clone,don't solder the pins to the Nano)
  • SG90 Servo and hardware pack
  • Mini USB cable
  • Some wires

Following are the steps to wire the servo to the Arduino Nano and installation of the servo and wheel.

The servo has a connector with 3 female pins. The orange one is the PMW pin that needs to be connected to the D9 pin on the Arduino Nano. The center Red wire is Vcc that goes to the +5V on the Nano and the Brown is ground that is connected to the GND on the nano. I used 3 male pins and soldered it to the wires from the Nano to make the wiring easier.

Use one of the servo horn and the screws to secure the SG90 servo to the mouse wiggler body, and install the wheel on the servo output. Make sure the wheel is level and does not interfere with the mouse. Optionally you can print the pattern and place it on top of the wheel to improve aesthetics and make the mouse move more consistent. I used white address labels for this.

Step 3: Code

The Arduino sketch is attached. Make sure you have the Servo.h and SimpleTimer.h libraries installed before uploading the sketch to your nano. You may change the angle in which the servo will travel, and the time interval that the servo will move. The default setting is the servo will move the wheel 30 degrees to the left then 30 degrees to the right every 30 seconds. This will make your mouse move for about 10 mm which is enough for keeping the computer from sleep, yet not too much to lost track of the mouse cursor. You may adjust these values as you desire.

Step 4: Let the Mouse Move

Place your mouse on top of the Mouse Wiggler and make sure the optical sensor on top of the wheel. Power the device up use a USB power adapter and you're good to go.

Automation Contest 2017

Runner Up in the
Automation Contest 2017

Lazy Life Challenge

Participated in the
Lazy Life Challenge

Plastics Contest

Participated in the
Plastics Contest

Make It Move Contest 2017

Participated in the
Make It Move Contest 2017

3 People Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

27 Discussions

0
Astronomy Domine
Astronomy Domine

2 months ago on Step 4

I've update my code. I discovered that detaching the servo between moves eliminates the servo 'buzz' that often occurred. I also wanted a random move time, so set a min and max time to create a random move time.

I then went overboard and put in a load of (unnecessary) serial debug info which can be enabled by uncommenting 1 line :)

New code:

/**This is a modified version of the code found at:
https://www.instructables.com/Arduino-Mouse-Wiggl...
*/
#include <Servo.h>
#include <SimpleTimer.h>

int servoPin = 9; //Servo attached to in 9
int mousePos = 20; // set the limit of mouse move (20 was plenty for me)

//Comment out the following 2 lines if you only need a repeating 30 second timer
#define MinimumTime 45 //Minimum time (in seconds) between mouse movements
#define MaximumTime 210 //Maximum time (in seconds) between mouse movements

Servo servo;
int angle = 0; // servo position in degrees

SimpleTimer timer(30000L); //This is how to decalre a 30 second timer with the version of SimpleTimer used

//Uncomment this if you want debug messages sent to the Serial Monitor
//#define DebugInfo

void setup()
{
#ifdef DebugInfo
Serial.begin(115200);
Serial.println("Serial output enabled.");
#endif

servo.attach(servoPin); //Attach the servo
servo.write(0); // Set Servo to 0 degrees
delay(15);

#ifdef DebugInfo
Serial.println("Servo set to 0 degrees.");
#endif

servo.detach(); //Detaching when not in use seems to prevent servo chatter/buzzing

randomSeed(analogRead(0)); //Get as close ro a random number as easily possible
}

void loop()
{
if (timer.isReady()) //Check if Simple Timer has reached it's trigger time
{
//Mouse Move
servo.attach(servoPin);

#ifdef DebugInfo
if (servo.attached())
{
Serial.println("Servo attached.");
}
else
{
Serial.println("Servo failed to attach.");
}
#endif

// scan from 0 to mousePos degrees
for(angle = 0; angle <= mousePos; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from mousePos to 0 degrees
for(angle = mousePos; angle >= 0; angle--)
{
servo.write(angle);
delay(15);
}

#ifdef DebugInfo
Serial.println("Servo move complete.");
#endif

servo.detach();

#ifdef DebugInfo
if (!servo.attached())
{
Serial.println("Servo detached.");
}
else
{
Serial.println("Servo failed to detach.");
}
#endif

#ifdef MinimumTime //only use random time if Min and Max are defined
#ifdef MaximumTime
#ifdef DebugInfo
long RandomTime = random(MinimumTime, MaximumTime);
timer.setInterval((RandomTime*1000));
Serial.print("Next Activation: "); Serial.print(RandomTime);Serial.println(" seconds.");
#else
timer.setInterval((random(MinimumTime, MaximumTime)*1000));
#endif
#endif
#else
#ifdef DebugInfo
Serial.println("30 second timer used.");
#endif
#endif

timer.reset(); //Restart the timer
}
}

0
samblaha
samblaha

6 months ago on Step 3

Hey great project, I have run into a snag while compiling the Arduino sketch. I received this error and was wondering if anybody knew how to fix it. The code seems right and is unchanged, so it could be a version issue. ANy help is appreciated, Thanks!

jiggler.PNG
0
Astronomy Domine
Astronomy Domine

Reply 2 months ago

Same error here. The modified code I posted in another comment works.

0
codingwolf
codingwolf

Reply 5 months ago

It looks like you might be trying to use a different version of SimpleTimer. You can obtain a compatible version of the SimpleTimer used from Arduino Playground. https://playground.arduino.cc/Code/SimpleTimer/#Ge...

You just need to get the SimpleTimer.ccp file and the SimpleTimer.h file. Then replace one line in the main code that is posted in the article.

In the main code, change the include line to:
#include "SimpleTimer.h"

See images below:

22:51:43_07-28-20_screenshot.jpg22:52:32_07-28-20_screenshot.jpg22:52:42_07-28-20_screenshot.jpg
1
SauliusP5
SauliusP5

10 months ago

Hi, its the second "wiggler" I am trying to make after the long break. I am doing everything the same as last time but no success this time. Need some help here please..

Wiggler.PNG
0
Astronomy Domine
Astronomy Domine

Reply 2 months ago

I'm 4 months later to the party but I had the same error when I used the SimpleTimer downloaded from the Arduino Library Manager.

I've posted code that works in another comment.

0
codingwolf
codingwolf

Reply 5 months ago

Try moving the entire function of "void mouseMove" above the "void setup" function and then compile. See attached image for example. Hope that helps.

22:38:58_07-28-20_screenshot.jpg
0
samblaha
samblaha

Reply 6 months ago

Hey did you ever figure this out?

0
ArtSuzhou
ArtSuzhou

Reply 10 months ago

Looks there are some grammatical errors in your sketch. Did you try to download the sketch again? The article hasn't changed since it was published.

0
Astronomy Domine
Astronomy Domine

2 months ago

This code will work for the version of SimpleTimer that I got from the Ardiono Library Manager:

/**This is a modified version of the code found at:
https://www.instructables.com/Arduino-Mouse-Wiggler/
*/
#include <Servo.h>
#include <SimpleTimer.h>
int servoPin = 9;
int mousePos = 20; // set the limit of mouse move (20 degrees was plenty for me)
Servo servo;
SimpleTimer timer(30000L); //This is how to decalre a 30 second timer with the version of SimpleTimer used
int angle = 0; // servo position in degrees
void setup()
{
servo.attach(servoPin);
servo.write(0); // Set Servo to 0 degrees
}
void mouseMove()
{
// scan from 0 to mousePos degrees
for(angle = 0; angle <= mousePos; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from mousePos to 0 degrees
for(angle = mousePos; angle >= 0; angle--)
{
servo.write(angle);
delay(15);
}
}
void loop()
{
//Thetimer.run() line is replaced by this code which triggers the mouse when the timer reaches 30 seconds
if (timer.isReady()) {
mouseMove();
timer.reset(); //Reset the timer
}
}

0
PacoT6
PacoT6

3 years ago

could you put out the code in the article because i cant open the file.

0
ArtSuzhou
ArtSuzhou

Reply 3 years ago

I just tried the sketch can be downloaded without issue. It can be opened by Arduino IDE, or a text editor.

0
PacoT6
PacoT6

Reply 3 years ago

Could you send me an email or something because the computer I use cannot open the file.

0
PacoT6
PacoT6

Reply 3 years ago

*email text file of the code or a picture of the code

0
Thanor
Thanor

Reply 3 months ago

You can open the file with Notepad++

Here is the code:

/**The MIT License (MIT)
Copyright (c) 2017 by Bin Sun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <Servo.h>
#include <SimpleTimer.h>
int servoPin = 9;
int mousePos = 30; // set the limit of mouse move
Servo servo;
SimpleTimer timer;
int angle = 0; // servo position in degrees
void setup()
{
servo.attach(servoPin);
timer.setInterval(30000L, mouseMove); //wiggle every 30 seconds
}
void mouseMove()
{
// scan from 0 to mousePos degrees
for(angle = 0; angle < mousePos; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from mousePos to 0 degrees
for(angle = mousePos; angle > 0; angle--)
{
servo.write(angle);
delay(15);
}
}
void loop()
{
timer.run(); //Initiate SimpleTimer
}

0
falias
falias

3 years ago

just get an Atmega32u4 and send mouse commands. no empty mouse batteries, no loud servo, 1-2 lines of code in the loop

0
codingwolf
codingwolf

Reply 5 months ago

I'd be interested in this, you should do an instructable on it.

0
ArtSuzhou
ArtSuzhou

Reply 3 years ago

ATtiny85 can do the same. But that requires installation of mouse driver which in some cases are not permitted. In some places plug in such an USB device will trigger an red alarm.

0
falias
falias

Reply 3 years ago

well the 32u4 has built-in usb and doesn't require special drivers (as far as i know), so attiny85 can't do the same. not to mention that those places must suck, when you aren't allowed to plug in another "default" input device :-P

0
DIY Hacks and How Tos

Genius! No more issues with movies getting interrupted by the screen saver.