28BYJ-48 stepper motor and ULN2003

Place code snippets and demo code here
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

28BYJ-48 stepper motor and ULN2003

Post by Fernando Perez »

I have followed with great interest the recent thread on stepper motor control.
Although I have in my drawers several motors from recycling printers, scanners, even old 5" ¼ floppy drives, I cannot find any driver to be able to carry out experiments with the new library incorporated into Annex32.
Being now with other projects and not imagining (at the moment) any really practical application for me of these motors, stops me from purchasing the motors you are using and their drivers.
But I also found a box with very cheap UNIPOLAR motors type 28-BYJ-48 and their corresponding ULN2803 controls and I couldn't resist the temptation of adapting to Annex32 an old code that I wrote in Bascom for AVR and I checked it works well in Annex.
Although the tests are done with an ESP8266, it should work equally well on ESP32.
It is a minimal code, only for demonstration, but in the ESP8266 I still have enough GPIOs to incorporate any sensor, mechanical or optical, that allows the program to know the exact position in space of the mechanical part associated with the motor, a kind of "home" to return to at any time. For example, when starting.
I am successfully using a tiny round magnet and a glass tube reed switch.
I copied the image of the ULN2003 controller and the 28BYJ-48 motor from the Fritzing forum.
image.png
https://youtu.be/KpC2g2prKME

Code: [Local Link Removed for Guests]

IN1 = 15
IN2 = 14
IN3 = 13
IN4 = 12

pin.mode IN1, output
pin.mode IN2, output
pin.mode IN3, output
pin.mode IN4, output

dim patern(7, 3)
for i = 0 to 7
  READ patern$
  for j = 1 to 4
    patern(i, j-1) = val(mid$(patern$, j, 1))
  next j
next i    

do
  move 4095, 0, 1
  pause 2000
  move 4095, 1, 1
  pause 2000
loop

END  


SUB move(steps, dir, speed)
LOCAL i, pos

  if dir = 0 then pos = 0 else pos = 7
  
  for i = 1 to steps
  
    pin(IN1) = patern(pos, 0)
    pin(IN2) = patern(pos, 1)
    pin(IN3) = patern(pos, 2)
    pin(IN4) = patern(pos, 3)
    
    pause speed
    
    if dir = 0 then pos = pos + 1 else pos = pos - 1
    if pos = 8 then pos = 0
    if pos = -1 then pos = 7

  next i    
      
END SUB


DATA "1000","1100","0100","0110","0010","0011","0001","1001"
You do not have the required permissions to view the files attached to this post.
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by Electroguard »

Thanks Fernando, is good to know they can be used with Annex... I have a couple which I bought ages ago for less than a fiver simply cos they were (are) so cheap and abundant.
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 124 times
Been thanked: 132 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by AndyGadget »

Hi Fernando. I'm working on a project (reflector telescope focusser) using one of these steppers but finding its lacking enough grunt to do the job.
I assume you were using the commoner 5v version of the motor and just wondered if you tried running at a higher voltage. I'm thinking of a 2 cell LIPO (8.4V fully charged). If you tried, I'd be interested to know the result.
I think I've got a spare one somewhere so will probably try it myself and if it overheats I'll buy the 12v version and run from a 3 call LIPO.
(Obviously I'll be dropping whatever voltage I use down to 5v for the ESP32 module.)
BeanieBots
Posts: 344
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 182 times
Been thanked: 112 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by BeanieBots »

Andy, many years ago I did a project (PICAXE based) that might do what you want.
I'm afraid I forget the part number but there is a common stepper driver module that has a little pot to adjust the current.
If you remove the pot, you can feed it with a voltage (from pwm via an RC and hence under program control).
The requirement of the project was to drive the stepper and then drop the current to save power.
In your case you could increase the current, drive to wherever and then drop it to just hold position and hence avoid overheating.
Might work, unless it needs continuous driving.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by Fernando Perez »

Andy, greetings.
These motors are very cheap because they seem to be manufactured in large quantities for use in air conditioners and similar appliances. But I don't know if the resolution will be the most appropriate for use in a telescope.
I personally wouldn't force the supply voltage to increase torque.
Before, you can play with the control method, among the three possible ones, simple sequence, wave or half-step. You can adapt my program by changing the DATA variables.
In wave mode, it has maximum torque but lower precision than my half-wave sequence.
You can also attach a reduction mechanism to the shaft, or convert it from a unipolar motor to a bipolar motor and take advantage of Cicciocb's library. Although you will have to replace the ULN2803 with an A4988.
Search the Internet for "28BYJ-48 increase torque". There are hundreds of results:
https://ardufocus.com/howto/28byj-48-bipolar-hw-mod/
https://everythingsmarthome.co.uk/conve ... re-torque/
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 124 times
Been thanked: 132 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by AndyGadget »

Thanks both.
I've written my own half-step code for this and it's working fine. I've got 3 touch sensors using drawing pin heads. Up, down and coarse/fine. Just touching the up or down sensor will give fine control (slow stepping), touching the coarse /fine control as well will give a faster speed.
I was just trying the cheap and cheerful approach first, thinking the high gearing on those motors (508 half steps per rev) might give sufficient torque but it's not quite enough with the weight of a good-sized eyepiece on the focusser.
I've seen a compact stepper with worm drive and high reduction ratio so I may invest in one of those. It's 4 wire not 5 so I'd use a standard 3D printer type for driver module.

Sods law has just struck 😳
The ESP32-S2 mini I was running this on has just died. No ping, no serial port detected. It was working last night. Ah well, plenty more where that came from.
Last edited by AndyGadget on Sat Nov 25, 2023 7:51 pm, edited 1 time in total.
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 124 times
Been thanked: 132 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by AndyGadget »

I didn't realise full-stepping gave more torque then half step. I'll look into that and those links.
Ta.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by Fernando Perez »

AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 124 times
Been thanked: 132 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by AndyGadget »

Just looked at the unipolar to bipolar mod and it looks like that may give me the torque I need. I've got a couple of suitable driver modules already.

A full blown star tracker is something I've considered building with a 35mm camera lens and a low-end astrophotography sensor. Webcams can be adapted; I've done this but the sensitivity isn't really good enough.
There's a really good and free astronomy app, Stellarium, which has an API it's easy to pull real-time altitude/azimuth data from. Getting this to control a pair of steppers would be an interesting challenge. I've already done part of this to make a manually guided device with positional feedback from a gyro on the telescope. The problem with this I haven't been able to overcome is the upset caused to the gyro by a metre long steel tube (the telescope) upsetting the local magnetic field.
BeanieBots
Posts: 344
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 182 times
Been thanked: 112 times

Re: 28BYJ-48 stepper motor and ULN2003

Post by BeanieBots »

Now that you've teased us with a description, you have to post a picture.
Post Reply