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
- Arduino UNO (or any other board)
- Servo motor
- Jumper wires
- 2X button module
- Visuino program: Download Visuino
- 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
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
- 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
- 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 Arduino 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 Instructable, you can download it and open it in Visuino: https://www.visuino.eu
Download servo-left-right-buttons.zip