Go Down

Topic: Newbie needs help :( (Read 453 times) previous topic - next topic

jagatia

Ok, so i got Arduino Uno starter kit yesterday.
I got to grips with a few example tutorials that came in the booklet.
So i thought, why not customise it?

so i tried to.
I used the code from the top of my head, comparing it to the example codes.

All it does, is when i press the button, the ServoMotor will move 180, stop and move 180 again, and repeat.

here is the code:

Code: [Select]
#include <Servo.h>
Servo myservo;
int pos = 0;
int switchPin = 8;

void setup(){
  myservo.attach(3);
  pinMode (switchPin, INPUT);
}
 
void loop(){
  if(switchPin == LOW){
  for(pos = 0; pos < 180; pos +=1)
  {myservo.write(pos);
  delay(15);
  }
  for(pos = 180; pos>=1; pos -=1)
  {
    myservo.write(pos);
    delay(15);
  }
}
}


I dont see any errors in that.

And i have wired it, so that:

Motor:
Black wire to ground - Yellow to 5v - White to Analogue 3 (because it has ' ~ ' next to it)

Switch:
In centre of the bread board (2 pins on one side, and 2 pins on the other, so none are on teh same row).
On the left side, one pin is connected to ground, and the other to digital pin 8.


Please take me easy, i am a total noob at this, i am learning new as i go along.  :smiley-red:

CrossRoads

add after this line:
  pinMode (switchPin, INPUT);
digitalWrite(switchPin, HIGH);

that will turn on the internal pullup resistor and keep the pin high until you ground it to start your action.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

jagatia

Thanks mate :D
Will try it first thing tommorow morning (2AM here)

While here, is there any cheap places to buy servo motors, Deal Extreme have one for about $3.

Is that the cheapest you can find them?

thanks once again :D

CrossRoads

Maybe a place like this?

http://www.hobby-lobby.com/servos_241_ctg.htm

You should update your profile with your geographic location.
I can only guess from the time difference that you are in the west part of Europe? So not sure the US sources I would use would be much help.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up