Thank you for the video. For the 5V 10A power supply, what battery are you using? Normally the amperage rating is much lower than the voltage rating, so I'm curious what source you used here.
You can use a 12v to 5v converter that is rated for 10amp if you need a portable supply. This one has good reviews on Amazon. www.amazon.com/12v-5v-Converter-Regulator-Transformer/dp/B08PP6LMM1?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A3M3YMPQTI06AD For most projects with high current requirements I will use a larger 24v/20a power supply and dial in the voltage I need.
can you adjust the start stop position of each servo and initiate each servo independently. I want to use servo motors to operate point motors and level crossing gates on a model railway. Is there a better way of achieving this
Yes, you can operate each servo independently and you can adjust the start and stop points of each servo individually by controlling the pulse width signal. The PCA9685 PWM driver is a good choice for something like this.
@@BMonsterLaboratory On the level crossing there would be 4 servo motors which I would want to operate together. How would I do this by switch. If I use a on-off-on switch. I would want to go one way then after operate the switch again to close the gates. How would I wire this up and the others I would want to operate again by switch but individually. Also do I only need to use the computer to programme the motors or does it need to stay connected. As you can tell I have never used these before. I would probably use about 12 motors
@@PeterEvans-dw2ol I think limit switches would be your best option. If all four gates operate together (they open and close simultaneously), you would only need two limit switches. The limit switches would be positioned so that when any one of the gates reaches the fully open or fully closed position, it triggers the switch and stops all servos. #include #include Adafruit_PWMServoDriver pwm; #define NUM_SERVOS 4 #define SERVO_MIN 100 #define SERVO_MAX 600 // define servo pins int servoPins[NUM_SERVOS] = {0, 1, 2, 3}; // define end switch pins const int endSwitchOpen = 9; // end switch for fully open position const int endSwitchClose = 10; // end switch for fully closed position void setup() { Serial.begin(9600); Serial.println("Servo Control with End Switches"); pwm.begin(); pwm.setPWMFreq(50); // set the PWM frequency // Initialize servos to their minimum position (gates closed) for (int i = 0; i < NUM_SERVOS; i++) { pwm.setPWM(servoPins[i], 0, SERVO_MIN); } // set the end switch pins as inputs pinMode(endSwitchOpen, INPUT_PULLUP); pinMode(endSwitchClose, INPUT_PULLUP); } void loop() { // check the state of the end switches bool isOpen = digitalRead(endSwitchOpen) == LOW; // end switch for fully open bool isClosed = digitalRead(endSwitchClose) == LOW; // end switch for fully closed // If not fully open or closed, move the servos if (!isOpen) { openGates(); } if (!isClosed) { closeGates(); } } // function to open gates (move all servos to max position) void openGates() { for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) { for (int i = 0; i < NUM_SERVOS; i++) { if (digitalRead(endSwitchClose) == LOW) return; // stop if end switch is triggered pwm.setPWM(servoPins[i], 0, pos); } delay(15); } }
hey there! The PCA9685 PWM driver operates at a voltage range between 2.3V and 5.5V for its VCC pin. The v+ terminal is 6v max However, it can still be used to control higher voltage servos by using an external power supply for the servos. Since the servo motor draws current to move, it's best to isolate the power for the servos from the power for the PCA9685 controller board.
Yes, you can control them individually. You’ll need to set up each channel with specific PWM values corresponding to the servo’s position. And yes, you can control individual servos connected to the PCA9685 through a Bluetooth module like the HC-05. I like this idea! Thanks for asking
sorry about that apprently you have to divide your pw by your boards bit rate so mine being a 12 bit had to be divided by 4.07 to get the correct values
hey there! great question. Do you have a link for this? I was under the impression that the PCA9685 takes care of generating the PWM signals for all the channels based on the frequency you've set and the specified pulse widths. It does this simultaneously, so you can control multiple servos independently without needing to manually calculate or divide pulse widths.
hey there! Here's what I'm thinking. Is this what you want to do? The code controls a servo motor based on whether a laser is hitting a photoresistor. When a laser is pointed at the photoresistor, the photoresistor value exceeds a specific threshold. As a result, the servo motor moves to a new position. When the laser is not pointed at the LDR, the servo motor returns to its initial position. The PCA9685 servo driver is used to control the servo, which allows for multiple servos to be connected if needed. If i'm wrong, let me know. Sounds interesting!
@BMonsterLaboratory the problem I'm running into is the threshold. Idk how m3asure it or Calibrate it or whatever if so new to this but I ha e developed a HUGE passion in the recent weeks and I'm on a mission lol no retreat no surrender, learn this thing Inside and out and create some wild ish
@@danielrizzi1153 I have a XINGYHENG 175pcs 7Values 5mm Photoresistor (LDR) kit that I bought on Amazon about 5yrs ago. There are multiple values i this LDR kit. If you want to set up multiple targets, just pick one value and set the threshold values in your code. For instance, in this kit I would use only the GL5506 LDR for consistent calibration and uniform behavior. This LDR has a dark resistance between 2-6k ohm and a light resistance of 0.15M ohm. For a good threshold value, the resistance will be relatively high wihtout a laser 500-800 depending on the voltage and will drop significantly with a laser (200-400 range). The exact analog values will depend on the strength of your laser - you can see the values in real-time by watching the serial monitor. Use a voltage divider circuit toconnect the LDR to the analog pin on the Arduino. One end goes to 5v while the other end is connected to a 10k ohm resistor (to ground) - and the point between the resistor and LDR is connected to the analog input. You can search google images for LDR voltage divider circuit. For you code, you may need to add something like this if you're using, for example, 3 LDR's. The threshold in this example is set at 500. I hope this was helpful! #include // Create the PCA9685 PWM driver object Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Photoresistor pins (using GL5506) const int LDR_PIN1 = A0; // GL5506-1 const int LDR_PIN2 = A1; // GL5506-2 const int LDR_PIN3 = A2; // GL5506-3 // Single threshold value for all GL5506 sensors int threshold = 500; void setup() { Serial.begin(9600); pwm.begin(); pwm.setPWMFreq(60); // Set PWM frequency to 60 Hz for servos // Set initial servo positions pwm.setPWM(0, 0, 300); // Servo 1 on channel 0 pwm.setPWM(1, 0, 300); // Servo 2 on channel 1 pwm.setPWM(2, 0, 300); // Servo 3 on channel 2 } void loop() { // Read values from GL5506 photoresistors int ldrValue1 = analogRead(LDR_PIN1); int ldrValue2 = analogRead(LDR_PIN2); int ldrValue3 = analogRead(LDR_PIN3); // Print the values for debugging Serial.print("LDR1: "); Serial.print(ldrValue1); Serial.print(" | LDR2: "); Serial.print(ldrValue2); Serial.print(" | LDR3: "); Serial.println(ldrValue3); // Control Servo 1 based on GL5506-1 if (ldrValue1 > threshold) { pwm.setPWM(0, 0, 450); // Move servo 1 to a new position when laser hits } else { pwm.setPWM(0, 0, 300); // Return servo 1 to the original position } // Control Servo 2 based on GL5506-2 if (ldrValue2 > threshold) { pwm.setPWM(1, 0, 450); // Move servo 2 to a new position when laser hits } else { pwm.setPWM(1, 0, 300); // Return servo 2 to the original position } // Control Servo 3 based on GL5506-3 if (ldrValue3 > threshold) { pwm.setPWM(2, 0, 450); // Move servo 3 to a new position when laser hits } else { pwm.setPWM(2, 0, 300); // Return servo 3 to the original position } delay(100); }
Hey there! Will const int = "name" = (number here) work instead of having an array list? or do i have to call each one in an array, and do i have to call the number of servos (line 6). Id really appreciate it! you inspire a lot!
Hi, thanks! You don't have to use arrays. You can define individual constants like this: const int SERVO_1 = 0; const int SERVO_2 = 1; const int SERVO_3 = 2; ...etc. But you'll need to reference each servo individually in your code. Doing it this way makes iterating over multiple servos or performing actions on all servos cumbersome. Arrays make your code look cleaner and easier to manage. NUM_SERVOS defines the number of servos you are going to control. It helps you easily adjust the number of servos without needing to change the code in multiple places. good questions! 👍
Hi I have hooked up my servos to my board. They say they have a pw of 500 to 2500 yet they seem to only move a few degrees when I plug in my values to replace the ones u entered . Any thoughts on this would be appreciated.
sure! You're loop would look something like this: //servo1 moves clockwise and servo2 counterclockwise for (int pos = 0; pos = 0; pos -= 1) { servo1.write(pos); servo2.write(180 - pos); delay(15); } You may need to adjust it according to your project, but that's the idea. 👍👍
hi there, thank you so much for your video, really helpful. quick question in term of power supply, im using 6 MG996R at the moment at 5V 15A seems to be too much for them, do you suggest particular lower A for the power supply?
Hello! If the 5v 15A supply is working for you, stick with it. You want to be sure to have plenty of overhead current to handle the servos when they are all drawing the most current at 5v and the motors will only draw the current they need. Check data sheets and test to ensure there's no over heating or erratic behavior of the motors based on your project. But, I would keep the 5v 15A supply for 6 servos. I hope this helps!
Hello sir i need help with my thesis project im already done with the wirings and programming its all good but why is that my servo motors are not functioning?? Im using PCA9685 with 3 MG996R and 3 MG995. With a 5v 2amps power source
Those 2 servo motors are 6v servos that can draw up to, and maybe a little over, 1amp of current each depending on peak load and speed. I am assuming your issues is the lack of current to power these motors. For 3 of each, and a total of 6 servos, I would use 5v-6v at 8-10amps. The motors will only draw the current they need so having a little overhead would be good. You may find a stand alone variable power supply or a step down converter to be useful. Perhaps you could test the motors and board by removing all but 1 servo and testing it at each servo position.
Hey there! Sorry for late reply, been traveling the past few days. I have a 5v10a supply connected. If you need more current for a lot of servos, try using an external power source and just connect ground and servo signal wires to the driver board for pwm control. I would not put more than 10amp supply on v+ to power the board. I believe this is the safest approach. I hope it helps
hey there! You can manually turn the potentiometers to control the movement of the servos when using the PCA9685 PWM Driver or you can connect the potentiometers to the Arduino directly and control them that way. Just curious, what kind of issues are you having with the driver?
Hello my friend. Excellent video. I compiled the video code on Arduino Uno and it worked perfectly. I wanted to ask you how do I increase the servo speed? I wish it moved faster.
Hi.. thank you! 👍 I don't have access to the code at the moment but it's posted on face book. try decreasing the delay. Should look something like this... MyServo.write(0); delay(1000); //decrease this number to increase speed
Hello, could i ask you i have 7,4V 2S lipo bat. and I use it to power the servos I have 12 servo motors and each one takes about 3A under load. The question is… is it possible to use this driver pca9685?
Hey there! This board cannot directly drive a 7.4v servo. The PCA9685 operates with a supply voltage range of 2.3 V to 5.5 V. However, you can connect your servos to a 7.4v power source and use the PCA9685 board to send control signals to the servo via its PWM control input (assuming your servo has a 5v signal pin). You may also want to check out high voltage servo drivers. This one is a stand alone servo controller - www.adafruit.com/product/5437?gad_source=1&gclid=CjwKCAiAt5euBhB9EiwAdkXWO9AbfugiJgUH6CyWzK35_XNwNcthAU-gfVnBhwZ7Tj0AlACuxN4CvxoCmvoQAvD_BwE -It supports high voltage servos, up to 11V. I have never used it but i'm sure there are some good demo videos out there. You're going to need a lot of current. Consider integrating fuses into your design to protect against short circuits or overcurrent. A fuse rated slightly above your expected maximum current will help prevent damage to your components. hope I answered your question. good luck to you!
@@BMonsterLaboratory I tried connecting the servos and it worked fine even at 7.4V. I'm just worried that the pca9685 will be ruined for long term use.
Good job! Thanks for explain very well about powering only the chip. Where can I find this code to test my board? I couldn't find this one in your Facebook page... There's tons of projects there!
I’m getting really annoyed with my boards. I have five micro servos (specifically MG90S) connected to this and my Arduino. I have a portable battery to power the Arduino and a Tenergy 6V NiMh battery (for RC cars) powering the servos (connected to the terminal block). It was working fine for a few days, then magically didn’t. I thought it was the battery so I bought a Tenergy balance charger and charged the battery. Multimeter checked the battery and it seemed fine. Definitely frustrating. I’m not *new* new but I’m still fairly inexperienced. Arduino forums weren’t much of a help, since the only questions that needed answering were in regards to bad wiring diagrams lol Any suggestions would be much appreciated. 🙏
hey there! if it was working and now it doesn't, i'm wondering about the battery. It sounds like the wiring is fine but I'm happy to help where I can. what is the mAh of you 6v battery? If your 6V battery capacity is 1600mAh, its continuous discharge rate might not be high enough to handle 4.5A and could overheat or be damaged but it also depends on usage duration and servo load. It's recommended to choose a battery with a higher capacity than the minimum required. Consider a 2000mAh or 2500mAh battery to provide a safety margin and potentially longer runtime.... just my initial thoughts.
@@BMonsterLaboratory You’re amazing. I’ll send you what I have over FB Messenger. I’ll try to show as much as possible as well as what I’ve already tried. I appreciate you and your time so much. I’m teaching a class of kids next weekend on how I built my last one (community leader asked if I’d help and I love to help kids so I said yes lol) and introduce them to the basics of Arduino programming. But the last one I made I had the servos directly wired to the Arduino. This time I wanted to use a servo driver and it’s been a pain in my rear!
I normally post them to Facebook but sometimes that can become confusing when it requires multiple posts for one sketch. I need a place to contain all project code that people can freely access.....anyway, Here's the code I posted for this video. 👍 #include #include Adafruit_PWMServoDriver pwm; #define NUM_SERVOS 5 #define SERVO_MIN 100 #define SERVO_MAX 600 #define SERVO_DELAY 1000 // Delay in milliseconds int servoPins[NUM_SERVOS] = {0, 1, 2, 3, 4}; void setup() { Serial.begin(9600); Serial.println("Alternate Servo Test"); pwm.begin(); pwm.setPWMFreq(50); // Set the PWM frequency for the PCA9685 // Initialize all servos to their minimum positions during setup for (int i = 0; i < NUM_SERVOS; i++) { pwm.setPWM(servoPins[i], 0, SERVO_MIN); } } void loop() { // Rotate all servos to one extreme position for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) { for (int i = 0; i < NUM_SERVOS; i++) { pwm.setPWM(servoPins[i], 0, pos); } delay(15); } delay(SERVO_DELAY); }
hi there, impressive video how to drive the servos with the pca9685. I only have one question regarding the baud rate. As I know the Mega requires a baud rate of 115200 to communicate while the 9600 is for the Uno. Did this have an impact on the control or is this not important with the PCA 9685? Thank you and keep making such kind of videos for us to help with problems.
Hey there! Thank you for the kind comment. It's great to get feedback on videos to improve future content. The baud rate settings in this video are primarily for serial communication between the Arduino board and my computer. In this instance, Arduino uses serial communication to send and receive data between the board and the computer. The baud rate specifies the data transfer speed in bits per second and the baud rate uploaded to the Arduino needs to match the baud rate set in your serial monitor. The PCA9685 PWM driver communicates with the Arduino via the I2C protocol, which is not affected by the serial baud rate settings. So no, baud rate doe not impact control of the servos. Thank you for asking and I hope you enjoy building your Arduino project! 👍💪
@@BMonsterLaboratory Thank you for your explanation. Now I understand the difference using the baud rate for communication between units in the Arduino world.
hey there! It depends on the servos you're using. The MG995 servos can have current at maximum load: 1200mA according to components101.com/motors/mg995-servo-motor You want enough current to accommodate all 15 servos. Current load for 15 servos could be around 18A (15 * 1200mA = 18000mA = 18A) It's advisable to choose a battery with a higher current rating than you need to ensure reliable and stable performance, taking into account factors like battery efficiency, voltage drops, and safety margins. Be sure to do our research and make sure you look over data sheets for the servos and other components you're going to use. I, personally, haven't used more than 6 servos on this driver. If you're using 15 MG995, I'd be interested in what you think of the performance. 👍
hi, yes... you should be able to. sorry for the late response. If you're using the code I posted on Facebook, you would have something similar to this: for (int pos = SERVO_MIN; pos
You can user 8 servos on this. are they they same model? MG995? I see recommendations not to use more than 10amps with this board. If your motors pull more than 10A, use an external power supply for the motors and ensure common ground with the PCA9685. This will help protect your components, and the board will control the motors properly using the data pins without overloading its power capabilities. 👍💪
@@BMonsterLaboratory ty for your answer. I want to control 8 linear servos with 3.3v.... and I want something of 8 beacuse I want to reduce the space inside the robot. (sorry my english, is not so good)
Hello. Even though I have completed the connections and library installation you explained in the video, exit status 1 Compilation error for Arduino Uno board. I'm getting the error. But when I load another code, I do not encounter this error. Can you help me, thank you in advance.
so, it's probably a syntax error or board selection error... Did you copy and paste code from Facebook post? If not, try this. #include #include Adafruit_PWMServoDriver pwm; #define NUM_SERVOS 5 #define SERVO_MIN 100 #define SERVO_MAX 600 #define SERVO_DELAY 1000 // Delay in milliseconds int servoPins[NUM_SERVOS] = {0, 1, 2, 3, 4}; void setup() { Serial.begin(9600); Serial.println("Alternate Servo Test"); pwm.begin(); pwm.setPWMFreq(50); // Set the PWM frequency for the PCA9685 // Initialize all servos to their minimum positions during setup for (int i = 0; i < NUM_SERVOS; i++) { pwm.setPWM(servoPins[i], 0, SERVO_MIN); } } void loop() { // Rotate all servos to one extreme position for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) { for (int i = 0; i < NUM_SERVOS; i++) { pwm.setPWM(servoPins[i], 0, pos); } delay(15); } delay(SERVO_DELAY); }
@@ardaa2607 great! thank you. I hope you find more videos that are helpful. If you have any questions just leave a message here, on facebook, or send an email. 👍
hey there! you could set the PWM to a certain duty cycle. For example, setting it to 50% duty cycle means the channel will be on half the time and off the other half. To turn a channel off, set its PWM value to 0, resulting in no signal being outputted. Here's what that might look like: #include #include // Create PCA9685 object Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); void setup() { Serial.begin(9600); pwm.begin(); pwm.setPWMFreq(1000); // Set the frequency to 1000 Hz } void loop() { // Turn channel 0 fully on (100% duty cycle) pwm.setPWM(0, 4096, 0); delay(1000); //on for 1 second // Turn channel 0 off pwm.setPWM(0, 0, 4096); delay(1000); //off for 1 second }
Hey there! I am happy to assistance however I can. Not sure about guiding through every step. Tell me the goal of your project, components you are using, and your experience level. I am currently traveling but will be available next week. 👍
@@kaushlendrapandey5404 Facebook mssg has worked well for me facebook.com/BMonster-Laboratory-101410418059806/ I usually check it at night. Feel free to send a message if you have a question.
Thank you for the video.
For the 5V 10A power supply, what battery are you using?
Normally the amperage rating is much lower than the voltage rating, so I'm curious what source you used here.
You can use a 12v to 5v converter that is rated for 10amp if you need a portable supply. This one has good reviews on Amazon. www.amazon.com/12v-5v-Converter-Regulator-Transformer/dp/B08PP6LMM1?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A3M3YMPQTI06AD For most projects with high current requirements I will use a larger 24v/20a power supply and dial in the voltage I need.
can you adjust the start stop position of each servo and initiate each servo independently. I want to use servo motors to operate point motors and level crossing gates on a model railway. Is there a better way of achieving this
Yes, you can operate each servo independently and you can adjust the start and stop points of each servo individually by controlling the pulse width signal. The PCA9685 PWM driver is a good choice for something like this.
@@BMonsterLaboratory Thank You.
Could I operate the points and gates by switch. How would I do this.
Just curious, how many servos are you operating? Are they the micro 9g servos?
@@BMonsterLaboratory On the level crossing there would be 4 servo motors which I would want to operate together. How would I do this by switch. If I use a on-off-on switch. I would want to go one way then after operate the switch again to close the gates. How would I wire this up and the others I would want to operate again by switch but individually. Also do I only need to use the computer to programme the motors or does it need to stay connected. As you can tell I have never used these before. I would probably use about 12 motors
@@PeterEvans-dw2ol I think limit switches would be your best option. If all four gates operate together (they open and close simultaneously), you would only need two limit switches. The limit switches would be positioned so that when any one of the gates reaches the fully open or fully closed position, it triggers the switch and stops all servos.
#include
#include
Adafruit_PWMServoDriver pwm;
#define NUM_SERVOS 4
#define SERVO_MIN 100
#define SERVO_MAX 600
// define servo pins
int servoPins[NUM_SERVOS] = {0, 1, 2, 3};
// define end switch pins
const int endSwitchOpen = 9; // end switch for fully open position
const int endSwitchClose = 10; // end switch for fully closed position
void setup() {
Serial.begin(9600);
Serial.println("Servo Control with End Switches");
pwm.begin();
pwm.setPWMFreq(50); // set the PWM frequency
// Initialize servos to their minimum position (gates closed)
for (int i = 0; i < NUM_SERVOS; i++) {
pwm.setPWM(servoPins[i], 0, SERVO_MIN);
}
// set the end switch pins as inputs
pinMode(endSwitchOpen, INPUT_PULLUP);
pinMode(endSwitchClose, INPUT_PULLUP);
}
void loop() {
// check the state of the end switches
bool isOpen = digitalRead(endSwitchOpen) == LOW; // end switch for fully open
bool isClosed = digitalRead(endSwitchClose) == LOW; // end switch for fully closed
// If not fully open or closed, move the servos
if (!isOpen) {
openGates();
}
if (!isClosed) {
closeGates();
}
}
// function to open gates (move all servos to max position)
void openGates() {
for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) {
for (int i = 0; i < NUM_SERVOS; i++) {
if (digitalRead(endSwitchClose) == LOW) return; // stop if end switch is triggered
pwm.setPWM(servoPins[i], 0, pos);
}
delay(15);
}
}
what if you are running very beefy servos that need more power? will it still work? if not what do I have to do?
hey there! The PCA9685 PWM driver operates at a voltage range between 2.3V and 5.5V for its VCC pin. The v+ terminal is 6v max However, it can still be used to control higher voltage servos by using an external power supply for the servos. Since the servo motor draws current to move, it's best to isolate the power for the servos from the power for the PCA9685 controller board.
Do all work in unison like you displayed, or can I control each servo individually through a Bluetooth HC-05?
Yes, you can control them individually. You’ll need to set up each channel with specific PWM values corresponding to the servo’s position. And yes, you can control individual servos connected to the PCA9685 through a Bluetooth module like the HC-05. I like this idea! Thanks for asking
sorry about that apprently you have to divide your pw by your boards bit rate so mine being a 12 bit had to be divided by 4.07 to get the correct values
hey there! great question. Do you have a link for this? I was under the impression that the PCA9685 takes care of generating the PWM signals for all the channels based on the frequency you've set and the specified pulse widths. It does this simultaneously, so you can control multiple servos independently without needing to manually calculate or divide pulse widths.
aye man sorry found it on a random form somewhere and it worked
but what i did was take my 2500 and 500 and divided it by 4.07 which gave me pretty much the same numbers as in your code
How would I wire and code for them to act of a photoresistor chips for a laser target system
hey there!
Here's what I'm thinking. Is this what you want to do?
The code controls a servo motor based on whether a laser is hitting a photoresistor.
When a laser is pointed at the photoresistor, the photoresistor value exceeds a specific threshold. As a result, the servo motor moves to a new position.
When the laser is not pointed at the LDR, the servo motor returns to its initial position.
The PCA9685 servo driver is used to control the servo, which allows for multiple servos to be connected if needed.
If i'm wrong, let me know. Sounds interesting!
@BMonsterLaboratory the problem I'm running into is the threshold. Idk how m3asure it or Calibrate it or whatever if so new to this but I ha e developed a HUGE passion in the recent weeks and I'm on a mission lol no retreat no surrender, learn this thing Inside and out and create some wild ish
@BMonsterLaboratory yes
@@danielrizzi1153 I have a XINGYHENG 175pcs 7Values 5mm Photoresistor (LDR) kit that I bought on Amazon about 5yrs ago. There are multiple values i this LDR kit. If you want to set up multiple targets, just pick one value and set the threshold values in your code.
For instance, in this kit I would use only the GL5506 LDR for consistent calibration and uniform behavior. This LDR has a dark resistance between 2-6k ohm and a light resistance of 0.15M ohm. For a good threshold value, the resistance will be relatively high wihtout a laser 500-800 depending on the voltage and will drop significantly with a laser (200-400 range). The exact analog values will depend on the strength of your laser - you can see the values in real-time by watching the serial monitor.
Use a voltage divider circuit toconnect the LDR to the analog pin on the Arduino. One end goes to 5v while the other end is connected to a 10k ohm resistor (to ground) - and the point between the resistor and LDR is connected to the analog input. You can search google images for LDR voltage divider circuit.
For you code, you may need to add something like this if you're using, for example, 3 LDR's. The threshold in this example is set at 500.
I hope this was helpful!
#include
// Create the PCA9685 PWM driver object
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Photoresistor pins (using GL5506)
const int LDR_PIN1 = A0; // GL5506-1
const int LDR_PIN2 = A1; // GL5506-2
const int LDR_PIN3 = A2; // GL5506-3
// Single threshold value for all GL5506 sensors
int threshold = 500;
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60); // Set PWM frequency to 60 Hz for servos
// Set initial servo positions
pwm.setPWM(0, 0, 300); // Servo 1 on channel 0
pwm.setPWM(1, 0, 300); // Servo 2 on channel 1
pwm.setPWM(2, 0, 300); // Servo 3 on channel 2
}
void loop() {
// Read values from GL5506 photoresistors
int ldrValue1 = analogRead(LDR_PIN1);
int ldrValue2 = analogRead(LDR_PIN2);
int ldrValue3 = analogRead(LDR_PIN3);
// Print the values for debugging
Serial.print("LDR1: ");
Serial.print(ldrValue1);
Serial.print(" | LDR2: ");
Serial.print(ldrValue2);
Serial.print(" | LDR3: ");
Serial.println(ldrValue3);
// Control Servo 1 based on GL5506-1
if (ldrValue1 > threshold) {
pwm.setPWM(0, 0, 450); // Move servo 1 to a new position when laser hits
} else {
pwm.setPWM(0, 0, 300); // Return servo 1 to the original position
}
// Control Servo 2 based on GL5506-2
if (ldrValue2 > threshold) {
pwm.setPWM(1, 0, 450); // Move servo 2 to a new position when laser hits
} else {
pwm.setPWM(1, 0, 300); // Return servo 2 to the original position
}
// Control Servo 3 based on GL5506-3
if (ldrValue3 > threshold) {
pwm.setPWM(2, 0, 450); // Move servo 3 to a new position when laser hits
} else {
pwm.setPWM(2, 0, 300); // Return servo 3 to the original position
}
delay(100);
}
I want to ask for a way the I can use 1 power supply to power the arduino and the motors at the same time
Easiest way is to use a step down converter. One with a digital display for output - select one rated for your current needs.
Hey there! Will const int = "name" = (number here) work instead of having an array list? or do i have to call each one in an array, and do i have to call the number of servos (line 6). Id really appreciate it! you inspire a lot!
Hi, thanks!
You don't have to use arrays. You can define individual constants like this:
const int SERVO_1 = 0;
const int SERVO_2 = 1;
const int SERVO_3 = 2;
...etc.
But you'll need to reference each servo individually in your code. Doing it this way makes iterating over multiple servos or performing actions on all servos cumbersome. Arrays make your code look cleaner and easier to manage.
NUM_SERVOS defines the number of servos you are going to control. It helps you easily adjust the number of servos without needing to change the code in multiple places.
good questions! 👍
Hi I have hooked up my servos to my board. They say they have a pw of 500 to 2500 yet they seem to only move a few degrees when I plug in my values to replace the ones u entered . Any thoughts on this would be appreciated.
just curious....what board and servos are you using? Thanks for sharing this 👍
Hey can we control each servo differently like one in clockwise and another one in anticlock wise at the same time
sure! You're loop would look something like this:
//servo1 moves clockwise and servo2 counterclockwise
for (int pos = 0; pos = 0; pos -= 1) {
servo1.write(pos);
servo2.write(180 - pos);
delay(15);
}
You may need to adjust it according to your project, but that's the idea. 👍👍
hi there, thank you so much for your video, really helpful. quick question in term of power supply, im using 6 MG996R at the moment at 5V 15A seems to be too much for them, do you suggest particular lower A for the power supply?
Hello! If the 5v 15A supply is working for you, stick with it. You want to be sure to have plenty of overhead current to handle the servos when they are all drawing the most current at 5v and the motors will only draw the current they need. Check data sheets and test to ensure there's no over heating or erratic behavior of the motors based on your project. But, I would keep the 5v 15A supply for 6 servos. I hope this helps!
Hello sir i need help with my thesis project im already done with the wirings and programming its all good but why is that my servo motors are not functioning?? Im using PCA9685 with 3 MG996R and 3 MG995. With a 5v 2amps power source
Those 2 servo motors are 6v servos that can draw up to, and maybe a little over, 1amp of current each depending on peak load and speed. I am assuming your issues is the lack of current to power these motors. For 3 of each, and a total of 6 servos, I would use 5v-6v at 8-10amps. The motors will only draw the current they need so having a little overhead would be good. You may find a stand alone variable power supply or a step down converter to be useful. Perhaps you could test the motors and board by removing all but 1 servo and testing it at each servo position.
Hey, What is the max output current for PCA9685?
Hey there! Sorry for late reply, been traveling the past few days.
I have a 5v10a supply connected. If you need more current for a lot of servos, try using an external power source and just connect ground and servo signal wires to the driver board for pwm control. I would not put more than 10amp supply on v+ to power the board. I believe this is the safest approach. I hope it helps
Do you know if you can control the servos using potentiometers? I haven’t had much luck controlling them while using the servo driver.
hey there! You can manually turn the potentiometers to control the movement of the servos when using the PCA9685 PWM Driver or you can connect the potentiometers to the Arduino directly and control them that way.
Just curious, what kind of issues are you having with the driver?
Hello my friend. Excellent video. I compiled the video code on Arduino Uno and it worked perfectly. I wanted to ask you how do I increase the servo speed? I wish it moved faster.
Hi.. thank you! 👍
I don't have access to the code at the moment but it's posted on face book.
try decreasing the delay. Should look something like this...
MyServo.write(0);
delay(1000); //decrease this number to increase speed
Thanks. I managed to find it and change the speed.
Great
where can i find the code?
hey there! i posted it to facebook. just search #servoduino on Facebook and look for the post. check the comment section. 👍
Hello, could i ask you i have 7,4V 2S lipo bat. and I use it to power the servos I have 12 servo motors and each one takes about 3A under load. The question is… is it possible to use this driver pca9685?
Hey there! This board cannot directly drive a 7.4v servo. The PCA9685 operates with a supply voltage range of 2.3 V to 5.5 V. However, you can connect your servos to a 7.4v power source and use the PCA9685 board to send control signals to the servo via its PWM control input (assuming your servo has a 5v signal pin). You may also want to check out high voltage servo drivers. This one is a stand alone servo controller - www.adafruit.com/product/5437?gad_source=1&gclid=CjwKCAiAt5euBhB9EiwAdkXWO9AbfugiJgUH6CyWzK35_XNwNcthAU-gfVnBhwZ7Tj0AlACuxN4CvxoCmvoQAvD_BwE -It supports high voltage servos, up to 11V. I have never used it but i'm sure there are some good demo videos out there.
You're going to need a lot of current. Consider integrating fuses into your design to protect against short circuits or overcurrent. A fuse rated slightly above your expected maximum current will help prevent damage to your components.
hope I answered your question. good luck to you!
@@BMonsterLaboratory I tried connecting the servos and it worked fine even at 7.4V. I'm just worried that the pca9685 will be ruined for long term use.
@@martinsvoboda1237 I agree.
Good job! Thanks for explain very well about powering only the chip.
Where can I find this code to test my board? I couldn't find this one in your Facebook page... There's tons of projects there!
Hey, thanks! I will post it at 4pm EST
sorry about the delay.
I’m getting really annoyed with my boards. I have five micro servos (specifically MG90S) connected to this and my Arduino. I have a portable battery to power the Arduino and a Tenergy 6V NiMh battery (for RC cars) powering the servos (connected to the terminal block).
It was working fine for a few days, then magically didn’t. I thought it was the battery so I bought a Tenergy balance charger and charged the battery. Multimeter checked the battery and it seemed fine.
Definitely frustrating. I’m not *new* new but I’m still fairly inexperienced. Arduino forums weren’t much of a help, since the only questions that needed answering were in regards to bad wiring diagrams lol
Any suggestions would be much appreciated. 🙏
hey there! if it was working and now it doesn't, i'm wondering about the battery. It sounds like the wiring is fine but I'm happy to help where I can. what is the mAh of you 6v battery? If your 6V battery capacity is 1600mAh, its continuous discharge rate might not be high enough to handle 4.5A and could overheat or be damaged but it also depends on usage duration and servo load. It's recommended to choose a battery with a higher capacity than the minimum required. Consider a 2000mAh or 2500mAh battery to provide a safety margin and potentially longer runtime.... just my initial thoughts.
@@BMonsterLaboratory Thank you for your quick reply! The battery I’m using is 2000mAh. If I need one go up to 2500 I can try ordering one of those too
@@KOAlleyCat can you send me a picture or diagram of your connections? Facebook or email is fine. Perhaps you don't need a new battery
@@BMonsterLaboratory You’re amazing. I’ll send you what I have over FB Messenger. I’ll try to show as much as possible as well as what I’ve already tried. I appreciate you and your time so much. I’m teaching a class of kids next weekend on how I built my last one (community leader asked if I’d help and I love to help kids so I said yes lol) and introduce them to the basics of Arduino programming. But the last one I made I had the servos directly wired to the Arduino. This time I wanted to use a servo driver and it’s been a pain in my rear!
Are there codes available to download for this video?
I normally post them to Facebook but sometimes that can become confusing when it requires multiple posts for one sketch. I need a place to contain all project code that people can freely access.....anyway, Here's the code I posted for this video. 👍
#include
#include
Adafruit_PWMServoDriver pwm;
#define NUM_SERVOS 5
#define SERVO_MIN 100
#define SERVO_MAX 600
#define SERVO_DELAY 1000 // Delay in milliseconds
int servoPins[NUM_SERVOS] = {0, 1, 2, 3, 4};
void setup() {
Serial.begin(9600);
Serial.println("Alternate Servo Test");
pwm.begin();
pwm.setPWMFreq(50); // Set the PWM frequency for the PCA9685
// Initialize all servos to their minimum positions during setup
for (int i = 0; i < NUM_SERVOS; i++) {
pwm.setPWM(servoPins[i], 0, SERVO_MIN);
}
}
void loop() {
// Rotate all servos to one extreme position
for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) {
for (int i = 0; i < NUM_SERVOS; i++) {
pwm.setPWM(servoPins[i], 0, pos);
}
delay(15);
}
delay(SERVO_DELAY);
}
hi there, impressive video how to drive the servos with the pca9685. I only have one question regarding the baud rate. As I know the Mega requires a baud rate of 115200 to communicate while the 9600 is for the Uno. Did this have an impact on the control or is this not important with the PCA 9685? Thank you and keep making such kind of videos for us to help with problems.
Hey there! Thank you for the kind comment. It's great to get feedback on videos to improve future content.
The baud rate settings in this video are primarily for serial communication between the Arduino board and my computer. In this instance, Arduino uses serial communication to send and receive data between the board and the computer. The baud rate specifies the data transfer speed in bits per second and the baud rate uploaded to the Arduino needs to match the baud rate set in your serial monitor. The PCA9685 PWM driver communicates with the Arduino via the I2C protocol, which is not affected by the serial baud rate settings. So no, baud rate doe not impact control of the servos.
Thank you for asking and I hope you enjoy building your Arduino project! 👍💪
@@BMonsterLaboratory Thank you for your explanation. Now I understand the difference using the baud rate for communication between units in the Arduino world.
What power supply do you recommend for 15 Servos?
And what can I use to make it portable
hey there! It depends on the servos you're using. The MG995 servos can have current at maximum load: 1200mA according to components101.com/motors/mg995-servo-motor You want enough current to accommodate all 15 servos. Current load for 15 servos could be around 18A (15 * 1200mA = 18000mA = 18A) It's advisable to choose a battery with a higher current rating than you need to ensure reliable and stable performance, taking into account factors like battery efficiency, voltage drops, and safety margins. Be sure to do our research and make sure you look over data sheets for the servos and other components you're going to use. I, personally, haven't used more than 6 servos on this driver. If you're using 15 MG995, I'd be interested in what you think of the performance. 👍
Can you have the servos doing different operations at the same time or can they only do the same action across them all
hi, yes... you should be able to. sorry for the late response. If you're using the code I posted on Facebook, you would have something similar to this:
for (int pos = SERVO_MIN; pos
there is something like this, but for just 8 servo???
You can user 8 servos on this. are they they same model? MG995?
I see recommendations not to use more than 10amps with this board. If your motors pull more than 10A, use an external power supply for the motors and ensure common ground with the PCA9685. This will help protect your components, and the board will control the motors properly using the data pins without overloading its power capabilities. 👍💪
@@BMonsterLaboratory ty for your answer. I want to control 8 linear servos with 3.3v.... and I want something of 8 beacuse I want to reduce the space inside the robot. (sorry my english, is not so good)
@@Aratgurth you're English is great.
Just make sure to watch your current and don't overheat.
@@BMonsterLaboratory thanks!
@@Aratgurth you're welcome. best of luck to ya
Hello. Even though I have completed the connections and library installation you explained in the video, exit status 1
Compilation error for Arduino Uno board. I'm getting the error. But when I load another code, I do not encounter this error. Can you help me, thank you in advance.
so, it's probably a syntax error or board selection error... Did you copy and paste code from Facebook post?
If not, try this.
#include
#include
Adafruit_PWMServoDriver pwm;
#define NUM_SERVOS 5
#define SERVO_MIN 100
#define SERVO_MAX 600
#define SERVO_DELAY 1000 // Delay in milliseconds
int servoPins[NUM_SERVOS] = {0, 1, 2, 3, 4};
void setup() {
Serial.begin(9600);
Serial.println("Alternate Servo Test");
pwm.begin();
pwm.setPWMFreq(50); // Set the PWM frequency for the PCA9685
// Initialize all servos to their minimum positions during setup
for (int i = 0; i < NUM_SERVOS; i++) {
pwm.setPWM(servoPins[i], 0, SERVO_MIN);
}
}
void loop() {
// Rotate all servos to one extreme position
for (int pos = SERVO_MIN; pos = SERVO_MIN; pos -= 1) {
for (int i = 0; i < NUM_SERVOS; i++) {
pwm.setPWM(servoPins[i], 0, pos);
}
delay(15);
}
delay(SERVO_DELAY);
}
@@BMonsterLaboratory I made a mistake while installing the library🤦♂ Thank you very much for your help. I subscribed to your channel :)
@@ardaa2607 great! thank you. I hope you find more videos that are helpful. If you have any questions just leave a message here, on facebook, or send an email. 👍
Can i turn it off and on
hey there! you could set the PWM to a certain duty cycle. For example, setting it to 50% duty cycle means the channel will be on half the time and off the other half. To turn a channel off, set its PWM value to 0, resulting in no signal being outputted.
Here's what that might look like:
#include
#include
// Create PCA9685 object
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(1000); // Set the frequency to 1000 Hz
}
void loop() {
// Turn channel 0 fully on (100% duty cycle)
pwm.setPWM(0, 4096, 0);
delay(1000); //on for 1 second
// Turn channel 0 off
pwm.setPWM(0, 0, 4096);
delay(1000); //off for 1 second
}
Can u guide me for a project ??
Hey there! I am happy to assistance however I can. Not sure about guiding through every step.
Tell me the goal of your project, components you are using, and your experience level.
I am currently traveling but will be available next week. 👍
@@BMonsterLaboratory cool, that will be really helpful. Where can I connect with u??
@@kaushlendrapandey5404 Facebook mssg has worked well for me facebook.com/BMonster-Laboratory-101410418059806/
I usually check it at night. Feel free to send a message if you have a question.