loading

While there are a lot of tutorials, on how to control Servos with joysticks, and analog sensors, sometimes we want to control a servo with buttons.

Here is a really easy and quick way to achieve this, with the help of Visuino - an easy to use and powerful graphical development environment for Arduino.

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it. Please make sure you click on the image to see the annotation showing the correct spot on the image!

Step 1: Components

  1. One Arduino board (I used Mega because I had one available, but ONO will be perfectly fine)
  2. One Breadboard
  3. 2 Push Buttons
  4. 2 10K resistors
  5. One Servo (I used SG90)
  6. Few jumper wires
  7. Optionally: one Breadboard power supply

Step 2: Add the Buttons

  1. Install the 2 push buttons on the Breadboard (Picture 1)
  2. Connect the Resistors between one ends of the buttons, and Ground on the Breadboard Power Bus (Picture 2)
  3. Connect jumper wires between the other ends of the buttons and Power on the Breadboard Power Bus (Picture 3)

Step 3: Connect the Buttons to the Arduino

  1. Connect 2 jumper wires (Green and White wires on Picture 1) to the same connection point on the buttons where the 2 resistors are connected (Picture 1)
  2. Connect the other end of one of the wires (Green wire) to Digital Pin 2 of the Arduino Board (Picture 2)
  3. Connect the other end of the second wire (White wire) to Digital Pin 3 of the Arduino Board (Picture 2)
  4. Connect 2 wires to the Power (Red wire) and Ground (Black wire) of he Breadboard Power Bus (Picture 3)
  5. Connect the other end of the Power (Red wire) wire to the 5V power pin of the Arduino Board (Picture 4)
  6. Connect the other end of the Ground (Black wire) wire to the Ground pin of the Arduino Board (Picture 4)

Step 4: Connect the Servo

  1. Attach the Breadboard Power Supply to the Breadboard on the side opposite to the buttons as seen on pictures 4 and 5
  2. Connect a jumper wire between the Grounds of the two Power Buses on the Breadboard as shown on Picture 1
  3. Add Ground(Black wire), Power(Red wire), and Control(Yellow wire) to the Servo connector (Picture 2, and 3)
  4. Connect the other end of the Ground(Black wire), and Power(Red wire) to the separated power bus on the Breadboard(Picture 4) . If you decide to power the Servo directly from Arduino, connect to the same Breadboard power bus, where the Buttons are connected
  5. Connect the other end of the Control(Yellow wire) to the Digital Pin 4 of the Arduino Board (Picture 5)

Step 5: Start Visuino, Add Clock Generators, and Prepare Them to Be Enabled by the Buttons

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.5 or one of the nightly 1.6.7 builds, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino
  2. Type "clo" in the Filter box of the Component Toolbox then select the "Clock Generator" component (Picture 1), and drop two of them in the design area

To Enable/Disable the generators we need to add pins to the Enabled property of the components:

  1. Select the ClockGenerator1 in the design area. In the Object Inspector click on the Pin button at front of the Enabled property, and select "Boolean SinkPin" (Picture 2)
  2. Select the ClockGenerator2 in the design area. In the Object Inspector click on the Pin button at front of the Enabled property, and select "Boolean SinkPin" (Picture 3)

Step 6: In Visuino: Add a Up/Down Counter to Control the Position Servo

  1. Type "count" in the Filter box of the Component Toolbox then select the "Up/Down Counter" component (Picture 1), and drop it in the design area
  2. Connect the components as shown on Picture 2
  3. In the Object Inspector expand the Counter's Min property, then set the RollOver sub property to False, and the Value sub property to 0 (Picture 3)
  4. In the Object Inspector expand the Counter's Max property, then set the RollOver sub property to False, and the Value sub property to 200 (Picture 4)
  5. Select the the Clock Generators, and in the Object Inspector set the Enabled property to False, and the Frequency property to 40 (Picture 5)

Step 7: In Visuino: Add Converter to Convert the Count to Analog Value

  1. Type "Inte" in the Filter box of the Component Toolbox then select the "Integer To Analog" component (Picture 1), and drop it in the design area
  2. In the Object Inspector set the Scale property to 0.005 (Picture 2) . This will convert the counter values from the integer range of 0 to 200, to the analog range of 0.0 to 1.0.
  3. Connect the "Out" pin of the UpDownCounter1 to the "In" pin of the IntegerToAnalog1 component (Picture 3)

Step 8: In Visuino: Add Component to Control the Servo

  1. From the Component Toolbox expand the "Motors" Category, and select the "Servo" component as shown on the first picture, then drop it in the design area
  2. Connect the "Out" pin of the IntegerToAnalog1 component to the "In" pin of the Servo1 component (Picture 2)
  3. Connect the "Out" pin of the Servo1 (Picture 3) to the "Digital" input pin of the Digital[ 4 ] channel of the Arduino component (Picture 4)

Step 9: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 10: And Play...

Congratulations!

The project is completed. You can use the buttons to control the servo. If you press and hold one of the buttons the servo will move in one direction until it reaches the end position. If you press and hold the other button the servo will move in the opposite direction until it reaches the end position.

On Picture 3 you can see the complete Visuino diagram.

Enjoy your servo control :-)

Also attached is the Visuinoproject, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

<p>i have used this on a continuous servo and it just spins one way or the other continuously is there a way to tell it to turn only 2 rotations as i want to use this on my blinds. or even install a stop button so it goes one way until i like where it is then i can stop it, or even stop when i relese the button</p>
You should use a normal servo for this purpose. This project is not designed for continuous servo.
<p>Heyy Boian. Was wondering if i can get IDE code as well.. The struggle is real for mac</p>
Hi MohammadH95,<br>Here is generated code:<br>www.mitov.com/ControlServoWithButtons.zip<br>compatible with the current version of the Visuino libraries:<br>https://bitbucket.org/mitov/visuino-libraries<br> <br>The libraries however will change in the future so the currently generated code will become incompatible. It is best to generate the code with Visuino for the latest versions of the libraries.<br><br>Cheers,<br> Boian
<p>Hay Boian I was wondering if you could send me the IDE code because I have a mac, and sadly Visuino does not work for me. If you could send me the IDE Arduino code, that would be amazing!</p>
<p>You can contact me at mitov@mitov.com and I can send you the code :-)</p>
<p>can this program use at arduino uno?</p>
<p>Yes, absolutely! I just had unconnected Mega available for the Instructable, but I could have done it with UNO too.</p>

About This Instructable

21,222views

108favorites

License:

More by BoianM:Assemble Kuman Wi-Fi Robot With Camera and Manipulator Arduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields  Arduino Nano and Visuino: Animate the Colors of RGB LED 
Add instructable to: