Control Arduino With a Portable App



Introduction: Control Arduino With a Portable App

About: I build projects using arduino nano / esp32 / arduino micro and also arduino mkr1010

We are going to learn how to make an application to control arduino.

We will see how to:

  • Easily make a windows application with python.
  • Convert it as an executable to use it anywhere.
  • Manage Serial ports (detection/reconnection) automatically with 1 line of code

We can even reuse the code to manage as many arduino as we want.

But before i tell you more about it, let's try utest first!
We will use it to control the internal led on an Arduino nano.

As always, all the documentation/code are available on github in english/french

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Upload Arduino Code

Frist we need to upload the code on the arduino.

On the Arduino software ( )

  • Copy utest folder into your sketch folder
  • Upload utest.ino

(Tools: Arduino Nano / Processor : Atmega328)

You will need an Arduino nano clone (ch340g) as the application will only detected it.

You can use the serial monitor, to test your arduino:
No Line Ending / 115200

UTest : return OK
ON : Turn on internal led (pin13)
OFF: Turn off internal led (pin13)

Step 2: Control the Arduino With Utest

utest is a portable application, you don't need to install anything to make it works.

utest will automatically find the arduino
You can try to unplugged it/plug it on another usb port, and it will reconnect.

utest might not work on Windows 7 due to missing .dll
This shouldn't happen if your computer is up to date

Step 3: Create Your Own Application

Let's see how to reuse this application, to make your own application.

First we need to install python 3 to modify it.

Then we need to install pySerial, to communicate with our arduino.

  • Open a command prompt (Windows key + cmd)
  • Type:
pip install serial

Finally, test the application, it is available in the source code ( ) at apps/utest/

  • Open a command prompt
  • Go to the source code folder (apps/utest/)
  • Type:

Step 4: Create the Interface

We have everything we need to modify our application.
Check out the source code : (github)

Let's see

  • how to manage our arduino
  • how to build a graphical interface with tkinter

In order to manage the arduino the easiest way possible, everything is handle by the module lib/


As for now, this module has only two commands

usb = USB.Device(...)
  • Connect to every serial ports which as CH340 in his name
  • Send UTest to the serial port
  • If it received "OK", it will connected to it
from lib import USB

device_name = "CH340" #Device name in Windows
device_type = "UTest" #Device type (in the arduino sketch)
device_return_string = "OK" #Answer when a response is correct
device_baudrate = 115200 #Baudrate
usb = USB.Device(device_name,device_type,device_return_string,device_baudrate,status)

Everything is inside a separate thread to avoid blocking the application.

  • Send a string to the arduino
  • If the serial port is not available, it will try to reconnect

GUI (TKinter)

utest use tkinter to manage the GUI (graphical interface)
You can find more information on tkinter here :

  • To create a window:
from tkinter import *
root = Tk()
  • To create a button ON
  • Create an action for the button ON
def on():
  • Create a label
status = Label(text="Searching...")

If you want to modify a widget , we need to save it into a variable, and use .pack() on a different line
We send the label to the USB Moduleto display the current state of the connection

usb = USB.Device(...,status)

Finally, we generate the GUI loop.


Step 5: Add Commands to the Arduino

Our interface is ready,
but we need to teach our arduino to understand the commands we will send.
Check out the source code : utest.ino (Github)

Serial Functions

We use two functions to manage the serial communication.


    Check the serial port and convert any messages to a string (inside readString)


      If UTest is received , answer OK

      Device name

      You can change the name of the usb device in the first line

      const String usb_name = "UTest";

      Add commands

      We manage our commands inside void loop()

      void loop() {
        //If string received
           if (readString.length() > 0) {
            if (readString == "ON"){
            if (readString == "OFF"){
        //We clean the serial buffer
        readString = "";

      For each commands create a condition, for example to turn on the internal led when "ON" is sent

      if (readString == "ON"){

      Step 6: Convert Your App Into a Portable Executable

      The arduino / Application is ready to be bundle into an .exe

      • Install pyinstaller, we will use it to convert our application into an single executable file

      pip install pyinstaller

      • You can compile your application using the script compile.bat

      pyinstaller --onefile --noconsole 

      • If you want to display debug messages, use this command instead:

      pyinstaller --onefile

      You should now have a /dist/utest.exe file

      You will probably have warning about api-ms...dll file.
      This shouldn't be a problem as these DLL (Universal C Runtime) are preinstalled on Windows 10 and previous windows should also have them if they are up to date.

      Step 7: ... to Be Continued

      I hope this was useful, and that will inspired you to create Arduino application !
      With some modification, this application should works on MacOS / Linux.

      Follow me on instructables/youtube, if you are interested by this topic.

      Next time, we will learn how to improve our application and use it to control a led strip!

      Be the First to Share


        • Backyard Contest

          Backyard Contest
        • Silly Hats Speed Challenge

          Silly Hats Speed Challenge
        • Finish It Already Speed Challenge

          Finish It Already Speed Challenge