Introduction: CONTROL 8 SERVO MOTORs USING 8 POTENTIOMETERs (HUMANOID ROBOT EP 02)
In the previous episode, we could control one servo motor by using one potentiometer.
In this episode, we are going to control 8 motors by using 8 potentiometer simultaneously. Let’s get it started!
- Source Code
- Master] https://github.com/happythingsmaker/MotionCapture...
- Slave ] https://github.com/happythingsmaker/MotionCapture...
[ Parts ]
Step 1: PCA9675
In order to use many servo motors,
I am going to use this PCA9675 board which has 16 PWM output.
The only thing we have to do is sending the signal to this board by using I2C communication.
You may feel it sounds hard but don’t worry. There are so many pre-made source code files.
Actually, it is pretty simple.
Step 2: Overall Principal
This drawing shows its system.
Let’s make the cable first
Step 3: Making Cables for Potentiometers
I am going to make 8 cables for connecting the potentiometers and the Arduino board.
The cable I use is called Dupont cable. I bought assembled cables.
Step 4: Overall Schematic
Now, I am going to assemble all the parts together.
As I always say, we need to make sure the direction.
Now, let’s make a source code for it.
Basically, the Arduino is going to read analog values and send i2c data.
Once the PWM module receives the data, it generates PWM signal immediately.
Step 6: Code
Let’s take a look into the source code.
It is short and simple but you may not be familiar with it.
Step 7: Code Explanation
The first line means that I will use a pre-made library to control the PWM board.
Step 8: Code Explanation
I made an instance of the pwm Driver.
Step 9: Code Explanation
These 2 lines are for setting up the board.
I tested the frequency and it turned out I need to add 1 to the frequency number.
50Hz is normally used.
Step 10: Code Explanation
These 3 lines are most complicating code.
If you want to know these 2 lines, you better check another video about the PWM driver.
Step 11: Code Explanation
Let’s take a look into the setPWM function. It needs 3 parameters.
The first parameter is for selecting the servo number.
Step 12: Code Explanation
The Second and third parameters are for setting the timing of PWM.
If you don’t understand it, just skip it. Just copy and paste the code and try it.
Step 13: Failed!
As you can see, I don’t think it works well. I took a look closely and found the problem.
ADC and I2C share the same pins.
We can use A4 and A5 pins as not only ADC, but also I2C. But, we cannot use it simultaneously.
Step 14: Solution
That’s why I need to use one more Arduino.
One Arduino is for getting potentiometer’s value, sending its value to another Arduino through a serial communication.
Another Arduino is for operating the pwm driver based on the value from the communication.
Step 15: Communication
Here is the idea about the communication
Step 16: Communication
The Master Arduino sends number 255 as
meaning that data is coming.
Step 17: Communication
And then, sends id number.
For example, if the master sends the first potentiometer’s value, the number will be 0.
Step 18: Communication
And then, master sends its angle value
which range is from 0 to 180
It is very simple but useful. I hope it works well.
Step 19: Code
Upload the source code.
There are 2 source code files for each Arduinos
Step 20: Test!!
Oh, it works pretty well. I put some delay code to the master Arduino
Next video, I am going to show how to communicate it without any wire.
Wireless communication is so useful as you know.
If you have any question, feel free left a comment on this Instructables
This is an entry in the
Make it Move Contest
We have a be nice policy.
Please be positive and constructive.