Introduction: Controlling Servo Motor From Terminal With Precise Angle Using Raspberry Pi
In this project I'm going to control one servo motor with precise angle using raspberry pi.
Step 1: Software Used
a) Raspbian OS: This is the recommended OS for raspberry pi. You can also installed other OS from third party. Raspbian OS is debian based OS. We can install it from noobs installer. you can Download it from here
b) Python idle: This is the software we get in raspbian os. For this project we have used python script.
c) Putty: We are using putty for remote access of Raspberry Pi.you can Download it from here
d) Win32DiskImager: This software is used to burn Raspbian Os on SD Card. you can Download it from here
e) SDFormatter: This software is used to format memory card. you can Download it from here
Step 2: Components Used
For this project you need :
1) Raspberry pi 3 :
This is the latest version of raspberry pi. In this we have inbuilt Bluetooth and wi-fi, unlike previously we have to use Wi-Fi dongle in one of its usb port. There are total 40 pins in RPI3. Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins.) There are 4 USB Port and 1 Ethernet slot, one HDMI port, 1 audio output port and 1 micro usb port and also many other things you can see the diagram on right side. And also we have one micro sd card slot wherein we have to installed the recommended Operating system on micro sd card. There are two ways to interact with your raspberry pi. Either you can interact directly through HDMI port by connecting HDMI to VGA cable, and keyboard and mouse or else you can interact from any system through SSH(Secure Shell). (For example in windows you can interact from putty ssh.) Figure is given above.
2 Servo Motor:
There are some special types of application of electrical motor where rotation of the motor is required for just a certain angle not continuously for long period of time. For these applications, some special types of motor are required with some special arrangement which makes the motor to rotate a certain angle for a given electrical input (signal). For this purpose servo motor comes into picture.
This is normally a simple DC motor which is controlled for specific angular rotation with the help of additional servomechanism (a typical closed loop feedback control system).
Step 3: Project Description
Here we will control servo motor from terminal. In this case we will use linear equation formula. In my servo motor I am getting full left at Duty Cycle 2 and full right at Duty Cycle 12. You can test your servo by giving the command
Now two points we get and that is (0,2) and (180,12)
So slope of the line will be
m=(y2-y1)/(x2-x1)=(12-2)/180-0)=10/180 = 1/18
Now using the point slope formula, equation of the line will be:
y = 1/18*x + 2
This will become:
DutyCycle = 1/18* (DesiredAngle) + 2
Step 4: Circuit Diagram
Step 5: Source Code
You can download the source code from the below link.
Step 6: Conclusion
If you have any doubt regarding this project feel free to comment us below or you can mail us on email@example.com. And if you want to learn more about these type of projects then feel free to visit our youtube channel
Thanks & Regards,
We have a be nice policy.
Please be positive and constructive.