Go Down

Topic: Project (Read 604 times) previous topic - next topic

Hi

I'm working on a car project . its 40cm by 20cm and runs on three energy sources, my problem is that i want to use a uno board with ultrasonic sensors for the steering of the car. once the car reaches a wall it moves away ... so can you help me what type of uno board do i use , and what about the program ?

thanks...

codlink

You can use an Uno..

Google for the code.  I think are around 152 different websites with the code you need.
//LiNK

AWOL

A really good way of earning a fast-track forum banning is to post the same question five or six times across the forum.

DO NOT CROSS-POST, IT WASTES TIME.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

////////////////////////////////////////////////
// This demo code checks the state of two switches
// and moves the stepper motor either clockwise or anticlockwise
//
// This code may be freely used and copied.
//
// Gareth Davies - June 2012
//
////////////////////////////////////////////////


//declare variables for the motor pins
int motorPin1 = 8;   // Blue   - 28BYJ48 pin 1
int motorPin2 = 9;   // Pink   - 28BYJ48 pin 2
int motorPin3 = 10;   // Yellow - 28BYJ48 pin 3
int motorPin4 = 11;   // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

int cwpin = 2;          // input pin for clockwise switch
int acwpin = 3;         // input pin for anticlockwise switch

int motorSpeed = 1200;  //variable to set stepper speed
int count = 0;          // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(cwpin, INPUT);  // Active low switch input
  pinMode(acwpin, INPUT); // Active low switch input
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
  if (digitalRead(cwpin) == LOW)
    clockwise();
  else if (digitalRead(acwpin) == LOW)
    anticlockwise();
  /*if(count < countsperrev )
    clockwise();
  else if (count == countsperrev * 2)
    count = 0;
  else
    anticlockwise();
  count++;*/
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)
void anticlockwise()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void clockwise()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void setOutput(int out)
{
  digitalWrite(motorPin1, bitRead(lookup[out], 0));
  digitalWrite(motorPin2, bitRead(lookup[out], 1));
  digitalWrite(motorPin3, bitRead(lookup[out], 2));
  digitalWrite(motorPin4, bitRead(lookup[out], 3));
}



i have found this code for the stepper motor,, how can i change the input from two switches to two ultrasonic sensors ?

thanks in advance,

codlink

Do you have working code for the sensors?  Once you have that, you can take out the switch part and insert the sensor code.
//LiNK

Go Up