Pages: [1]   Go Down
Author Topic: Newbie needs help :(  (Read 432 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks mate smiley-grin
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 smiley-grin
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Pages: [1]   Go Up
Jump to: