Hi guys!, exciting winter ahead at home! - Nano dual servo code guidance needed

Hi guys, I have decided that this winter will be a creative one!.

I literally got my Nano with some extra stuff 2 days ago. My goal is that by the end of the winter to have a controllable robot that I will mount a desktop light on!

Anyway, back to reality : )

I have wired up my nano on a breadboard together with a micro servo and I was able to install the drivers, upload the "sweep" code from the library and get it to run!

The servo is mapped to pin 9 on the nano. How do I go about wiring the second? Can I just duplicate the code for servotwo and just map it to pin 8?

By default I have wired up the original servo to pins 5v GND and D9. Am I correct in thinking I can also wire the second servo in line on the 5v and GND then use D8 for the third wire to make them both behave in the same way, at the same time?

Many thanks in advance, I am not looking for someone to just give me the solution, I would much rather understand what I am doing : ) Looking forward to getting to know you all : )

well not too long later, I have found the solution : )

Running two servos doing the same thing on the Nano should be as follows?

// Double servo Sweep mod by itscoldoutside
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
  Servo myservotwo;              // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
   myservotwo.attach(8);  // attaches the servo on pin 8 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 90; pos < 180; pos += 1)  // goes from 90 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    myservotwo.write(pos); 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=90; pos-=1)     // goes from 180 degrees to 90 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    myservotwo.write(pos);
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

I changed the values from 0 to 90 because myservotwo was trying to go beyond 0 degrees. Does anyone know if that is a hardware issue?

So, thats me learned how to wire up servos and define them on board the Nano. Next step will be learning how to influence each servo position by a hardware switch? (rotate left, rotate right?)

Hi guys, well today was a long one, and its much to late to start churning over code for me this evening :fearful:

I have pretty much gone all day trying to focus on anything else in my head than this project, but one thing has bothered me all day.

Sure, I got the servos to move, but it irritates me that they are just duplicating one another and I have not been able to work out the code to get them to both follow their own separate instructions.

Can anyone please help push me in the right direction, how for example could I get the servos to sweep through their own definable radius, and how would the code differ when doing lets say both at the same time, or one after the other? - lets say that servo 1 moves from 0 to 180, and before returning to 0, servo 2 sweeps from 0 to 180 while servo1 is stationary?

Hope you all had a great Monday!

I now have both servos working via serial! (so much for sleep)

I do need hardware advice now though folks. Over 300 people have chosen to look at this thread and have either been too afraid, or maybe its just my english? :astonished: So heres your chance to get some karma!

The bluetooth modules I have been looking at vary a lot in price, so a quick question on the available hardware;

I dont need a massive range, but as it will be used indoors, but will an RN 42 suffice or is an RN 41 more favourable? Can anyone say from experience what has worked/not worked for them previously? (I plan to use it via Android) is there any benifit to using the more expensive chips from vendors like SparkFun ?