kwhhSt
October 24, 2022, 1:36pm
1
Hello,
I try to run 6 servos on an Arduino nano.
Every's working fine (port PD2 - PT5 and PT7) except running a servo on PD6.
Here is my code:
#include <Servo.h>
Servo Servo01, Servo02,Servo03, Servo04,Servo05, Servo06;
int ServoPin01=2 , ServoPin02=3 ,ServoPin03=4 ,ServoPin04=5 ,ServoPin05=5 ,ServoPin06=7;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
Servo01.attach(ServoPin01);
Servo02.attach(ServoPin02);
Servo03.attach(ServoPin03);
Servo04.attach(ServoPin04);
Servo05.attach(ServoPin05);
Servo05.attach(ServoPin06);
delay(6000);
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.println("Start cycle");
Servo01.write(0);
Servo02.write(0);
Servo03.write(0);
Servo04.write(0);
Servo05.write(0);
Servo06.write(0);
delay(2000);
Servo01.write(180);
Servo02.write(180);
Servo03.write(180);
Servo04.write(180);
Servo05.write(180);
Servo06.write(180);
delay(2000);
}
I have no idea what's the problem.
Must there be a special setting to run on PD6 port?
How are the servos powered ?
Hi,
Can you see something repetitive here?
int ServoPin01=2 , ServoPin02=3 ,ServoPin03=4 ,ServoPin04=5 ,ServoPin05=5 ,ServoPin06=7;
You are using pins 2, 3, 4, 5, 5, 7.
..................................................| problem?
Tom...
1 Like
kwhhSt
October 24, 2022, 1:56pm
4
Hi UKHeliBob,
thanks for your answer.
They are powered on a powersuply with 2.4A.
Maybe that is not the problem.
It's funny because I can run the servo on each port except the PD6.
So I connect only one servo on each prot seperately.
When I connect to PD6 there is nothing happens. It's the same problem on an other ARDUINO Nano too.
kwhhSt
October 24, 2022, 2:00pm
5
Hi TomGeorge,
thanks for your hint.
I corrected the code but there is still this problem.
Posting schematics might help out.
Hi,
Write some code that just turns pin 6 ON and OFF each second.
See if you can see the voltage going up and down with a DMM, or a LED and resistor.
A picture(s) of your project would help to, let us see you component layout.
Tom...
Hi,
Repetitive again.
Serial.begin(9600);
Servo01.attach(ServoPin01);
Servo02.attach(ServoPin02);
Servo03.attach(ServoPin03);
Servo04.attach(ServoPin04);
Servo05.attach(ServoPin05);
Servo05.attach(ServoPin06);
Two Servo05 to attach.
Tom..
1 Like
kwhhSt
October 24, 2022, 2:36pm
9
Hi TomGeorge,
thanks a lot for your answer.
Yes thism was my fault.
I corrected it and now it works.
Thanks to all of you for your support.
Koepel
October 24, 2022, 2:50pm
10
It will be easier with an array. It is still possible to do something with a specific servo, as in the loop(), or with a for-loop, as in setup():
#include <Servo.h>
Servo servo[6];
int servoPins[6] = {2,3,4,5,6,7};
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
for( int i=0; i<6; i++)
{
servo[i].attach(servoPins[i]);
}
delay(1000);
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.println("Start cycle");
servo[0].write(0);
servo[1].write(0);
servo[2].write(0);
servo[3].write(0);
servo[4].write(0);
servo[5].write(0);
delay(2000);
servo[0].write(180);
servo[1].write(180);
servo[2].write(180);
servo[3].write(180);
servo[4].write(180);
servo[5].write(180);
delay(2000);
}
The sketch in Wokwi simulator:
Run IoT and embedded projects in your browser: ESP32, Arduino, Pi Pico, and more. No installation required!
kwhhSt
October 24, 2022, 2:56pm
11
Hi Koepel,
thanks! you are right! But this works for a dirty sketch too.
system
Closed
April 22, 2023, 2:57pm
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.