Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Re: Controlling a DC motor using PWM and a potentiometer on: February 07, 2013, 07:14:53 pm
stopping the motor isn't really a priority, the code you wrote for getpot had an error saying void was not ignored how it should be and motorForward has an error about too many arguments.  As the code stands, all i want is to make everything go in one direction.

by the way, 100 and 140 are arbitrary numbers, I modified the program when I thought i needed to turn the motor off.

@retroplayer what do you mean by void run()?
2  Using Arduino / Motors, Mechanics, and Power / Re: Controlling a DC motor using PWM and a potentiometer on: February 06, 2013, 08:07:41 pm
the purpose of this code is to generate a pwm signal and use a potentiometer that changes speed of the motor in one direction smoothly.  the reason that the value is set between 90 and 255 is because 0 and 255 was very choppy. 

what is the syntax for constraining a pwm signal reading? analogWrite(pot) I'm not sure this is correct.
Code:
int getpot()
{
  analogRead(pot) = constrain(pot, 90, 255)
}

the value string was supposed to set the motor to stop when the signal was between 100 and 140.

the code I used was modified off of an example found on the arduino playground under DC motor control, which is why there is both forward an backward motor control, although i am not sure what it's original purpose was.  The case is the same with the relay and as I am still pretty inexperienced I don't even know what it does.  the code we first tried was
Code:
int motorFoward() {
  analogWrite(motorPin, getPot());
  delayMicroseconds(35000);
  digitalWrite(motorPin, LOW);
  delayMicroseconds(35000);
  digitalWrite(relay, HIGH);
  delayMicroseconds(35000);
}

int motorBackward() {
  analogWrite(motorPin, getPot());
  delayMicroseconds(35000);
  digitalWrite(motorPin, HIGH);
  delayMicroseconds(35000);
  digitalWrite(relay, LOW);
  delayMicroseconds(35000);
}
I remember that the highs and lows were inverse of each other but as far as I could see, switching them didn't make a difference in how the motor ran.
It'd be great if you could point me to a solution. thanks.
3  Using Arduino / Motors, Mechanics, and Power / Re: Controlling a DC motor using PWM and a potentiometer on: February 02, 2013, 02:57:21 pm
I tried the code but it didn't work.
When I changed the delay back to microseconds it worked the same way it did before, (full speed forward and variable speed backward).  The code is much more simple, but there is still a problem with everything not going in the same direction.
4  Using Arduino / Motors, Mechanics, and Power / Controlling a DC motor using PWM and a potentiometer on: February 02, 2013, 01:44:01 pm
I am using a potentiometer and a PWM signal to make a variable speed DC motor. As our code works now, we have full speed forward, and variable speed backwards. The variable speed is VERY slow. We only want the motor to go forward, and a range of variable speed.

Our current code is:
Code:
int pot = 0;
int relay = 3;
int motorPin = 11; 
int val = 0;

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  pinMode(pot, INPUT);
  pinMode(relay, OUTPUT);
  pinMode(motorPin, OUTPUT);
}

int getPot() {
  int v;
  v = analogRead(pot);
  v /=   4;
  v = max(v, 90);
  v = min(v, 255);
  return v;
}

int motorFoward() {
  analogWrite(motorPin, getPot());
  delayMicroseconds(250000);
  digitalWrite(motorPin, LOW);
  delayMicroseconds(250000);
  digitalWrite(relay, HIGH);
  delayMicroseconds(250000);
}

int motorBackward() {
  analogWrite(motorPin, getPot());
  delayMicroseconds(250000);
  digitalWrite(motorPin, LOW);
  delayMicroseconds(250000);
  digitalWrite(relay, HIGH);
  delayMicroseconds(250000);
}
 int value() {
  val = analogRead(pot);
  val = map(val, 90, 255, 100, 140);
  analogWrite(0, val);
  if (val = map(val, 90, 255, 100, 140))
    {
    analogWrite(motorPin, 0);
  }
  else
  {}
 
}

void loop()                     // run over and over again
{
  value();
  motorFoward();
  motorBackward();
}

Is there anything we are doing wrong; that can be improved?

Thanks!
Pages: [1]