Comments on: Driving a 28BYJ-48 Stepper Motor & ULN2003 driver with a Raspberry Pi https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/ Mon, 31 Aug 2026 06:55:23 +0000 hourly 1 https://wordpress.org/?v=7.1 By: ULN2003 Stepper Motor Driver Pinout https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-2469 Mon, 31 Aug 2026 06:55:23 +0000 https://ben.akrin.com/?p=9768#comment-2469 […] ULN2003 with Raspberry Pi […]

]]>
By: Beachfinn https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-853 Fri, 26 Sep 2025 16:45:50 +0000 https://ben.akrin.com/?p=9768#comment-853 Super nice write-up (2025), the value of these is tremendous! Just happened to have the same setup, very useful general info too.

]]>
By: Benoit https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-852 Wed, 26 Mar 2025 17:25:06 +0000 https://ben.akrin.com/?p=9768#comment-852 Thanks a lot!
I used it as is and plugged the 5V to my raspberry. Worked a charm. If I may, I added a little input that mightt save time to some of you, by re placing the “direction” line (line 15):

angle = input("Rotation angle in degrees: ")
step_count = int(4096/360*abs(float(angle)))  # 5.625*(1/64) per step, 4096 steps is 360°

if float(angle) > 0 :
        direction = True
        print("clockwise")
else: 
        direction = False
        print("anticlockwise")
]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-851 Sun, 13 Oct 2024 12:51:51 +0000 https://ben.akrin.com/?p=9768#comment-851 In reply to Gareth.

Hah! if it works, it works. I’m glad this helped :).

]]>
By: Gareth https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-850 Sun, 13 Oct 2024 10:28:41 +0000 https://ben.akrin.com/?p=9768#comment-850 Thank you – that saved me a lot of hunting around – and gave me confidence that I wouldn’t blow things up on my first motor project!
Although I must confess to sneaking the 5V off the Pi – real project will behave better.

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-849 Mon, 22 Apr 2024 15:25:45 +0000 https://ben.akrin.com/?p=9768#comment-849 In reply to HotfixCowboy.

Someone in the comments pointed out that this same motor is sold at various gear ratios. https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-840

]]>
By: HotfixCowboy https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-848 Sun, 21 Apr 2024 01:49:22 +0000 https://ben.akrin.com/?p=9768#comment-848 Thank you for your guide, I was able to get my stepper spinning!

I visited the linked website (http://www.4tronix.co.uk/arduino/Stepper-Motors.php). Its step sequence ends with [1,0,0,1], and begins with [1,0,0,0]. But this didn’t matter and the step sequence works fine either way.

The website also says 512 steps for 360 degrees. I don’t think the 8 phases of each step can be subdivided, so the stepper’s angular resolution becomes ~ .7 deg/step.

Am I understanding this correctly? It’s unnecessary I suppose. I don’t think this motor is suitable for applications demanding that level of precision. An integral proportion between steps and degrees would’ve been nice.

]]>
By: Stéphane M https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-847 Wed, 06 Mar 2024 13:51:46 +0000 https://ben.akrin.com/?p=9768#comment-847 In reply to Biel Palomar.

Hi Biel,
I guess your Pi doesn’t have enough power to make your motor run. You should use an external power supply (what is recommended to do whatever the motor, actually).

]]>
By: Rik https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-846 Wed, 07 Feb 2024 09:15:07 +0000 https://ben.akrin.com/?p=9768#comment-846 In reply to ben.

Hi Ben

Sorry for my late reply (been mothered with non playing wav files – all sorted now).

Many thanks for your swift reply and advice. I agree it’s a terrible way to incorporate your script. I’ll look into something else.

Thanks again – glad I came across your site.

Rik

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-845 Fri, 02 Feb 2024 14:55:30 +0000 https://ben.akrin.com/?p=9768#comment-845 In reply to Rik.

I’d have to see your code, but importing the snippet I gave as a mean to run it seems like a terrible way to call it :). It’s not a library, it’s a fully fledged (albeit distilled to the essential) program that’s sets up the pins when it starts, and cleans them up when it stops. It’s not surprising it wouldn’t work when you’re calling it twice in the same context.

The thing to do here, is copy paste my code within your code, and arrange it so the “meat” section is a function you can call at will, ideally with a step count as a parameter.

I hope this helps.

]]>
By: Rik https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-844 Fri, 02 Feb 2024 14:27:51 +0000 https://ben.akrin.com/?p=9768#comment-844 Hi – absolutely brilliant – simple and effective and got me rolling straight away so firstly thanks for putting this up. Not sure if I’ve missed this but I’m trying to import and call 2 versions one after the other ( ie creating a new file / module which calls your 360 version and then a 180 version straight after). However, I’m guessing there’s something in the coding that’s stopping my 180 (or any further) version from executing once the 1st one has stopped. I’ve even added a sleep(5) in between import mod1 and import mod2. Any clues please?

Much appreciated

Rik

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-843 Tue, 30 Jan 2024 13:01:11 +0000 https://ben.akrin.com/?p=9768#comment-843 In reply to ben.

To answer your question more specifically about why the code doesn’t error out: it is doing what it is supposed to and activating the GPIO pins properly. From Python’s perspective, everything went well. There is no mechanism for it to be aware that this had no effect on the stepper motor or its driver.

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-842 Tue, 30 Jan 2024 12:55:50 +0000 https://ben.akrin.com/?p=9768#comment-842 In reply to Biel Palomar.

