Hi
I building a solar tracker for my graduation project , and my code is almost done. the code is working fine and - it give me the sun angles (azimuth and elevation) with very high accuracy. and now i'm trying to send these two angles to two servo motors.
And when i write the servo function the servo should go to the specific position.
The problems is the moment that i write the servo function and upload the code the two servos start moving in random positions and never stops. I know when something like this happen that's mean that the servos are not getting enough current BUT i'm powering them with a PC ATX power supply (From the pin that has [5V - 2A]) so it should be enough.
Even if i just write (motor.attach(8)
without even give the servo any angle ; it's start moving at random.
The weird thing is that i tried another code and the two servos worked fine , this is the code :
#include <Servo.h>
Servo motor1;
Servo motor2;
void setup(){
motor1.attach(8);
motor2.attach(9);
}
void loop(){
motor1.write(45);
motor2.write(45);
delay (10000);
motor1.write(90);
motor2.write(90);
delay (10000);
}
This project is due in 3 weeks so I need help fast !!!
Thanks in advance
Have you got a common ground connected?
Can you post the non-working code?
So you're running interrupts from a software serial instance too?
SoftwareSerial serial_connection(4, 3); //RX=pin 10, TX=pin 11
there's something happening here, what it is ain't exactly clear.
are you using an UNO, NANO, MEGA? Things get unstable when you run low on memory.
SoftwareSerial serial_connection(4, 3); //RX=pin 10, TX=pin 11
this is the old code
I've changed it to
SoftwareSerial serial_connection(10, 11); //RX=pin 10, TX=pin 11
PC ATX power supply (From the pin that has [5V - 2A]) Maybe okey.
What does the specification for the servos say? Start current, running curent, stall current?
It sounds like a software problem but it's always good to have some margins regarding the power supply. Check it up! Then You know in case You might change servos in the future.
TheMemberFormerlyKnownAsAWOL:
And...?
I mean i've already changed them before posting the code here and nothing happen
They're still causing interrupts if anything is transmitted.
Railroader:
PC ATX power supply (From the pin that has [5V - 2A])
Maybe okey.
What does the specification for the servos say? Start current, running curent, stall current?
It sounds like a software problem but it's always good to have some margins regarding the power supply. Check it up! Then You know in case You might change servos in the future.
Current: 8.8mA, 9.1mA ;
Stall current: 350 mA,450 mA;
yeah i guess it's a software problems but the code is working fine , but the moment i just write [servo.attach()]
and not writing any thing else with it - the servo goes all over the place.
Please post your actual sketch, that will successfully compile. The code posted has too many errors.
Fine. The pwr supply is good enough.
Did You tell which Arduino You are using? They are not all the same in every respect.
TheMemberFormerlyKnownAsAWOL:
So you're running interrupts from a software serial instance too?
Sorry i meant No
I don't what that even means
david_2018:
Please post your actual sketch, that will successfully compile. The code posted has too many errors.
I'm using arduino UNO
And sorry i'don't reply as fast because i get this message every time i want to reply [Unable to publish the post. Please notice you can only post once every 5 minutes and only edit posts after 30 seconds. Once you reach 100 published posts this limit will be removed.].
From the pin that has [5V - 2A]) so it should be enough.
Not necessarily. State which servos you are actually using. For two MG996R servos, you need a 5V, 5A power supply.
#include <SoftwareSerial.h>
#include <math.h>
#include <Servo.h>
I believe that SoftwareSerial.h and Servo.h conflict in their use of Timer1. Try ServoTimer2.h