Go Down

Topic: Need some help for a science project. (Read 11484 times) previous topic - next topic

Falchion

So I tried to do sweep with my Uno, and it decided that it does not want to work anymore, so now I have to do a completely different science project.
Robots are cool.

Falchion

I also have an extra that I haven't touched at all and that isn't working either.
Robots are cool.

arduinohabib

Aw... Sorry to hear that. Don't drop Arduino now you've picked it up though...
What is man's best friend? The breadboard!

Falchion

Nevermind. It was a false alarm.  :smiley-roll:
Robots are cool.

Falchion

However, one of them did die on me. Whenever I plug the USB in, the green LED turns on and then immediately turns off. 
Robots are cool.

arduinohabib

The led on the servo, on the computer or on the Arduino? If it's on the Arduino, there's a short circuit and you must be very careful or you might destroy your Arduino.
What is man's best friend? The breadboard!


arduinohabib

The green led? YOu mean the TX and RX leds?
What is man's best friend? The breadboard!

Falchion

Yeah, that's what I'm talking about. It started working again though.
Robots are cool.

arduinohabib

The TX and RX leds only flash when your uploading a sketch.
What is man's best friend? The breadboard!

Falchion

Woops. I actually meant the ON LED.  :smiley-roll:
Robots are cool.

arduinohabib

You must be careful when that happens. It means there's a short circuit somewhere.
What is man's best friend? The breadboard!

Falchion

This is getting out of hand... I'm doing everything it says in this tutorial, (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and it still isn't working... I have to have this thing done by February 4th, and this is worth a TON of points, so if it doesn't get done, my grade will suffer...
Robots are cool.

Falchion

Wait a second... How do I add a servo? Here's the line of code.
Quote

  // attach the servos
  for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
  {
    myServos[nServo].attach(SERVO_TO_PIN(nServo));
  }

Robots are cool.

JimboZA

#89
Jan 26, 2013, 06:05 am Last Edit: Jan 26, 2013, 06:13 am by JimboZA Reason: 1
At the top of DuaneB's code it says this...

Code: [Select]
#include <Servo.h>
// Sample sketch for driving 12 Servos from an Arduino UNO, servos are attached to digital pins 2,3,4,5,6,7,8,9,10,11,12,13

#define CONNECTED_SERVOS 12


It sweeps a whole load of servos on those pins....

So to attach servos to the board, you control them by putting their yellow / orange wires into those pins.

(The #define CONNECTED_SERVOS 12 tells it there are 12 and you could reduce that number I guess to just have however servos you have)

This part:

Code: [Select]
// attach the servos
 for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
 {
   myServos[nServo].attach(SERVO_TO_PIN(nServo));
 }



... uses the value of "CONNECTED_SERVOS" which is 12 if you didn't alter it at the top as the upper limit of a counter in a loop and runs the "attach" line as many times as you have servos to as many pins as there are servos.

This is an automated way of doing what I showed you a few posts back where I had something like myservo.attach and anotherservo.attach. The myServos[nServo] in Duane's code is a way of automating say myServos5 and myServos9 or whatever where nServo is a variable instead of hardcoding the same line a stack of times each with a different number.
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

Go Up