Root cellar automation: Running two 28BYJ-48 steppers from same driver and power from Arduino

I apologize for any base concepts or obvious errors I may have made in my wiring/coding, I did as much research as I could. This is my first project that I am making that isn't just the Arduino starter kit tutorial and I am very much a beginner in this domain.

The parts in the project are as follows:

  • 1 Arduino Uno (Rev3) (900mA capacity if powered by power adapter)
  • 2 28BYJ-48 Stepper motors (200mA at full step)
  • 1 ULN2003 driver board
  • 2 DS18B20 waterproof temperature probes (1mA)
  • 1 4.7K resistor
  • 1 12VDC 2A power adapter

The goal of this project is to automate my root cellar ventilation by opening and closing valves based on the inside and outside temperature . I would also like to eventually add an LCD readout, as such I want to keep some digital pins open for future expansion.

I saw after some research that the data cables from the probes can go to the same pin because they have unique 64 bit serial code that can be recognized. I will run another code while everything is plugged to recognize the probe order before uploading the final code.

I also found information pointing towards being able to run multiple 28BYJ-48 steppers on the same ULN2003 driver, but I couldn't find any examples of people actually doing it. Some people ran the steppers directly from the board and others said it would fry the board.

Since each motor is 200mA and the probes are 1mA it should total to about 402mA which is far less than 900mA. Heating problems from using a 12V adapter could also be mitigated since I only want the motors to move at 5 minute intervals for a quarter turn.

Some parts are still missing for me to physically build it, but I wanted to pass this by people more familiar with such projects before risking burning the board.

Here is the code I wrote based on a few projects I saw online and testing. There is only one driver for both stepper motors which is why there is only one set of outputs for the steppers.

#include <OneWire.h> 
#include <DallasTemperature.h>
#include <AccelStepper.h>

#define motorPin1  2      // IN1 on the ULN2003 driver
#define motorPin2  3      // IN2 on the ULN2003 driver
#define motorPin3  4      // IN3 on the ULN2003 driver
#define motorPin4  5      // IN4 on the ULN2003 driver
#define MotorInterfaceType 4 // set the motors to FULL steps
#define ONE_WIRE_BUS 6 //sets the temperature bus to be in digital pin 6

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices  
DallasTemperature sensors(&oneWire); // Pass oneWire reference to Dallas Temperature.

float inC=0; //creates inC variable
float outC=0;//creates outC variable
float MaxC=4;
float MinC=0;//creates variables for max temperature and minimum temperature tolerated for easy change
unsigned long previousMillis = 0; // create time variable previousMillis
const long interval = 300000; //5 minute interval

