Week 3 - Servo and Potentiometer

Week 3 - New components: Servo and Potentiometer

In this weeks lecture of physical we were firstly introduced to a new component called a Servomotor. A Servomotor or Servo for short is a rotary actuator that allows for precise control of angular positions. Servos are commonly used within remote controlled cars or airplanes for accurate movements such as rudders.

A servo usually has three wires: power, ground and signal. The power cable is usually red and connected to the 5v power on an Arduino. The ground is usually brown or black and connect to the ground port on the Arduino. The signal wire is usually yellow, orange or white and this is what gives the Servo the signal of what position to point in.

A servo will only spin 180 degree and the position it points in is dependent on the signals sent to it. The diagram below shows the pulses sent to the Servo through the signal wire. The greater the width between each pulse the further the Servo will point in one direction.

Diagram:











The gaps between each pulse is measured is milliseconds. The gaps between each pulse will be between 1000-3000ms so 1500ms will mean the Servo will point in the middle.

Arduino-

Once we were explained about Servos and how they work we were given one to experiment on with the Arduino. Firstly we coded the Servo to turn 180 degrees one way and then 180 degrees the one way. Using an if statement the delay between the Servo going from 0 degrees to 180 degrees decided the time it took for this to happen.

Code:



Image: 




Once we completed this we added a potentiometer. A potentiometer is a three terminal resistor which varies the resistance through the circuit using a knob that the user can turn. Turning one way will increase the resistance and turning it the other way will decrease the resistance.

Using a potentiometer I coded the Servo to move through it 180 degree movement depending on the resistance. The following code below shows how this was done. Firstly the potentiometer can read a value between 0-1023 so this firstly had to be scaled down to the 180 degrees of movement for the Servo.

Once this was done it was very simple to set the value of the potentiometer to the position of the Servo.

Code:


























Image:


After this I added an LED so that if the angle was above 90 degrees one LED would light and below 90 degrees another LED would light. 

Code:


Image: 


Comments

Popular posts from this blog

Week 2 - LDR

Week 1 - Introduction Session