Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: Using IR Proximity Sensor to control motors on: May 02, 2011, 09:24:10 am
Thanks AWOL but by removing the semicolons it doesn't want to compile, sorry, what do you think is wrong?
2  Using Arduino / Sensors / Re: Using IR Proximity Sensor to control motors on: May 02, 2011, 07:39:57 am
Thanks wildbill but the change didn't work. In the place of the motors I plased an LED to check if they would work, and they did work but the light emitted by them was really dim.
3  Using Arduino / Sensors / Using IR Proximity Sensor to control motors on: May 02, 2011, 05:59:06 am
Hi all, I'm struggling to use the output of my IR sensors(2 sensors) to control 2 motors.
I am using 2 Sharp IR GP2Y0D340K Distance sensor , a Ardumoto to power the motors and a Arduino Uno. When I connect power to the Arduino the motors turn as expected , but only keep turning in one direction. I want the motors to change direction when the IR sensor detects an object, but they do not respond to the sensors. In my code I have assigned the sensors readings( 1 or 0 ) to be sent to the serial monitor just so that I can see if they are working, and they are. Can someone please take a look at my code and why the motors do not respond. Thanks in advance.


Code:
int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3
int pwm_b = 11;  //PWM control for motor outputs 3 and 4 is on digital pin 11
int dir_a = 12;  //dir control for motor outputs 1 and 2 is on digital pin 12
int dir_b = 13;  //dir control for motor outputs 3 and 4 is on digital pin 13


void setup()
{
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);
 
  Serial.begin(9600);
   
   analogWrite(pwm_b, 220);
   analogWrite(pwm_a, 220);       
}

void loop()
{
   int sensorValue = digitalRead(A0);
   int sensorValue1 = digitalRead(A1);
   Serial.println(sensorValue1, DEC);//Just to see if the sensors are working, and they are
   
  if (sensorValue = 0) {            //Sensor 1 is asigned to only control the left-side motor
   void LFORWARD();
 }
    else{
   void LREVERSE();
    }   

  if(sensorValue1 = 0){           //Sensor 2 is asigned to only control the right-side motor
   void RFORWARD();
   }
    else{
   void RREVERSE();
   }
void LFORWARD();{
  digitalWrite(dir_a,HIGH);//Control for the left-side motor
}
void RFORWARD();{
  digitalWrite(dir_b,HIGH);//Control for the right-side motor
}
void LREVERSE();{
   digitalWrite(dir_a,LOW);//Control for the left-side motor
}
void RREVERSE();{
  digitalWrite(dir_b,LOW);//Control for the right-side motor
}
}
 
 
4  Using Arduino / Sensors / Re: Struggling to receive the correct data from a IR Sensor. Help please... on: March 28, 2011, 09:08:40 am
Tnx John and AWOL , if got every working and functioning correctly  smiley. I only want to know wat is the siggnificence of connecting pin6 to ground and how do I reduce the distance that the sensor can receive? 
5  Using Arduino / Sensors / Re: Struggling to receive the correct data from a IR Sensor. Help please... on: March 28, 2011, 07:22:56 am
Tnx AWOL , but if also tried that, I'm am now getting readings of 1023 dropping to about 900 if a object is in front of the sensor, and a value from 0 to about 100 when there is no object. Any idea why its so inconsistnet? I would also like to know how to map these valuese to 0 and 1, is'nt this a proximity sensor which only gives a value of 1 and 0? Tnx very much
6  Using Arduino / Sensors / Struggling to receive the correct data from a IR Sensor. Help please... on: March 28, 2011, 06:23:19 am
Hi all, I'm struggling to " read " my Sharp IR GP2Y0D340K Sensor.

Firstly I want to know how to connect the sensor to the arduino. If have looked and followed the diagram of the sensor in the following link : http://sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0d340k_e.pdf (note it's a pdf file). I have wired the sensor to the arduino by connecting the pin 1 of the sensor to the 3.3 V on the arduino, pin 2,4 and 5 of the sensor to the ground of the arduino with the neccesary componnets (capacitator and resistor), and pin 3 to the analog input pin of the arduino. Is this correct?

I then used  the simple  AnalogReadSerial aswell as a modified AnalogInOutSerial example in the library of the arduino. Again, is this correct? When I open the serial monitor I only receive a constant value which doesn't change if the sensors orientation changes or the distence changes. I know this a proximity sensor which only gives output values, I think of 1 and 0, but the sensor gives me readings from 0 to 1023, but these values differ on the start of the serial monitor , not through out the  "running" of the code.

Can someone please help me with : connecting the sensor to the arduino correctly if it isn't and help me with reading the sensor correctly so that it only gives a value of 1 or 0.
Any help will be grately appreciated, or even just a link to website that can help me. Tnx all.
7  Forum 2005-2010 (read only) / Troubleshooting / Re: Arduino if else statement . . . . on: December 30, 2010, 03:12:01 am
Thank  you PaulS for the code , it's appreciated very much and it worked. The only question that I want to ask is if I would like to compare ex sensorVal1 against a preset value and not the other sensor, how will I write that value,where and should I map that value ?

I'm asking this because I'll be conrolling motor's with the value and if the value from the the sensor is for ex. < than the preset value to put the motor in reverse and so on.

Thanx all, as I said, just starting out with the programming and sorry for all the questions . . .
8  Forum 2005-2010 (read only) / Troubleshooting / Arduino if else statement . . . . on: December 29, 2010, 04:04:17 pm
Hi all, I'm new to the whole Arduino/Programming thing as well as electronics. I've played around with the Arduino succesfully and thought I'd start building(trying) to build a robot, a simple robot , one that detects objects via IR and avoiding them.

I did/tryed this by using an Arduino Uno, Ardumoto, tank track sistem and 2 IR sensors. The plan was to mount the to sensors on the front of the tank sistem, each looking "outwarts", I used the 2 sensors this way because I don't have a servo to sweep 1 sensor. I've succesfully written code to operate the motor aswell as the IR sensor.

I need help with a basic " if else " statement, I can't seem to get the if else statement working( the statement should read the value from the IR sensors and then be used to control the motors...) So I tried just reading the IR sensors and if it reeches a sertain value, it has to turn a LED on(HIGH), just to see if I could that. But I failed.

What I'm asking is that if anybody can help me with this basic if else statement, even some ex. code would realy be appreciated.

Any comments wil be greatly appreciated.
Pages: [1]