Yes, the Pi can’t supply enough power. It can indeed supply 5V, but definitely not with enough amps. That’s why there’s an external power supply in the circuit. In general physical motion (motors) takes lots of power and doesn’t want to be powered by the logic. Another good reason is that motors often create massive interference on circuits and you don’t want them messing with the logic side, so it’s better to keep them decoupled from it.

]]>
By: Biel Palomar https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-841 Tue, 30 Jan 2024 09:54:18 +0000 https://ben.akrin.com/?p=9768#comment-841 Hi,

I have the motor board powered directly from the raspberry, i execute the script and there is no error message, any idea why it executes but there is no movement from the motors or even the leds? Thank you so much.

Biel Paloamr

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-840 Fri, 05 Jan 2024 20:47:21 +0000 https://ben.akrin.com/?p=9768#comment-840 In reply to Jotiraditya Gokaraju.

The short answer is yes. I’ve been running various projects for thousands of hours without missing a single step.

The long answer, and what you are alluding to correctly, is that Pi processors are shared between multiple processes and sleeping a certain amount of time between steps is not guaranteed. Here’s what I found though illustrated as an example. If I sleep for 0.0002 seconds between steps, it’s not guaranteed I’ll sleep exactly 0.0002 seconds, but it’s guaranteed I’ll sleep AT LEAST 0.0002 seconds. In the real world, when I hear my motors step, they have a very consistent sound, but if I SSH into the Pi and start running a bunch of commands competing for the CPU, I’ll hear the motors slow down at bit. Maybe that’s an issue for some projects with CPU volatility and where consistent motor speed being required. But it’s never been an issue for what I’m working on.

]]>
By: Jotiraditya Gokaraju https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-839 Fri, 05 Jan 2024 19:58:36 +0000 https://ben.akrin.com/?p=9768#comment-839 Is the Linux on Raspberry Pi conducive to a stepper motor? Since you need exactly timed pulses to move it a certain amount, would the Raspberry Pi be able to move it an exact number of degrees consistently?

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-838 Tue, 13 Jun 2023 02:37:36 +0000 https://ben.akrin.com/?p=9768#comment-838 In reply to Mauricio.

You can grab any of the available GPIO pins (https://pinout.xyz). Make sure to ground it too.

]]>
By: Mauricio https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-837 Tue, 13 Jun 2023 02:30:43 +0000 https://ben.akrin.com/?p=9768#comment-837 Great tutorial it worked for me… How could I connect 2 of the same motors to raspberry pi(to do different things)? is it possible?.. what pins could I use additionally for the other motor?

]]>
By: David https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-836 Mon, 01 May 2023 14:50:44 +0000 https://ben.akrin.com/?p=9768#comment-836 In reply to ben.

Thanks Ben,

I’m very glad to read your answer. In one of your videos I heard some French, so it makes sense with what you say regarding your sister. For sure she sould be Casteller in Paris or Toulouse.

USA is a great country, with more diversity than is transmitted through the news and stereotypes. Just a sample: I am writing this after attending a concert in Barcelona by the great Bruce Springsteen. I’m a big fan. He has always been a rebel and a committed man.

Concerning Catalonia, well,… just trying to preserve language ​​and culture, which is difficult in this globalized world if you don’t have a state behind. But always, keeping the doors open to everyone who needs it, with solidarity, There are millions of people who, just because of their place of birth, have less opportunities than us.

Best wishes to you and your family.

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-835 Sat, 29 Apr 2023 20:35:38 +0000 https://ben.akrin.com/?p=9768#comment-835 In reply to David.

David,

bon dia, I was very lucky to spend several Summer vacations in Catalonia and I found it to be an incredible place. The culture is strong and the people are super nice. My sister is a Casteller in France, this tradition is exceptional and I show videos of it to my kids. Because they show amazing kids, but also because the exercise is the antithesis of American individualism :). It’s good for them to see both.

In any case, I won’t bore you with my vacations, but your place is a truly special one in the world, and from it there isn’t much to envy.

I’m glad I was able to help you drive your motor, and I’m suprised you were able to power the motor with the Pi :). Motors usually wreck havoc on circuits and you want to decouple them from the logic and other sensitive things. But hey, if it works it works :).

Take care and good health to you too.

]]>
By: David https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-834 Sat, 29 Apr 2023 13:48:15 +0000 https://ben.akrin.com/?p=9768#comment-834 Thanks Ben for your post.
It was very easy and useful.
As I do not have external power supply, I have powered the motor and ULN2008 with Raspberry Pi 4. As said, it perfectly worked.

What it’s more amusing is that I have descovered your web page. Congratulations. It’s fantastic. This lifestyle and projects are inspiring. They even make me a little jealous. Healthy envy. And they bring back a little hope in the human being. Good luck and good health from Catalonia.

]]>
By: charmys https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-833 Wed, 12 Apr 2023 21:22:36 +0000 https://ben.akrin.com/?p=9768#comment-833 In reply to Don Warr.

there are multiple gear ratios for this stepper whilst his is most likely 1:64 yours is 1:16

]]>
By: ben https://ben.akrin.com/driving-a-28byj-48-stepper-motor-uln2003-driver-with-a-raspberry-pi/#comment-832 Thu, 23 Mar 2023 13:10:01 +0000 https://ben.akrin.com/?p=9768#comment-832 In reply to Don Warr.

Oh wow, I’m glad there’s an explanation. I never came upon the 1/16 ones, thanks for finding out.

I think that most stepper drivers have a “brake” mode that does draw current to stay in position, and a “free” mode that draws no current but lets the motor move is force is applied externally.

]]>