AccelStepper Ventstep = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4); //set up rotation order for steppers
void setup() {
  Ventstep.setMaxSpeed(1000); //set max speed
  Ventstep.setCurrentPosition(0); //define current position as 0
  Serial.begin(9600); // open serial port
sensors.begin(); 
  // Start up the temperature sensors 
}
void loop() {

  
  unsigned long currentMillis = millis(); //make a variable which equates to the amount of time passed
  if (currentMillis - previousMillis >= interval) {// start code when 5 minute interval has passed
    previousMillis = currentMillis; //set previousMillis to currentMillis for the next cycle
  sensors.requestTemperatures(); 
  inC=sensors.getTempCByIndex(0);//uses the libraries to read the sensor and save the reading as inC variable (0) refers to first sensor on the pin assumed to be inside for now
  outC=sensors.getTempCByIndex(1);//uses the libraries to read the sensor and save the reading as outC variable (1) refers to second sensor on the pin assumed to be outside for now
 Serial.print("Cold room:  "); //sends (Cold room:  ) as text to the serial port
 Serial.print(inC);//sends (inC) value to serial port
Serial.print("°C   ");//sends (°C) to serial port
Serial.print("Outside:  "); //sends (Outide:  ) as text to the serial port
 Serial.print(inC);//sends (inC) value to serial port
Serial.println("°C   ");//sends (°C) to serial port
Serial.print ("Vent state:  "); //sends (Vent state:  ) as text to the serial port

if (Ventstep.currentPosition() == 0){ // checks step of Ventstep and send back text to serial port accordingly
Serial.println ("Closed");}
else if(Ventstep.currentPosition() == 509){
Serial.println ("Open");}
else if(Ventstep.currentPosition() != 509 && Ventstep.currentPosition() != 0){
Serial.println ("PosErr");}

if(inC >= MinC && inC <= MaxC && outC >= MinC && outC <= MaxC ){//opens valve 90 degrees if Inside and outside temperatures are within margins
while (Ventstep.currentPosition() != 509) {
    Ventstep.setSpeed(-500);
    Ventstep.runSpeed();}
}
else if(inC >= MinC && inC <= MaxC && outC <= MinC){//closes valve if inside temperature is within margins but outside is cold
while (Ventstep.currentPosition() != 0) {
    Ventstep.setSpeed(500);
    Ventstep.runSpeed();}
}
else if(inC >= MinC && inC <= MaxC && outC >= MaxC){//closes valve if inside temperature is within margins but outside is hot
while (Ventstep.currentPosition() != 0) {
    Ventstep.setSpeed(500);
    Ventstep.runSpeed();}
}
else if (inC <= MinC && outC <= MinC){//closes valve if inside and outside temperatures are cold
while (Ventstep.currentPosition() != 0) {
    Ventstep.setSpeed(500);
    Ventstep.runSpeed();}
}
else if (inC <= MinC && outC > MinC){//opens valve if inside temperature is cold but outside is above minimum
while (Ventstep.currentPosition() != 509) {
    Ventstep.setSpeed(-500);
    Ventstep.runSpeed();}
}
else if (inC >= MaxC && outC >= MaxC){//closes valve if inside and outside temperatures are hot
while (Ventstep.currentPosition() != 0) {
    Ventstep.setSpeed(500);
    Ventstep.runSpeed();}
}
else if (inC >= MaxC && outC < MaxC){//opens valve if inside temperature is hot but outside lower than maximum
while (Ventstep.currentPosition() != 509) {
    Ventstep.setSpeed(-500);
    Ventstep.runSpeed();}
}
}
}

I will add two analog inputs to reset Ventstep.currentPosition either to 0 or 509 when after a power outage.
I wanted to post the wiring diagram I drew in Fritzing but as I am a new user, the forums won't let me.

I know I am posting a lot of information, but I want to know if I am making any major beginner errors.

Edit: i had put 2 ULN2003 drivers, but I am only using 1

Where did you get that 900mA figure from - it's a lot higher than anything I've ever seen for the Uno.

This isn't the source i initially found the information, but it says the same thing regarding the 5v pin when connected by a power adapter rather than the USB.

If it's wrong I was thinking of splitting my power adapter cable in two to power the Arduino Uno and the stepper driver in parallel

As far as I know, the limit if you're using the barrel Jack is 150 mA because the voltage regulator will shut down from over temperature if you try to pull more.

USB power gives 500mA.

Regardless, the Arduino is a controller, not a power supply, so if you want to run anything more than some LEDs, you need separate power, especially if you would like the Arduino to last.

I suggest you change your 12V power adapter to a 5V power adapter. Connect the Arduino directly to the 5V adapter.
And connect the motor and driver directly to the power adapter (i.e. not through the Arduino.)

Regardless, the Arduino is a controller, not a power supply, so if you want to run anything more than some LEDs, you need separate power, especially if you would like the Arduino to last.

Than you for the advice. I'll power the Arduino and driver separately and keep this in mind for future projects

I suggest you change your 12V power adapter to a 5V power adapter. Connect the Arduino directly to the 5V adapter.
And connect the motor and driver directly to the power adapter (i.e. not through the Arduino.)

The reason I was going to use 12V is that I bought a bundle of 4 to power a homemade soldering fan. I'll check if I have a loose 5V adapter somewhere, but if I don't have one, what would be negative effects of using the 12V? (the driver can also be powered by either 5V or 12V)

My last worry would be whether I can really run 2 steppers motors off the same ULN2003 driver.

Read all info in your link carefully:

The 900 mA is for an adapter that provides ~7V. As the adapter voltage increases, the amount of heat the regulator has to deal with also increases, so the maximum current will drop as the voltage increases. This is called thermal limiting

Your adapter provides 12V wich wlll lead to much more power loss of the regulator. And even with a 7V adapter I think 900mA is too much. It means 1.8W for this tiny regulator without a real heatsink.

