Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Sensors / Re: controlling DC motor with encoder on: February 05, 2011, 03:23:59 pm
Hi,

This is my code so far:
Code:
/* Using 1 potentiometer to control h-bridge
 * forward from zero to highest rpm
 * stop
 * reverse from zero to highest rpm
 * by Leo Groeneveld
 */
 
int potpin2 = 2; // analog pin used to connect the potentiometer2
int val2;        // variable to read the value2 from the analog pin2
int pwmval2;     // variable to set the value of the PWM signal
int pwmval3;     // variable to set the value of the PWM signal

void setup()  {
    pinMode(2, OUTPUT); // declare pin 2 to be an output:
    pinMode(3, OUTPUT); // declare pin 3 to be an output:
    analogWrite(2, 0);  // start with no output on PWMpin2
    analogWrite(3, 0);  // start with no output on PWMpin3
    Serial.begin(9600);
}

void loop()  {
  val2 = analogRead(potpin2);       // reads the value of potentiometer2 (value between 0 and 1023)
  if (val2 > 461 and val2 < 561) {  // dead-band
  analogWrite(2, 0);                // when in dead-band no signal to digital pin2
  analogWrite(3, 0);                // when in dead-band no signal to digital pin3
  }
 
  if (val2 >= 0 and val2 <= 461) {      // motor rotating one direction
  pwmval2 = map(val2, 0, 461, 255, 0);  // motor rotating in one direction slow to highest rpm
  analogWrite(2, pwmval2);              // writes PWM value to digital pin2
  }
 
  if (val2 >= 561 and val2 <= 1023) {      // motor rotating in other direction
  pwmval3 = map(val2, 561, 1023, 0, 255);  // motor rotating in other direction slow to highest rpm
  analogWrite(3, pwmval3);                 // writes PWM value to digital pin3
  }
Serial.println(pwmval2, DEC);
}


I can control speed too.

I have taken an old printer apart and would like to be able to steer the printing head left and right to a certain position using a linear encoder but that's also an A B type. The current motor is small and easy to experiment with.

In the future I would like to build a robot arm with a friend of mine and we would like to use a DC motor to rotate the whole arm and model servos for the other movements.

17  Using Arduino / Sensors / Re: controlling DC motor with encoder on: February 05, 2011, 02:58:56 pm
Thanks,

Is this an interrupt code? I mean will it not miss any input from the encoder when looping through the code for the pot and L298N?

EDIT: Just read it isn't interrupt based, for direction it's no problem. In the future I would like to use it to determine position, after going to a micro switch after the Arduino is started, so the code will have to be adapted.

Leo
18  Using Arduino / Sensors / controlling DC motor with encoder on: February 05, 2011, 02:18:21 pm
Hi,

I have managed to steer a 12V DC motor with the use of one pot. I can control left and right turning and stop. I have used a L298N IC, some diodes, capaciters, a pot and lots of jumper wires.

Now I would like to read out the A B encoder which is in the motor and use a LCD display to display "motor turning left", "motor turning right" and "motor stop". I could use the pot value as input for the display but I will not learn from it and if the motor would be stuck it wouldn't be right anyway.

This is the motor I'm using:
http://www.mrutty.com.au/Portescap%20Pages/Specification%20PDFs/16N%20Series%20(16mm).pdf

I have looked for it but I can't find a code I can use as example code, can anybody help me get on the way?

Thanks,

Leo
19  Forum 2005-2010 (read only) / Bugs & Suggestions / suggestion on: January 15, 2011, 12:09:34 pm
I would appreciate a home button to the Arduino home page on top of the forum.

Leo
20  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: 2nd reset button possible? on: January 16, 2011, 04:12:30 pm
Found it after reading the post mentioning it.

thanks,


21  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: 2nd reset button possible? on: January 16, 2011, 03:58:44 pm
Ok thanks, maybe that's a better idea.

Would you believe I looked at the board for reset and completely missed it???
22  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: 2nd reset button possible? on: January 16, 2011, 01:22:08 pm
Sorry for kicking an old thread but I don't understand this possibility.

Quote
Actually it can be as simple as wiring your additional reset switch between the Arduino reset and ground pin, no soldering required.

Lefty

I have a Mega1280 (clone) and am wondering where the reset pin is.
(I know where ground is smiley)
And should there be a resistor added?
I need this as an emergency stop for a tool.

Thanks,
23  Forum 2005-2010 (read only) / Frequently-Asked Questions / what switch to get that doesn't pop out on: January 15, 2011, 12:03:51 pm
Hi,

I'm getting a bit annoyed with the microswitches which were in the Arduino package I got. The things keep popping out of the breadboard.

Are there other (micro)switches I can use in a breadboard that don't pop out all the time?

Thanks,

Leo
24  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Is it possible to break a servo with pulses? on: January 08, 2011, 11:32:05 am
I think so because I just did.

I made a mistake in my code and the servo input went berserk giving even negative values.
Now everytime the servo comes to it's end and returning to neutral there is a spark like sound.

I can still use it for testing but I will not put it in a plane or any vehicle.
25  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: arduino in italiano possibile per ┬áprogrammazione on: January 06, 2011, 01:17:20 pm
Duh?
26  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: File Association?? on: January 01, 2011, 05:57:49 am
Quote
Exactly - and when I do that it acts as if I had selected cancel instead of ok, it drops back to the list of programs and does not open ardiuino-0021.

Same problem over here and 0021 is my first Arduino compiler installed.
Windows 7 Ultimate.

I'm opening sketches from the compiler now.
27  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: RC car control Help on: January 02, 2011, 06:06:57 am
I should have known.

Thanks!
28  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: RC car control Help on: January 02, 2011, 05:56:26 am
Quote
thnx for replying, but I should've mentioned that you can consider me as a biggner.

Can you provide more comments for the codes?

thnx

I would like that too.

Thanks,
29  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: PWM Generation on: December 25, 2010, 11:14:42 am
Quote
and the ESC will react the same way as the servo? where am I going to get the potentiometer value is it given on the data sheet for the ESC

I think so, I have to try. I think you have to try using the mapping command which limits to use.

You often have to calibrate the ESC so I think there are electronics inside the ESC using a kind of mapping code for the receivers signals suggesting the ESC can take a range of values.

(WARNING: I don't know if you can damage the esc or board by using the wrong limits but my guess would be not)
30  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: PWM Generation on: December 24, 2010, 10:41:33 am
If you search in the servo library (on the Arduino home page) for knob you will find the information needed to make servos move using a potentiometer.

The esc accepts PWM at 50Hz I think.
(I think PPM is often used to get the information from transmitter to receiver and the receiver makes a PWM signal for each channel, AWOL please correct me if I'm wrong)

Duration is usually from 1ms to 2ms and the sketch includes servo.h if I remember correctly so it's all done for you.

Pages: 1 [2] 3 4