Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Re: total lost on first project need help please on: June 24, 2012, 10:24:50 am
sorry made a mistake it keeps wanting to turn right but only turns left when right ldr covered
what i am trying for is to go straight with no ldrs covered and right if left covered and left if right covered hope that makes sense
Al
17  Using Arduino / Programming Questions / Re: total lost on first project need help please on: June 24, 2012, 10:21:02 am
thank you its getting better all the time but when right ldr is covered it turns left as i wanted it to.
but it will not turn the wheels right when cover the left ldr also the servo keeps buzzing not stoping when it reaches its position.
but there is light at the end of the tunnel now please advise
Al
18  Using Arduino / Programming Questions / Re: total lost on first project need help please on: June 24, 2012, 09:44:05 am
i am confused the first bit suggested i have changed so it now reads if (Right == Left) that has made it a bit better but now servo just keeps trying to go left.
as to the "  if (pos < 100) pos++;  " bit i am not sure about it at all as i have put several sketches together to get this far so any thing any one can suggest would be of great help.
Al
19  Using Arduino / Programming Questions / total lost on first project need help please on: June 24, 2012, 08:02:33 am
hi i have asked a couple of times fro help but just getting more confused. i will explain in the hope some one can help.
i have an old r/c car the motor is connected to motor 1 on an adfruit motor shield
the steering is a servo connected to  servo2 on the motor shield
connected to analog input 0 is the left ldr and the right ldr is connected to analog input 1
all the bits work individually i have used a sketch that showed me the ldrs go from 200 when blocked to around 800 in light.
i just can not get it all to work together i have tried lots of ideas from the net but i get all sorts of problems.
like servo keeps pulsing left or right or ldrs get ignored.
the servo needs to move between 70 and 120 degrees to steer OK. what i am hoping to do is the car will go forward until the light on one side is brighter the car will then turn towards the light.please remember this is my first project and i am very confused.so please keep answers very simple.the latest code i am using just bounces the servos left to right all the time and takes no notice of sensors. 
please please can some one help me here is the code i am using now i dont know how to put it in a window so just cut and pasted it here

#include <servo.h>
 
// create servo object to control a servo
// a maximum of eight servo objects can be created

#include <AFMotor.h>
#include <Servo.h>
AF_DCMotor motor(1);

Servo myservo; 



int pos = 0;    // variable to store the servo position
int inputPhotoLeft = 1; // Easier to read, instead of just 1 or 0.
    int inputPhotoRight = 0;

    int Left = 0; // Store readings from the photoresistors.
    int Right = 0; // Store readings from the photoresistors.


#define CENTER 95 // servo at center
#define LEFT 70 // servo turn left
#define RIGHT 120 // servo turn right
 
