How to program an ATmega Nano

What I need to happen.
2 Nano’s driving 1 stepper motor each, both running at variable speeds and both motors periodically reverse
direction, see the link below of what i want to achieve.
I don’t want to use springs and pulleys, but want to combine electronics with wood craft.
Space is important, hence Nano’s, but if anything else is better, I am open to suggestions.
I have read a lot about Nano’s but can’t find how to achieve my goal. Any help greatly appreciated.

Hi Frank.

That kinetic art is stunning.

I build projects around Nanos. I reckon programming the Nano will one of the easier components of your project and least time consuming. A typical approach would be to start with the tutorials for controlling stepper motors. Duplicate those to learn how things work then customise the program to suit your needs. Plenty of help available if you get stuck.

You won’t be learning Nano programming, but Arduino programming. You might need to research if Nano is the most appropriate board – will it be able to provide the current needed by the motors? I don’t know.

Will the Nanos be located in the artwork itself?

Keep us updated.


Thanks for your reply John,
I have been stuffing about and I discovered that I can put the “blink” sketch into the nano, so the other sketch should work OK as well. (Still have to write it, though). I still need a few other parts before I try it out. Thanks for your pointers, I shall heed them.
I am not certain that the nano is the best board for the job, I suppose I’ll find out. One question, John.
Can ONE nano drive both steppers? I think it’s possible, but it would be great to have it confirmed by an expert. Also, if I put my sketch up in the forum would you or anyone else be good enough to check it out for me and correct it?
I’ll try to incorporate the nano visibly into the wood work, maybe even use a remote control (if I am good enough). John, if I may ask, what projects have you been doing with the nano?


I just searched on “Arduino stepper motor tutorial”. Many results.

The first I looked at is:

This states you cannot provide adequate current to the motor from the Arduino (UNO, but would apply to the Nano). They say a stepper motor driver is required. That’s a small board that’s powered from the source providing power to the Arduino, but not via the Arduino’s output pins. So the Nano will be fine for logic but it will command the driver board and that commands and powers the motor.

I expext one Nano would be able to drive more than one motor. Each motor would need its own driver board but all control signals would come from the single Nano. Perhaps not if you wanted to drive them simultaneously. I haven’t used stepper motors.

I’m by no means an expert – being exploring Arduino for six months. Not hard.

Yes, people will help you with problems but don’t ask them to write the code for you. As some wag on another forum said: “We won’t tell you how to put your pants on.” :wink: You’ll be fine. People are pleased to help.

I like the idea of the Nano being a visible part of the work. RC is a definite possibility. Bluetooth. Not hard. You would be able to control it from a phone. Viewers could interact with it.

My projects: a GPS speedometer and overspeed alert for my car; a parking assist; an SMS alert device using bluetooth because I often don’t hear the phone alert.

Good luck.

Thanks John,
I will order the parts tomorrow and get the show on the road.
I am happy to write the sketch and and see if it works out, but help is always appreciated. I fully agree, I’ll put my own pants on :grin:
Thanks again for your help

Hello John and everybody,
I got hold of a sketch by MarcoGPS, which uses stepper motors.
I amended the sketch somewhat to my needs.
May I publish this amended sketch on here and get comments/hints/help, please.
I ordered my parts and now it’s just a matter of waiting.
Thanks to all, especially MarcoGPS and John.

Hi Frank,

We have a tutorial on Stepper motors that you can find here:

Core electronics’ tutorial on GPS got me going when I was not having success with others. I’ll help where I can.

Thank you both, your help is very much appreciated.
Let’s see what I come up with in a couple of days/weeks.

Frank, will we get to see the finished art work?

The short answer is: YES.
I shall make an small movie and put it up here, I need to get a few parts and do
a lot of trial/error stuff. Presently, I am quite busy with Council stuff/meetings, so sometimes some important things have to be put on the back-burner.

1 Like

I am working with pro mini, which is basically a nano minus the USB connector (so even smaller). I figure what you want can be accomplished with two L293D motor driver ICs driven by your nano. The L293D will drive small steppers and less than $1 if you buy a few. I haven’t done it myself, but if you type ‘l293d arduino stepper’ into your search engine there’s a heap of information out there. There’s enough output pins on the ATmega328/P to drive two L293Ds concurrently but I don’t know if there’s sketches for it. I program in assembler so it wouldn’t be an issue, it is possible to drive 12 outputs without using the TX RX (used to program the pro mini).

Thanks for that Alan,
I ordered a couple nanos and ULN2003’s so I’ll stick with them, it’s hard for an old dog to learn new tricks :slight_smile:
But thank anyhow.
I got the cw code, now I need the coding for increasing and decreasing the rotation as well as going ccw.
It should go into the same sketch of the nano.
I think I’ll need some help soon :frowning:

I am just investigating the various “File_Examples_Stepper” codes.
When I try to put them into my nano, i get an error message “Error compiling for board Nano”
Obviously I am missing something, where am I going wrong, please?
Cheers CrankyFrank :slight_smile:

I’m not of much help there. I
think the error is a generic error and there would be a more
specific error somewhere else. I use assembler in Atmel Studio
and then use avrdude to load the program into the pro mini so
not familiar with the Arduino programming environment (and not
too good with C). Ask me most things about the Atmega328 and I
may be more useful.


Does this happen only with the Stepper examples? What about the Bare Minimum sketch? Does that compile?

There are two stages to getting the sketch onto the Nano: compile & upload. Just do the compile (also called verify/compile). If it’s a compile problem, no point attempting upload.

What operating system?

Always have Windows Device Manager running. Open the Ports (COM & LPT) tab. This shows the devices connected to COM ports. Does your Nano appear? Might be listed as “USB-SERIAL CH340 (COMxx)”. The “xx” number is the port you specify in the IDE.

Always try unplugging & replugging the Nano. Some issues just fix themselves.

Can you cut & paste the compile messages so we can see exactly what happens?

Hi John and Alan,
Been a bit busy today, sorry. I have to go thru the stuff myself to find out what’s wrong. I think it wants something else connected that was NOT connected to the nano? BUT in the meantime, I tried other examples (examples-stepper-oneRevolution) which compiled and loaded OK.
The way I understand it is: it should run cw and then ccw, but it only runs cw. I have delay 500ms, so I know when it should start and run ccw.
BTW, the little motor is quite warm to touch (would that be normal?) It’s running on 6 V powersupply driving ULB2003 AND the uno
Sooner or later, I’ll get my head around it. :slight_smile:
I want a variable cw speed and I variable ccw speed. If you got any suggestions, great.
thanks for your help, fellows.

Stepper Motor Control - one revolution

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.

The motor should revolve one revolution in one direction, then
one revolution in the other direction.

Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe


#include <Stepper.h>

const int stepsPerRevolution = 16; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
// set the speed at 500 rpm:
// initialize the serial port:

void loop() {
// step one revolution in one direction:
myStepper.step(320); //(stepsPerRevolution)

// step one revolution in the other direction:
myStepper.step(-300); //(-stepsPerRevolution)

I compiled all the stepper examples & uploaded to a new Nano without anything connected. No errors. I wouldn’t expect the compiler or uploader requires that devices be connected. They run; the TX led blinks and I get the “clockwise” & “counterclockwise” messages on the monitor.

I tried to compile your script but got ‘stray "/3241’ or something like that. Haven’t figured that out.

Be wary of any component that gets warm. It might be normal or might indicate mistaken wiring. Looks like the direction simply depends on the sign of the value in the parenthesis, so maybe there is a mis-wiring somewhere.

Hi John, I send a PM