Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Controlling a simple toy car with Arduino Mini 05 or similar. on: January 20, 2013, 03:48:14 pm
Hi, I would like to make a experiment with a toy car, the car have a 130 Mabuchi motor and are using a coil system for the steering.

I need to find a way to control the coil and how to make the power go in different directions to steer left and right and how to control the motor.

Where to start?
I am searching an example of controlling a coil with Arduino

Any help is appreciated.




2  Forum 2005-2010 (read only) / Syntax & Programs / Tank project on: March 13, 2008, 07:35:37 pm
Hi!
I am rebuilding an R/C tank and I'm working on some code for it.
You can find my notes at my website here:http:// www.mikaelmadsen.dk/tank_project

I'm trying make a program that pans a servo from 0 to 180 degrees. On the servo (tower) I have a sensor.
When the sensor gets a HIGH reading I want the servo to DELAY for 2 seconds while it does that I need a DC motor to be activated. and then the SERVO should pan again until next reading.

The program below gives my servo some strange movements. The servo I'm using is an TowerPro MG995

What am I doing wrong in this code?

Thanks in advance.


/* Tank driver
*
*/

int servoPin = 2;           // servo connected to digital pin 2
int servoAngle;            // angle of the servo roughly 0-180
int pulseWidth;           // servoPulse function variable

int targetPin = 3;      // target sensor
int val = 0;             // variable to store the value coming from the sensor

int gunnerPin = 4;   // output to gunner (motor)

//-------------------------------------------------------

void setup()
{
pinMode(servoPin, OUTPUT);      // sets pin 2 as output
pinMode(targetPin, INPUT);     // sets pin 3 as input
pinMode(gunnerPin, OUTPUT);   // sets pin 4 as output
}

//-------------------------------------------------------

// (This section controls the servo)

void servoPulse(int servoPin, int servoAngle)
{
pulseWidth = (servoAngle * 10) + 600;   // determines delay
digitalWrite(servoPin, HIGH);          // set servo high
delayMicroseconds(pulseWidth);        // microsecond pause
digitalWrite(servoPin, LOW);         // set servo low
}

void loop()
{
// servo starts at 10 deg and rotates to 170 deg
for (servoAngle=10; servoAngle<=170; servoAngle++)
{
servoPulse(servoPin, servoAngle); // send pin and angle
delay (20);                      // refresh cycle
}
// servo starts at 170 deg and rotates to 10 deg
for (servoAngle=170; servoAngle>=10; servoAngle--)
{
servoPulse(servoPin, servoAngle); // send pin and angle
delay (20);                      // refresh cycle
}

//------------------------------------------------------

// Read targetPin and starts gunnerPin if value is high


    val = digitalRead(targetPin);   // read input value and store it in val
    if (val == HIGH) {              // check if the sensor is high
    digitalWrite(gunnerPin, HIGH);    // turns gunner on
    delay (5000);
  }
}
3  Forum 2005-2010 (read only) / Interfacing / Re: motion detection on: March 07, 2008, 11:07:03 am
I have made some changes in the BrainStem code
This is how it looks so far:

LINK to the rewrite:
http://www.cuztom.dk/arduino/pyroelectric_scan_test_program_rewrite.pde

Can anyone give me some advises on what I should do next, I still get a few errors...
That I don't know how to deal with:


LINK to the original code:
http://www.cuztom.dk/arduino/pyroelectric_scan_test_program_original.pde



/* pyroelectric scan test program */

int aCore;

int aPrint;
int aServo;
int aA2D;

int PYROIN = 0
int SRVSCAN = 3

int SSTEP = 1
int SCANDELAY = 30
int DTHR = 250

/* global variables for scan statistics */
int max;
int min;
int maxp;
int minp;
int pos1;
int pos2;


/* Resets scan statistics. */

void reset_scan()
{
  max = 0;
  min = 1023;
  maxp = 0;
  minp = 0;
}


/* This routine updates the servo position,
delays for a moment, then takes an A2D
reading from the Eltec sensor and updates
the global statistics variables. */

void update_max_min(int npos)
{
  int r;
  aServo_SetAbsolute(SRVSCAN, (unsigned char)npos);
  aCore_Sleep(SCANDELAY);
  r = aA2D_ReadInt(PYROIN);
  if (r &gt; max) {
    max = r;
    maxp = npos;
  }
  if (r &lt; min) {
    min = r;
    minp = npos;
  }
}


/* This routine checks the range between the peaks
and sees if it is big enough to be a valid detection.
If the detection is valid, the function returns the
average of the peak positions. */
int check_min_max()
{
  int pos = 0;
  int diff;
  diff = max - min;
  if (diff &gt; DTHR) {
    pos = (maxp + minp) / 2;
  }
  return pos;
}


void main()
{
  int i;
  int pos1=0;
  int pos2=0;

  while (1) {
    // scan going in one direction
    reset_scan();
    for (i = 2; i &lt; 254; i = i + SSTEP){
      update_max_min(i);
    }
    pos1=check_min_max();

    // scan going in the other direction
    reset_scan();
    for (i = 254; i &gt;= 2; i = i - SSTEP) {
      update_max_min(i);
    }
    pos2=check_min_max();

    // print the position of the hot spot for each scan
    // (may vary a little bit depending on direction)
    aPrint_IntDec(pos1);
    aPrint_Char(&39;,&39;);
    aPrint_IntDec(pos2);
    aPrint_Char(&39;n&39;);
  }
}


THANKS
/Drake
4  Forum 2005-2010 (read only) / Interfacing / motion detection on: March 04, 2008, 04:12:01 pm
Hi there.

I am working on a school project and I need a program that pans a servo back and forth and takes readings from an Eltec 442-3 sensor mounted on the servo. If there is a detection I want a relay to be activated.

I have found this code for a BrainStem microprocessor, could I use this code??

LINK TO CODE: http://www.acroname.com/examples/10020/10020.html#e3

LINK TO SENSOR: http://www.acroname.com/robotics/parts/R3-PYRO1.html

I am new in this, so any help would be appreciated... Thanks

5  Forum 2005-2010 (read only) / Interfacing / Re: Human movement detection with R3-PYRO1 on: January 11, 2008, 08:39:33 am
Quote
I did something similar with Lego Mindstorms for a soccer tournament.
It followed the ball around to block it.

You actually need two sensors and the best arrangement is the 'crosseyed' arrangement.
So they look like this: / \
The top being the sensing bit.

That way you get stereoscopic vision and can easily tell what direction the person is moving.

Thanks for the help smiley
6  Forum 2005-2010 (read only) / Interfacing / Human movement detection with R3-PYRO1 on: September 28, 2007, 10:38:40 am
Hi there.
I'm building a small robot with a turning tower, I want the tower to detect human motion and follow it. (the robot stands still, but the tower turns)

I found this sensor: R3-PYRO1 - http://www.acroname.com/robotics/parts/R3-PYRO1.html
Would it be possible to connect this sensor to Arduino? And what should I consider?

Have anyone seen a similar project or something related, all help are appreciated

THANKS!
Pages: [1]