void setup()
{
  myservo.attach(9);
 
 
 
  myservo.write(CENTER);
 
 
}
 
 
void loop()
{
 // Reads the values from the photoresistors to the Left and Right variables.
    Left = analogRead(inputPhotoLeft);
    Right = analogRead(inputPhotoRight);

    // Checks if right is greater than left, if so move to right.
    if (Left > (Right +20))
    // +20 is the deadzone, so it wont jiggle back and forth.
    {
    if (pos < 100)
    pos++;
    myservo.write(LEFT);
    }

    // Checks if left is greater than right, if so move to left.
    if (Right > (Left +20))
    // +20 is the deadzone, so it wont jiggle back and forth.
    {
    if (pos > 80)
    pos -= 1;
    myservo.write(RIGHT);
    }

    // Checks if left and right the same go straight.
    if (Right = (Left))
   
    {
   
    pos -= 1;
    myservo.write(CENTER);
    // Added some delay, increase or decrease if you want less or more speed.
    delay(10);
 



  unsigned char pos;
  char i;


  {
    myservo.write(pos);             // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
thank you in advance
Al   
20  Using Arduino / Programming Questions / Re: slowly going mad need helpon first project on: June 23, 2012, 10:57:42 am
Yes the servo works ok got it to sweep left to right ok just wher I run the program above it keeps jumping left whichever ldr is covered
Tried a secktch that wrote to the serial Moniter and both ldrs work great and read low when covered and high when light is on them
21  Using Arduino / Programming Questions / Re: slowly going mad need helpon first project on: June 23, 2012, 10:34:29 am
the ldr is a light dependent resistor
22  Using Arduino / Programming Questions / Re: slowly going mad need helpon first project on: June 23, 2012, 10:33:22 am
the left and right ldrs are connected to separate analog inputs 0,1 i have monitored them with the serial monitor and both working ok
23  Using Arduino / Programming Questions / Re: slowly going mad need helpon first project on: June 23, 2012, 10:31:04 am
forgot not sure if i posted code right so will paste it here as well
#include <Servo.h>
     #include <AFMotor.h>
    Servo myservo;

    int pos = 0;  // Variable to store the servo position.
    int inputPhotoLeft = 1; // Easier to read, instead of just 1 or 0.
    int inputPhotoRight = 0;

    int Left = 0; // Store readings from the photoresistors.
    int Right = 0; // Store readings from the photoresistors.

    void setup()
    {
    myservo.attach(9); // Attach servo to pin 9.
    }

    void loop()
    {
    // Reads the values from the photoresistors to the Left and Right variables.
    Left = analogRead(inputPhotoLeft);
    Right = analogRead(inputPhotoRight);

    // Checks if right is greater than left, if so move to right.
    if (Left > (Right +20))
    // +20 is the deadzone, so it wont jiggle back and forth.
    {
    if (pos < 179)
    pos++;
    myservo.write(pos);
    }

    // Checks if left is greater than right, if so move to left.
    if (Right > (Left +20))
    // +20 is the deadzone, so it wont jiggle back and forth.
    {
    if (pos > 1)
    pos -= 1;
    myservo.write(pos);
    }

    // Added some delay, increase or decrease if you want less or more speed.
    delay(10);
    }
24  Using Arduino / Programming Questions / Re: slowly going mad need helpon first project on: June 23, 2012, 10:29:18 am
ok sorry just been at it all day and getting nowhere i will post the best code i have so far haven got to the drive motor part yet still trying to get it to turn left and right.
i bet it a simple mistake but i have looked and looked and can not find it.
hope i get it sorted soon then i can work things out myself
25  Using Arduino / Programming Questions / slowly going mad need helpon first project on: June 23, 2012, 10:20:57 am
hi i am going around and around in circles and not getting very far
this is my first project i will outline what i am trying to do
i have an old r/c car the motor is connected to motor 1 on an adfruit motor shield
the steering is a servo connected to  servo2 on the motor shield
connected to analog input 0 is the left ldr and the right is connected to analog input 1
all the bits work individually i have used a sketch that showed me the ldrs go from 200 when blocked to around 800 in light.
i just can not get it all to work together i have tried lots of ideas from the net but i get all sorts of problems.
like servo keeps pulsing left or right or ldrs get ignored.
the servo needs to move between 70 and 120 degrees to steer OK
please please can some one help me
Al 
26  Using Arduino / Project Guidance / my first project problems on: June 22, 2012, 06:58:06 am
hi just got my first arduino uno board and ad-fruit motor shield but still trying to get my head around the programing
i have built the following base to experiment with but finding it hard to get started. i have an old r/c car as base with the motor connected to motor 1 on the motor shield. the steering is by a servo connected to  header 1 on the same board. i have 2 ldrs connected to input 0 and 1 respectively.
by trying various sketches i have found i know the motor runs, the servo steers and each light sensor works OK.
but can not get them all to work together. what i am trying to do is car will steer towards the strongest light but if unable to go forwards will reverse and try another way.
this project is supposed to help keep me busy as i have very bad depression so if someone can help me with my first project it will give me confidence to continue.
thank you
AL
Pages: 1 [2]