Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to convert Arduino into USB Rubber Ducky for automatic Gmail login

By Nikhil Agnihotri March 21, 2024

You might have heard about USB rubber ducky. A Rubber ducky is a programmed USB HID device, often a pen drive, to send a programmed sequence of keystrokes and mouse events to a computer. It is a powerful device that can unlock a PC or login credentials by inserting a USB stick. Even a rubber ducky can be used to automate tasks on a computer.

The 32u4 or SAMD micro-based Arduino boards like Arduino Leonardo, Pro Micro, Zero, Due, Esplora, and MKR family can be configured to appear as USB HID devices on a computer. The Keyboard library can send keystrokes to a computer, and the Mouse library can trigger mouse events. With the help of these libraries, 32u4 or SAMD micro-based Arduino boards can be programmed to run as USB Rubber Ducky even without any USB programming involved.

Typically, USB Rubber Ducky is created by compiling a ducky script or payload and transferring the executable payload to the USB HID device like a pen drive. In the case of Arduino, ducky scripts are converted to Arduino sketch using a specific IDE or online converter. The converted sketch is uploaded to a suitable Arduino board to run as a USB Rubber Ducky.

In this project, first, we will directly code Arduino Leonardo to operate as USB Rubber Ducky using the Keyboard library. There are two ducky sketches demonstrated in this project. The first ducky sketch shows automating tasks on a computer. The second ducky sketch automatically logins to a Gmail account as the Arduino Leonardo is plugged into the computer.

Components required

  1. Arduino Leonardo or any SAMD-based Arduino board x1
  2. Micro USB Cable x1

Circuit connections
There are no circuit connections required. You simply need to upload the ducky sketch to Leonardo. When you connect Leonardo to a computer via a micro-USB cable, the ducky sketch automatically plays its part on the target computer.

Automating tasks on a computer
The first ducky sketch we demonstrate here automates tasks on a target computer. As Arduino Leonardo is plugged into a computer, the sketch opens NotePad on the target Windows PC and starts typing an automated message. Any other application can be automated similarly using a USB rubber ducky. Check out the video below.

How it works
The sketch uses the Keyboard.h library. The library only works with 32u4  or SAMD Micro-based Arduino boards. A function typeKey() is defined as inserting keystrokes, exceptional ones like Tab, Enter, Shift, Ctrl, etc. It is important to wrap keystrokes in a function; otherwise, the emulated keystroke will remain pressed after a call to Keyboard.press() until Keyboard.realease() is called. This can cause Arduino to constantly push the same keystroke to the computer leading to unpredictable behavior.

All the remaining code is written in the setup() function because we want the automated tasks to run only once. In the loop function, the script would continue executing infinitely, actually rendering the target computer in an unpredictable state.

In the setup() function, USB HID Keyboard is initiated from Arduino Leonardo by calling Keyboard.begin(). After some delay run command is executed on Windows by sending keystrokes for GUI and ‘R.’ The keystrokes are sent by calling the Keyboard.press() function. In the run command, Windows Powershell is launched by typing “powershell” and sending the keystroke for ENTER. The text is typed by calling the Keyboard.print() function. From Windows PowerShell, notepad is launched by typing “notepad.exe” and sending a keystroke for ENTER. Sufficient delay is provided to wait for the notepad to launch. As the notepad is launched, keystrokes to type a predetermined message are sent, followed by a keystroke for carriage return after each message multiple times. Finally, the USB HID Keyboard from Arduino is turned off by calling Keyboard.end().

In the same way, we can automate any application on the target computer. Now, let us see some real-life use of automating tasks on a computer by configuring a USB rubber ducky to automatically login credentials.

Automatic Gmail login
Arduino-based Rubber Ducky can even automatically log in to an email account or social media platform. The following video shows how Arduino-based USB Rubber Ducky is used for logging in to Gmail.

Arduino Sketch

How it works
The same Keyboard.h library is utilized to create this USB Rubber Ducky. The typeKey() function is defined as sending keystrokes from Arduino to the computer. Since this USB rubber ducky is used for logging in to a Gmail account, the sign-in must be only once. Therefore, the entire code is written in the setup() function.

The sketch sends keystrokes to execute the run command on Microsoft Windows. The link for Gmail login is automatically typed through the sketch and executed by sending a keystroke for ENTER. The Gmail opens in the default browser of the target computer. The Arduino automatically typed the Gmail username, followed by a keystroke for ENTER. Next, the Arduino automatically typed the Gmail password, followed by a keystroke for ENTER to implement sign-in. In the sketch, you need to replace GMAIL-USERNAME and GMAIL-PASSWORD with your Gmail username and password.


Filed Under: Arduino Projects, Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Does mobility carrier ratio changes with Wn? (0.18um) inverter design
  • DC/DC Converter with wide range input
  • i need an embedded c program that will read a 12 bit memory address from the io pins and output the data to pins from the memory in a 8051 mcontroller
  • Output return loss mismatch
  • DIY Buck Boost Converter using XL6019

RSS Electro-Tech-Online.com Discussions

  • parallel-to-serial problem
  • Back to the old BASIC days
  • Guitar electronics project
  • 12v battery, 18v magic
  • Actin group needed for effective PCB software tutorials

Featured -USB Series

  • Controller Chip Selection for Developing USB Enabled Device (Part 6/6)
  • Signal and Encoding of USB System (Part 5/6)
  • USB Requests and Stages of Control Transfer (Part 4/6)
  • USB Descriptors and their Types (Part 3/6)
  • USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)
  • Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Recent Articles

  • Littelfuse driver achieves less than 1 µA standby current for energy-efficient designs
  • Microchip optimizes power consumption in transceiver-less FPGA design for automotive applications
  • What is an IoT platform and when is one useful?
  • Silanna launches laser driver IC with sub-2 ns FWHM pulse for LiDAR application
  • LEM introduces current sensors with bandwidth up to 2.5 MHz for precision applications

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe