Arduino Control Servo Motor Position With Buttons

by RonFrtek in Circuits > Arduino

891 Views, 3 Favorites, 0 Comments

Arduino Control Servo Motor Position With Buttons

Arduino Control Servo Motor Position With Buttons

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

Watch the Video!

What You Will Need

pngegg.png
button module red 2-1000x1000.jpg
FZEK4WBK3XGYAP0.LARGE.jpg
VisuinoAdvrtisementRaspberryPiRobot1.jpg
  • Arduino UNO (or any other board)

  • Servo motor

  • Jumper wires

  • 2X button module

  • Visuino program: Download Visuino

Circuit

2020-12-06_21-43-31.jpg
FZJ1USDK26CLY4O (1).jpg
  • 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]

Start Visuino, and Select the Arduino UNO Board Type

F5ZAEMUK36U3RS2.LARGE.jpg
F311FBVK5AHN5HJ.LARGE.jpg

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

In Visuino Add & Set Components

2021-01-20_17-03-01.jpg
2021-01-20_17-02-39.jpg
2021-01-20_17-02-14.jpg
2021-01-20_17-01-52.jpg
2021-01-20_17-01-32.jpg
2021-01-20_17-03-46.jpg
2021-01-20_17-04-02.jpg
  • 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

In Visuino Connect Components

2021-01-20_16-31-20.jpg
servo-button.png
2021-01-20_16-31-38.jpg
  • 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]

Generate, Compile, and Upload the Code

2020-10-30_13-20-50.jpg

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.

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 Instructable, you can download it and open it in Visuino: https://www.visuino.eu