Grad student in need of help

Hello all,

We are doing some research and need some help designing a contraption of sorts. We are in a bit of a time crunch. We are ecologist and are not the very knowledgeable with Arduino so any help you could offer is greatly appreciated.

We need a to make a stepper motor turn 180 degrees (100 steps) with a rainfall sensor when rainfall is detected (not sure on exact 0-1023 value, but will determine that later). Then, when the rain stops, the motor returns to its original position.

I have spent about 30 hour learning what I could about Arduino language, steppers, etc. but have not had much luck. I can get the motor to spin, but not step a certain number of steps.

Here is my equipment:

Arduino Uno
6 wire Stepper (Portescap - 23H018D20U)
Microstep Driver (ST-4045-A1) - powered with 12 volt battery
Breadboard
Rainfall sensor

With this driver, I read it should be hooked up through the breadboard so that the +5v PUL, DIR, and ENA get 5v from the Arduino and the others go to digital outputs on the Arduino. Only problem is i'm not sure how to control it this way, and I haven't had much luck looking online.

Any input would be very valuable as we are at a loss and now running out of time before a grant deadline.

Thank you for looking,

Mark

Unless you plan on turning more than 180 degrees later you might want to use a hobby servo instead. They can easily be positioned at 0 degrees and 180 degrees and have internal position feedback so they won't lose position if power drops like a stepper would.

Unfortunately we must use what we have here (out of money for this portion of the research) unless it is something small I can purchase on my own. Additionally, the motor needs to rotate an arm with a lid on it. It will be light, but i'm not sure if a hobby servo could move it easily.

I looked at this post http://makezine.com/video/driving-big-stepper-motors-with-arduino/

From what I can tell, this stepper motor driver enables you to control the speed by just sending a PWM signal (hence the digitalWrite from HIGH to LOW with a set delay). I was under the impression that many stepper motors can have the position set directly, but maybe not with your setup.

What I would do, given you want to keep all the same components, is buy a mechanical encoder. I've used these and they work well and are super cheap.

From there, you set up a PID loop to control the position of the servo by setting the speed. i.e. you have a reference position, send a speed, measure the actual position, get an error value, push that through PID to get a new speed. This will require calibration, and it is unlikely you will need all three letters (probably only PI actually). There is a PID library you can use for this.

