CONTROL 8 SERVO MOTORs USING 8 POTENTIOMETERs (HUMANOID ROBOT EP 02)
by HappyThingsMaker in Circuits > Robots
8427 Views, 65 Favorites, 0 Comments
CONTROL 8 SERVO MOTORs USING 8 POTENTIOMETERs (HUMANOID ROBOT EP 02)

.JPG)
In the previous episode, we could control one servo motor by using one potentiometer.
https://www.instructables.com/id/Control-1-Servo-M...
In this episode, we are going to control 8 motors by using 8 potentiometers simultaneously.
Let’s get it started!
[LINKS]
- Source Code
- Leader] https://github.com/happythingsmaker/MotionCapture...
- Follower ] https://github.com/happythingsmaker/MotionCapture...
Supplies
PCA9675
.JPG)
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.
Overall Principal
.JPG)
This drawing shows its system.
Let’s make the cable first
Making Cables for Potentiometers
.JPG)
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.
Overall Schematic
.JPG)
Now, I am going to assemble all the parts together.
As I always say, we need to make sure the direction.
.JPG)
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.
Code
.JPG)
Let’s take a look into the source code.
It is short and simple but you may not be familiar with it.
Code Explanation
.JPG)
The first line means that I will use a pre-made library to control the PWM board.
Code Explanation
.JPG)
I made an instance of the pwm Driver.
Code Explanation
.JPG)
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.
Code Explanation
.JPG)
These 3 lines are most complicating code.
If you want to know these 2 lines, you better check another video about the PWM driver.
Code Explanation
.JPG)
Let’s take a look into the setPWM function. It needs 3 parameters.
The first parameter is for selecting the servo number.
Code Explanation
.JPG)
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.
Failed!
.JPG)
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.
Solution
.JPG)
.JPG)
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.
Communication
.JPG)
Here is the idea about the communication
Communication
.JPG)
The leader Arduino sends number 255 as
meaning that data is coming.
Communication
.JPG)
And then, sends id number.
For example, if the leader sends the first potentiometer’s value, the number will be 0.
Communication
.JPG)
.JPG)
And then, leader sends its angle value
which range is from 0 to 180
It is very simple but useful. I hope it works well.
Code
Upload the source code.
There are 2 source code files for each Arduinos
Source Code
Leader ] https://github.com/happythingsmaker/MotionCapture...
Follower ] https://github.com/happythingsmaker/MotionCapture...
Test!!
Oh, it works pretty well. I put some delay code to the leader 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