Arduino Control Servo Motor Position With Buttons

About the project

In this tutorial we will learn how to Control Servo motor position with buttons using arduino. Watch the Video!

Project info

Difficulty: Easy

Platforms: ArduinoDFRobotVisuino

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Jumper wires (generic) Jumper wires (generic) x 1
SG90 Micro-servo motor SG90 Micro-servo motor x 1
Arduino UNO Arduino UNO x 1
DFRobot Gravity:Digital Push Button (Yellow) DFRobot Gravity:Digital Push Button (Yellow) x 2

Software apps and online services

Visuino Visuino
Arduino IDE Arduino IDE

Story

In this tutorial we will learn how to Control Servo motor position with buttons using arduino.

Watch the Video!

Step 1: What You Will Need

1 / 3

  • Arduino UNO (or any other board)
  • Servo motor
  • Jumper wires
  • 2X button module
  • Visuino program: Download Visuino

Step 2: Circuit

1 / 2

  • Connect Servo motor "Orange" (signal) pin to Arduino Digital pin[2]
  • Connect Servo motor "Red" pin to Arduino positive pin[5V]
  • Connect Servo motor "Brown" pin to Arduino negative pin[GND]
  • Connect Button1 pin [VCC] to Arduino positive pin[5V]
  • Connect Button1 pin [GND] to Arduino negative pin[GND]
  • Connect Button1 signal pin [S] to Arduino digital pin[8]
  • Connect Button2 pin [VCC] to Arduino positive pin[5V]
  • Connect Button2 pin [GND] to Arduino negative pin[GND]
  • Connect Button2 signal pin [S] to Arduino digital pin[9]

Step 3: Start Visuino, and Select the Arduino UNO Board Type

1 / 2

The Visuino: https://www.visuino.eu also needs to be installed. Download Free version or register for a Free Trial.Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

Step 4: In Visuino Add & Set Components

1 / 7

  • Add 2X "Detect Edge" component
  • Add "Up/Down Counter" component
  • Add "Integer To Analog" component
  • Add "Divide Analog By Value" component
  • Add "Servo" component
  • Select "UpDownCounter1" and in the properties window set Max > Value to 10 and "Roll Over" to False
  • Select "UpDownCounter1" and in the properties window set Min> Value to 0 and "Roll Over" to False
  • Select "DivideByValue1" and in the properties window set Value to 10

Step 5: In Visuino Connect Components

1 / 3

  • Connect Arduino Digital Pin [8] to DetectEdge1 pin [In]
  • Connect Arduino Digital Pin [9] to DetectEdge2 pin [In]
  • Connect DetectEdge1 pin [Out] to UpDownCounter1 pin [Up]
  • Connect DetectEdge2 pin [Out] to UpDownCounter1 pin [Down]
  • Connect UpDownCounter1 pin [Out] to IntegerToAnalog1 pin [In]
  • Connect IntegerToAnalog1 pin [Out] to DivideByValue1 pin [In]
  • Connect DivideByValue1 pin [Out] to Servo1 pin [In]
  • Connect Servo1 pin [Out] to Arduino board digital pin [2]

Step 6: Generate, Compile, and Upload the Code

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Step 7: Play

If you power the Arduino module and by pressing the buttons you will be able to change the servo motor position.

To Set the servo degrees check out this tutorial How to Control Servo Motor Angle Using Visuino Sequence Component

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this tutorial, you can download it and open it in Visuino: https://www.visuino.eu

Schematics, diagrams and documents

Visuino File

Code

Visuino File

Credits

Photo of Ron

Ron

Arduino Developer

   

Leave your feedback...