However, I would highly suggest finding a method that just allows you to send a position value directly from code, if it is possible (which I think it is... since it's a "STEPPER" motor)..

mlucius291:
Hello all,

We are doing some research and need some help designing a contraption of sorts. We are in a bit of a time crunch. We are ecologist and are not the very knowledgeable with Arduino so any help you could offer is greatly appreciated.

We need a to make a stepper motor turn 180 degrees (100 steps) with a rainfall sensor when rainfall is detected (not sure on exact 0-1023 value, but will determine that later). Then, when the rain stops, the motor returns to its original position.

Thank you for looking,

Mark

You will have to either have a 'home' position switch, or a physical motion stop to create a 'starting' point for the motion. If you have a switch, you must monitor the switch during each movement, with a mechanical stop you just drive the motor against the stop for the maximum possible number of movement steps. Personally I like the switch method better. for code simplicity I will ignore home position.

Configure the Driver for 1 step per pulse.
enable -> pin D2
dir -> pin D3
pulse -> pin D4
rainSensor -> D5
abortswitch -> D6

#define ENABLEPIN 2
#define DIRPIN 3
#define PULSEPIN 4
#define ABORTPIN 6
#define RAINPIN 5

#define ACTIVEPOSITION 100 // directed distance to inuse position
#define ABORTLED LED_BUILTIN // usually 13

static int position=0; // starts out at home
static short speed=10; // 10 steps per second
static int direction=0; // 1= direction1, -1=direction2, 0=motor off
static bool aborted=false;

bool stop(){
if(digitalRead(ABORTPIN)) {
  if(not aborted){ // just detected abort signal
    Serial.println("ABORT DETECTED!");
    }
  digitalWrite(ABORTLED,HIGH);

  aborted=true;
  }

if(aborted) {// disable motor driver
  digitalWrite(ENABLEPIN,LOW);// force motor controller OFF
  }
return aborted;
}


void moveOneStep(){
unsigned long stepTime=(1000 / speed)/2; // drive pulse will be 1/2 step high,low
unsigned long timeout = millis();
if(!stop()){ // if not aborted, send pulse
  digitalWrite(PULSEPIN,HIGH);
  if(!aborted){ // pulse has been send, adjust position
    position = position + direction;
    }
  while((!stop())&&((millis()-timeout)<stepTime)) ; // twiddle fingers waiting
  digitalWrite(PULSEPIN,LOW);
  timeout = timeout + stepTime; // other half
  while((!stop())&&((millis()-timeout)<stepTime)) ; // twiddle fingers waiting
  
  }
}


void setDirection(int dirIn){
direction = dirIn;

switch(direction){
  case 0 : // no movement, release motor
    digitalWrite(ENABLEPIN,LOW); // de select motor
    digitalWrite(PULSEPIN,LOW); // ready for next motion
    break;
  case 1 : // move in direction 1
    digitalWrite(PULSEPIN,LOW); // ready for next motion
    digitalWrite(DIRPIN,LOW);  // Select correct direction 1
    if(!stop()) digitalWrite(ENABLEPIN,HIGH); // power up driver
    break;
  case -1 : // move in direction 2
    digitalWrite(PULSEPIN,LOW); // ready for next motion
    digitalWrite(DIRPIN,HIGH);  // Select correct direction 1
    if(!stop()) digitalWrite(ENABLEPIN,HIGH); // power up driver
    break;
  default : //unknow motor direction, just shutdown
    aborted = true;
    digitalWrite(ENABLEPIN,LOW); // shutdown motor
  }
}

void goHome(){
Serial.println("Moving HOME!");
while((position!=0)&&(!stop())){
  if(position>0){
    setDirection(-1);
    moveOneStep();
    }
  if(position<0){
    setDirection(1);
    moveOneStep();
    }
  }
setDirection(0); // release motor drive, power savings.  remove if motor needs to hold position
}


void goOpPosition(){
Serial.println("Moving to Position");
while((position!=ACTIVEPOSITION)&&(!stop())){
  if(position>ACTIVEPOSITION){
    setDirection(-1);
    moveOneStep();
    }
  if(position<ACTIVEPOSITION){
    setDirection(1);
    moveOneStep();
    }
  }
setDirection(0); // release motor drive, power savings.  remove if motor needs to hold position
}


void configPins(){
pinMode(ENABLEPIN,OUTPUT);
pinMode(ABORTPIN,INPUT_PULLUP); // abort pin is held low for run mode
pinMode(ABORTLED,OUTPUT);
pinMode(DIRPIN,OUTPUT);
pinMode(PULSEPIN,OUTPUT);
pinMode(RAINPIN,INPUT_PULLUP); // rain sensor grounds pin for activation signal
setDirection(direction); 
}

void setup(){
configPins();
digitalWrite(ENABLEPIN,LOW); // disable motor drive

Serial.begin(9600); // start up Serial monitor for debug messages
aborted = false; 
digitalWrite(ABORTLED,LOW);

digitalWrite(DIRPIN,LOW); // direction 1

digitalWrite(PULSEPIN,LOW); // rising edge is active
Serial.println("Booted at HOME!");

}

static unsigned long timeout=0, movementTimeout=0;
static bool lastRain=false;

void loop(){
if(millis()-timeout>300000L) {
   configPins();  // every 5 minutes reconfig in case static event
   if(aborted) Serial.println("Abort has Been Detected, clear Abort Switch, Reboot");
   }

if(!stop()){ // check rainfall switch
  if((lastRain!=digitalRead(RAINPIN))&&
   (millis()-movementTimeout>30000L)){ // different rain sensor position, and 30seconds since last movement
    Serial.println(" Moving! ");
    configPins();
    lastRain=digitalRead(RAINPIN);
    if(lastRain) goHome();
    else goOpPosition();
    movementTimeout=millis(); // start next movement timeout
    }
  }

}

have fun, you need to add some home position detection, I'm just counting steps from an unknown starting position.

chuck

What kind of switch are we talking about here?

We need this to be autonomous so we can't monitor this setup as it will out in the field and only returned to once a week.

Holy Cow! :o

Yeah...i'm pretty sure it would have taken me years to learn how to write that code. I will give this a try in the lab tomorrow. Thank you.

If you only want to open and close a lid, then you don't need to worry about coding for the stepping motor.

Put a switch at each end ( open, and closed). When the motor moves the lid to the max, it will trigger a switch, and you can turn off the motor, and know where the lid is located.

Have a look at stepper motor basics

Post a link to the datasheet for your stepper motor

Post a link to the datasheet for your stepper driver

Give details (volts and amps) of the power supply you plan to use with the motor.

From what I have read here a hobby servo would be far more appropriate for this application. Some of them are very powerful. They are easy to use mechanically, they have all their electronics included and programming them with an Arduino is as simple as myServo.write(180); and myServo.write(0);

...R

Here is a link to the driver data sheet: cnc-club.ru - Информация

Here is a link to the motor data sheet: http://media.digikey.com/pdf/Data%20Sheets/Portescap%20Danaher%20PDFs/Stepper%20Hybrid%20Technology.pdf

We plan to just use a 12 volt battery without a power supply. Seems to move the motor fine.

I attached a pdf of quick mock up I made of the proposed design. Think a hobby servo would be able to do this?

This was our budget idea for building this: http://kodu.ut.ee/~olli/eutr/LiseFig8.jpg

That unit costs over $5000

Presentation1.pdf (95.4 KB)

Not sure what the gizmo is to do, but if you just need a bucket with a lid that opens when it rains, you might make that with a bucket/lid from home depot, a servo and a few other parts.

mlucius291:
I attached a pdf of quick mock up I made of the proposed design. Think a hobby servo would be able to do this?

That looks like an ideal role for a servo.
How heavy is the lid ?

Of course, if you have already bought the stepper and the driver they could also be used.

I suspect your stepper is over-specced for the job. I thought you needed to lift the lid - but you are only rotating it.

One "problem" with a stepper is that it can't report its own position so you normally need some sort of switch to detect the HOME or ZERO position when the Arduino is started.

Another problem is that stepper motors are very inefficient - they need full power to hold position even when stationary. If you remove the power you can no longer guarantee the position without some other features such as, perhaps, a mechanical brake.

A hobby servo probably has enough internal friction to prevent moving when depowered and, in any case, it "knows" where it is.

...R

You can get a good servo for less than 15$, are you sure you can't afford it ?

We could definitely spend $15 for a servo motor, as long as A) it will move to the lid b) it will be ok in a sealed box outdoors and C) it will run off a 12 volt battery.