Follow the advice of @JohnRob , but be aware that the UNO must not be sourced from 5V pin and USB in parallel.

But not your motor, which is connected to the driver.

Your adapter provides 12V wich wlll lead to much more power loss of the regulator. And even with a 7V adapter I think 900mA is too much. It means 1.8W for this tiny regulator without a real heatsink.

I saw that part too, I just thought that maybe it could take it since it's running once per 5 minutes maximum.

Follow the advice of @JohnRob , but be aware that the UNO must not be sourced from 5V pin and USB in parallel.

I'm not sure what you mean here. After taking everyone's advice into account, I would connect a 5v adapter in parallel to both the barrel connector of the arduino and to the UNL2003 driver, the ULN2003 will then run the 2 motors in parallel. The only thing left to power would be the two probes from the Arduino's 5V pin. Apart from that it's just signal inputs and outputs. I would not use a USB at all in this system.

[quote="daemonick6, post:6, topic:951455"]
(the driver can also be powered by either 5V or 12V)

But not your motor, which is connected to the driver.

Thanks, I didn't realise that the driver doesn't regulate the voltage like the Arduino. Rookie mistake.

Your steppers are designed for 5V. My guess nothing bad will happen with 6 or 7 volts, 12V I'm not to sure.

You can purchase a 12V to 5V converter on eBay for not too much $$. However for nearly the same cost you can purchase a 5V supply. Nearly any Phone adapter should work. Most are rated at 1 amp.

You can't provide 5V to the barrel Jack, it needs at least 7V. If you have a stable 5V supply, connect it to the 5V pin.

We used to have a green house attached to our house. It had a thermostat controlled vent and fan and never even came close to needing a microcontroller. Are you just wanting to do this as an exercise?
The louvered vent used a 120 AC motor that would open the vent and stall with it open. When the thermostat removed the power, a spring closed the vent. The motor was specifically designed to stall for ever without over heating.
I am sure the vent system is still available.

I didn't really look into those options, but I don't know if it would work for my situation. I'm guessing that the system only opens when the temperature in the greenhouse goes above a threshold without taking the outside temperature into account? In my case if the temperature goes above the threshold, it has to take the outside temperature into account because it might be higher than the cellar's temperature.

In my case I need to keep the room between 0 and 4 degree Celsius and here in Canada it can easily go from below 0 to over 10 degrees over the course of a day, especially in spring and fall. So there are may different situations where vents should be open or closed.

You are completely right, I had tunnel vision and forgot that fact.

Granted, our place East of Seattle, in the tall fir trees, was always cooler outside. But a second thermostat would surely solve that problem, also. I will see if I can find a link to the type of vent we had. The dog chewed the aluminum shutters once trying to get into the house, so I had to but a new vent and place it high so she could not get to it.

For my tests of imitation UNO https://www.jaycar.com.au/duinotech-uno-r3-development-board/p/XC4410?pos=3&queryId=e50d29c39cc83ad25c5b33c281d41483, 28BYJ-48 Stepper motor, 1602a LCD & joystick.
I used one of these https://www.jaycar.com.au/arduino-compatible-breadboard-power-module/p/XC4606?pos=2&queryId=ae4b1fbeb78da6bf842444cdff521a3e to power my 28BYJ-48 Stepper motor, connected to the 5V-12V connector on the ULN2003 board. RaspberryPi 2.1A power wart powering stepper, LCD & Joystick. UNO powered from a 7 port USB3 adaptor.
My first attempt was powering it all straight from the UNO let the magic smoke out.

If you connect your power source directly to the 5V pin, and in parallel connect the PC via USB, there may be a problem. Because there is no protection diode between USB 5V and UNO 5V-pin, your power source is directly connected to the USB 5V. This may even damage the USB port of your PC. You must disconnect your power source when connecting to USB, or you need an USB cable with the 5V line interrupted.
BTW: the 'classic' Nano has this protection diode ( at least the original ones - with clones you have to check ). So this is not a problem with a Nano.

I found a 5v usb charger plug, would using this and splitting the cable to power the ULN2003 and the UNO work? It would remove the risk of powering the UNO from both sides since I would have to unplug the power to plug the computer.

sounds good :sunglasses:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.