Lesson 7: Working with Servo

In this lesson we will work with basic Servo motor. Model Tower Pro SG90.

This is angle rotation controlled motor. Which rotation angle is between 0 and 180 degrees. Connection consist of 3 pins: Brown wire is for GND (-), Red wire is for 5V (+), and Orange wire is for signal input.

Ok, let's make simple connection Servo motor to Arduino.


When you connect this scheme. You need to write a program. But before writing or copying this program, I want you to make notice about <Servo.h> library. Instead of "pinMode()" command we will use "attach()" command.

#include <Servo.h>
Servo s1;

void setup() {
  // here is like pinMode command, but we firstly attach 3rd pin to Servo
  s1.attach(3);
}

void loop() {
  // put your main code here, to run repeatedly:
  s1.write(0); //put Servo to 0 angle degrees
  delay(2000);
  s1.write(180); //put Servo to 180 angle degrees
  delay(2000);
}

Self study:::

Now, please try to add 2 buttons. When one button pressed the angle will increase to 30 degrees, when second button pressed the angle will decrease. Of course you have to count that angle must not be less than 0 or bigger than 180 degrees.








Comments

Popular posts from this blog

Lesson 9: Piezo Buzzer

Lesson 10: Piezo Buzzer controlled with Potentiometer

Lesson 6: Potentionmeter & LED