Any links to cheap servos that will do the the job? We got our stepper refurbished off of electronic goldmine for very cheap

You need to measure the force and torque required to move the lid before you can decide what motor or servo will be required to move it. To measure force, you can use a small spring scale or digital luggage scale. To convert that to torque, study this introduction.

Most servos run on 5-6 volts, so you would need a buck converter to run off a 12 V battery.

The best use of a servo is to have it only move the object, not try to hold the objects weight. A hinged and counter weighted bucket lid would be easy to make.

zoomkat:
Not sure what the gizmo is to do, but if you just need a bucket with a lid that opens when it rains, you might make that with a bucket/lid from home depot, a servo and a few other parts.

Tracing back the picture that was provided up thread, here's a explanation of the prototype "gizmo" in context: Eutrophication -- 2.6 Measurements of deposition

The gist is that there is a bucket which either has the lid fully on or fully off depending upon whether rain is detected. A stepper motor isn't necessary since the transient "in between" positions are non-critical, but could be made to work if it is strong enough to move the lid mechanism. Likewise for a servo motor, it only needs to know "open" and "closed". The required strength of the motor would depend upon the weight, balance, and potential wind loading of the lid mechanism.

" Likewise for a servo motor, it only needs to know "open" and "closed"."

Both stepping motors, and servo motors are useful to move to a precise position along the path.

If only two positions are required ( full open, and full closed ), neither a servo nor stepping motor is required (but of course can be used).

All that is required is a 12V motor, and a sensor circuit to detect full open and full closed. Of course, you will need to drive the motor bidirectional.

Many options for the sensors; mechanical switch, optical switch, magnetic switch, motor load sensor, and I bet many more.

All that is required is a 12V motor, and a sensor circuit to detect full open and full closed. Of course, you will need to drive the motor bidirectional.

For $10-$20 a big (15kg-50kg) servo can be obtained, and with a good, well balanced, and thought out bucket/lid design, the project should be doable. A lot depends on the OP's mechanical design ability.

Yes, the OP's mechanical design ability is a big factor.
This 12v geared motor would be sorta what I would envision.

http://www.ebay.com/itm/DC-6V-12V-Turbine-Worm-Gear-Motor-8-16RPM-Long-Shaft-Slow-Reduction-Gear-Box-/311250697134?hash=item4877fcbbae

8 - 16 rpm. Should be easy to control speed with PWM. Low cost ( $2.17 delivered).

Need limit switches. Need control transistors. Would have required at least one limit/ "zero position" switch with stepper motor in any case. Can use "vane" sensor (AKA opto-interrupter) for this.