0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« on: December 16, 2010, 06:34:27 am » |
Hi, I'm relatively new to arduino and coding, I picked it up as an interest and so far I've been enjoying it even though it's been pretty basic stuff. Now I've wanted to try something more advanced/tricky. I want to use a Sharp GP2Y0A21YK IR Proximity sensor to trigger two continuous servo motors (Parallax). I've managed to get the two servo's moving in one direction, but i have no clue where to start or if im doing something wrong.
This is what I have so far: #include <Servo.h>
Servo myservo; Servo myservo2;
int pos = 0;
void setup(){ myservo.attach(12); myservo2.attach(4); }
void loop(){ for(pos = 0; pos < 180; pos+=1){ myservo.write(pos); delay(15);}
for(pos = 0; pos < 180; pos-=1){ myservo2.write(pos); delay(15);} }
If someone would be kind enough to point this clueless newbie (me) in the right direction it would be much appreciated.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #1 on: December 16, 2010, 06:44:33 am » |
You haven't declared your Sharp sensor or its interface - how do you expect it to trigger anything?
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #2 on: December 16, 2010, 07:14:44 am » |
WEll assuming the sensor is analog type you need to do something like this #define sharp 0 main() { sharp(//set as input) } loop { analog read ( sharp ) if (//value <> something ) { action }
this is the pseudo code - hope it helps 
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #3 on: December 16, 2010, 07:55:02 am » |
...but without the 'main'
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #4 on: December 16, 2010, 08:02:43 am » |
...but without the 'main' ? :-?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #5 on: December 16, 2010, 10:18:14 am » |
(the one in your example 'pseudo code')
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #6 on: December 16, 2010, 10:27:07 am » |
Sorry but i cant get you what do you exactly mean ? the pseudo code shouldnt include then main ?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #7 on: December 16, 2010, 02:27:04 pm » |
This is Arduinoland - what is 'main'?
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #8 on: December 16, 2010, 10:55:22 pm » |
Oops i forgot [edit] main = void setup ()[/edit] 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #9 on: December 17, 2010, 12:01:09 am » |
I figured that's what main was. thanks though. I tried the pseudo-code out but i couldnt get it to work, like servos move foward and everything but it wont respond to the sensor. might be a hardware issue i guess? either that or im messing up somewhere.
|
|
|
|
|
Logged
|
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #10 on: December 17, 2010, 12:09:38 am » |
tried the pseudo-code out but i couldnt get it to work well the pseudo code isnt ment to work  post your code and someone will help you out 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #11 on: December 17, 2010, 04:09:59 am » |
Oh i know that. I used it as a guideline.  here's the code. I did some changes to it because it was giving me errors. so If something seems off, its because of me. #include <Servo.h> #define sharp 0 Servo myservo; Servo myservo2; int pos = 0; void setup(){ Serial.begin(9600); myservo.attach(12); myservo2.attach(4); } void loop() { int sensorValue = analogRead (sharp); Serial.println(sensorValue);
if(sensorValue > 250); { for(pos = 0; pos < 180; pos+=1){ myservo.write(pos); delay(15);} for(pos = 0; pos < 180; pos-=1){ myservo2.write(pos); delay(15);} }
delay(15); }
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #12 on: December 17, 2010, 04:24:26 am » |
What's the problem? What does it do that is shouldn't and what doesn't it do that it should? What do you observe?
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Hyderabad , India
Offline
God Member
Karma: 5
Posts: 621
can't help not to think arduinaizing something !
|
 |
« Reply #13 on: December 17, 2010, 04:24:50 am » |
Ok what are the values you see on the serial monitor ?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #14 on: December 17, 2010, 05:27:49 am » |
so many questions @_@ ok. let me respond to Groove first. My intention for this project is to get the sensor to trigger the servos to move. the problem I'm having is that the servos rotate non stop without the trigger. so either the sensor is not working the way it should or I'm not sure what else. I know the sensor isnt dead or defective since i tried it out just to see if it was before. now to newbie. when i open up the serial monitor i get one number, literally just one since no other value prints there after. and each time i reopen the serial monitor i get a new value. basically i get a single random value each time ranging from the 100's to 3000's. not sure if I've answered the questions correctly but, oh well. I'm literally a complete newbie.  oh and thanks for taking the time to help me. ;D
|
|
|
|
|
Logged
|
|
|
|
|
|