How to use windows .bat file instead of serial monitor? [Solved]

I have an arduino mini pro connected to my windows xp pc using a usb-ttl cable.

I have several servos connected to the arduino powered using an external 5V power source.

I have written a program that will rotate different servos to different positions depending on which key I press on the computer keyboard.

For example, pressing "5" on the keyboard will rotate servo 2 to position "a", hold it there for 3 seconds and then rotate to position "b", then... etc.

Everything works fine when I use the "Serial Monitor" in the arduino software to send the commands to the arduino - com3 9600 baud.

I want to create a bunch of .bat files for different keyboard keys that I can run automatically instead of launching the arduino software and typing into the "Serial Monitor" window.

When I try using a .bat batch file to send the same keyboard commands to the arduino nothing happens - Rx light lights up on the arduino but the servos don't move - sometimes they do actually move, but not correctly.

Here's the .bat text I used:


Any suggestions?


A nice bit of retro programming :)

Does that send 5 or "5"?

Is there a trailing \n\r that stuffs up the Arduino?


I'd guess that your "mode" command causes the arduino to auto-reset (and maybe the echo program as well), and the "5" arrives long before the sketch is ready to receive it (perhaps it even gets eaten by the bootloader.)

Put some code in setup() that blinks the onboard LED in a distinctive pattern to confirm this, and try disabling the auto-reset feature...

I discovered that the arduino is resetting when I send a command using the .bat file.

In my program I have the servos move to a start position when the arduino powers up - say 180 degrees.

I can use "Serial Monitor" to rotate the servos by pressing a key on the keyboard as intended.

When I send a command to the arduino using the .bat file however all the servos move to their start positions - meaning the arduino is resetting.

I've tried using char type and int type in the program for the variable reading the serial input and both work with "Serial Monitor" but none work with .bat files.

westfw - how do I disable auto-reset?

Is there an alternative?


You will need to defeat the arduino auto resert by putting a 100 ohm resistor between the board 5v pin and reset pin after you have loaded your program into it. If the comport on your pc is already set for 9600 baud, then you can skip the mode line in the batch file.

I forgot to ask the obvious...

What is the difference between sending a command using "Serial Monitor" and a .bat file that would cause the arduino to reset?

Is it the particular commands in the .bat file that cause the arduino to reset?

The baud rate is the same - should I change the baud rate?


With batch files, PHP, and similar applications sending data to a com port (which is treated somewhat like a file), the com port is opened, the data is sent, then the com port is closed. When a com port is opened (at least in windows), the DTR line is momentairly blipped high, then back low as a signal mechanism to the gizmo on the other end. I think the DTR going high is used to momentairly pull the arduino reset pin low, causing a reset.The serial monitor and other similar applications keep the com port open when in use, so the DTR never goes high after the first time, so no reset after the first reset. the resistor just keeps the reset pin from going low enough to cause a reset when the DTR line is blipped.

Thanks for the explanation zoomkat,

I will try to disable auto-reset and see if it solves the problem.

The reason I want to use .bat files is that I have a windows program that I like to use that runs .bat or .exe files after certain events.

Thanks again.

Keep in mind that the auto-reset is used when downloading sketches to the Arduino. If you disable the auto-reset, you will have to manually reset the Arduino when downloading sketches.

If you disable the auto-reset, you will have to manually reset the Arduino when downloading sketches.

Or just remove/disconnect the resistor.

I figured out how to use windows .bat files to send commands to an arduino pro mini instead of using serial monitor.

a) configure port settings

  • open up the properties dialog box for the usb-to-serial com port
  • select the following options under the port settings tab - click the advanced button
  • serial enumerator - yes
  • set rts on close - yes

b) syntax in .bat file

the following works:

MODE COM3:9600,N,8,1 >NUL

the following does not work:

MODE COM3:9600,N,8,1>NUL <======= no space before >
ECHO 1>COM3 <======= no space before >

Don’t ask me why…

c) connect 120 ohm resistor across vcc and reset

  • with resistor in place communication works and servos move - good
  • without resistor led flashes on arduino and it resets - not good

Thanks for all the assistance.

By the way, Serial Monitor works with or without the resistor in place.
I’ve soldered in a jumper that I can remove when I want to reprogram the arduino

I’ve marked this thread as [Solved].

Using the "mode" line will slow down the batch file execution somewhat. You can set the pc comport to 9600 in windows control panel (I think 9600 is the default), comment out the mode line like below, and have a faster executing batch file. You can use notepad to make the batch files on the desktop, then double click them for testing.

@echo off ::mode com5:9600,N,8,1 >nul echo 1500 >com5


I started this post a long time ago and everything seemed to work fine on an xp machine.

I’ve switched over to Windows 7 and here’s my problem:

I have the 5V pro mini connected to some servos and some photomos relays - servos are powered by a separate 5V power supply - ground is connected to usb ground on circuit board.
Everything works fine using the serial monitor.
I have a 200 ohm resistor across the 5V and RST on the arduino pro mini - I have checked the resistance across both pins and it’s 200 ohms - I have a switch that I can flip when I want to reprogram the arduino.
I can send commands across the serial monitor and everything works fine.
When I use a batch file the arduino tends to reset.
I have noticed that with the resistor hooked up between 5V and RST I CAN STILL REPORGRAM THE ARDUINO.
I can’t figure out why - seems that auto reset is not being disabled by the resistor.
Is the arduino damaged or am I doing something wrong.
Any suggestions?
Unfortunately, I don’t have an xp machine to test everything out - I have set the com port settings as above.