You are on page 1of 10

technology workshop craft home food play outside costumes

Arduino Nano and Visuino: Control Servo with Rotary Encoder


by BoianM on December 25, 2015

Table of Contents

Arduino Nano and Visuino: Control Servo with Rotary Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Arduino Nano and Visuino: Control Servo with Rotary Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2: Connect the Rotary Encoder to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 3: Connect Power to the Servo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 4: Connect the Servo to Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 5: Start Visuino, and select the Arduino Board type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 6: In Visuino: Add and connect Rotary Encoder component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 7: In Visuino: Add and connect Up/Down Counter component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 8: In Visuino: Add and connect Integer To Analog component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 9: In Visuino: Add and connect Servo component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 10: Generate, Compile, and Upload the Arduino code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 11: And play... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Intro: Arduino Nano and Visuino: Control Servo with Rotary Encoder
There are a lot of Instructables on how to control Servo with potentiometer, however sometimes it is useful to control it with a Rotary Encoder. In this Instructable, I will
show you how easy it is to implement this with the help of Visuino - an easy to use graphical development environment for Arduino.

Step 1: Components
1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine )
2. One Rotary Encoder module I got from this cheap 37 sensors set.
3. 1 Small Servo
4. 1 Male-Female jumper wire
5. 5 Female-Female jumper wires
6. One K2 Breadboard power supply with adapter

Step 2: Connect the Rotary Encoder to the Arduino


1. Connect Ground(Black wire), Power(Red wire), Direction(Green wire), and Clock(Yellow wire) to the Rotary Encoder Module (Picture 1)
2. Connect the other end of the Power wire(Red wire) to the 5V power pin of the Arduino board(Picture 2)
3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 2)
4. Connect the Clock wire(Yellow wire) to Digital pin 2 of the Arduino board(Picture 3)
5. Connect the Direction wire(Green wire) to Digital pin 3 of the Arduino board(Picture 3)
6. Picture 4 shows where are the Ground, 5V Power, Digital 2 and Digital 3 pins of the Arduino Nano.

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Step 3: Connect Power to the Servo
1. Connect the Male end of the Male-Female jumper wire (Gray wire) to the Control wire of the Servo as shown on Picture 1
2. Connect the Servo connector to the K2 Power Supply in such a way that the Ground of the Power Supply is connected to the Ground wire of the Servo, and
the Power of the Power Supply to the Power wire of the Servo as shown on Picture 2, and 3
3. Make sure the power supply is set to 5V (Picture 4)

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Step 4: Connect the Servo to Arduino
1. Connect a Female-Female wire (Black wire) to the Ground of the Power Supply as shown on Pictures 1 and 2
2. Connect the other end of the Ground wire(Black wire) to the Ground pin of the Arduino (Picture 3)
3. Connect the Control wire(Gray wire) from the Servo to Digital pin 2 of the Arduino (Picture 3)
4. Picture 4 shows in Red the Arduino Nano pins that ware connected in this step

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Step 5: Start Visuino, and select the Arduino Board type
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.7 or 1.6.5, otherwise this Instructable will not work!

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

1. Start Visuino as shown in the first picture


2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
3. When the dialog appears, select Arduino Nano as shown in Picture 2

Image Notes
1. Click on this "Tools" button

Step 6: In Visuino: Add and connect Rotary Encoder component


1. Type "rot" in the Filter box of the Component Toolbox then select the "Rotary Encoder Sensor" component (Picture 1), and drop it in the design area
2. Connect the "Out" pin of the Digital[ 2 ] channel of the Arduino component to the "Clock(A)" pin of the RotaryEncoderSensor1 (Picture 2)
3. Connect the "Out" pin of the Digital[ 3 ] channel of the Arduino component to the "Direction(B)" pin of the RotaryEncoderSensor1 (Picture 3)

Image Notes
1. Select this component

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Step 7: In Visuino: Add and connect Up/Down Counter component
We need a counter to count the Up/Down rotations from 0 to 100, and we need to set in in the middle/neutral 50:

1. Type "cou" 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 "Down" pin of the RotaryEncoderSensor1 component to the "Down" pin of the UpDownCounter1 component (Picture 2)
3. Connect the "Up" pin of the RotaryEncoderSensor1 component to the "Up" pin of the UpDownCounter1 component (Picture 3)
4. 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 4)
5. In the Object Inspector expand the Counter's Max property, then set the RollOver sub property to False, and the Value sub property to 100 (Picture 5)
6. In the Object Inspector set the value of the InitialValue property to 50 (Picture 6)

Image Notes
1. Select this component

Image Notes
1. Set these 2 properties

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Image Notes Image Notes
1. Set these 2 properties 1. Set this property

Step 8: In Visuino: Add and connect Integer To Analog component


The servo needs analog value in the range between 0 and 1.0, so we need to convert the count to Analog and multiply it by 0.01 to convert the 0 to 100 range into Analog
0 to 1.0:

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.01 (Picture 2) . This will convert the counter values from the integer range of 0 to 100, 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)

Image Notes
1. Select this component

Image Notes
http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
1. Set this property

Step 9: In Visuino: Add and connect Servo component


1. Type "serv" in the Filter box of the Component Toolbox then select the "Servo" component (Picture 1), and drop it in the design area
2. Connect the "Out" pin of the Servo1 component to the "Digital" input pin of Digital[ 4 ] channel of the Arduino component (Picture 2)
3. Connect the "In" pin of the Servo1 component (Picture 3) to the "Out" pin of the IntegerToAnalog1 component (Picture 4)

Image Notes
1. Select this component

Step 10: 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)

Image Notes
1. Click here or press F9 to generate the code

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
Image Notes
1. Click here to compile and upload the code

Step 11: And play...


Picture 1 shows the connected and powered up project.

If you rotate the Rotary Encoder back and fort, the Servo will move in the same direction, as you can see in the video.

On Picture 2 you can see the complete Visuino diagram.


Also attached is the Visuino project, that I created for this Instructable.

You can download and open it in Visuino: https://www.visuino.com

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/
File Downloads

RotaryEncoderServoControlInstructable.zip (995 bytes)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'RotaryEncoderServoControlInstructable.zip']

Related Instructables

NFC Ring Lock


Arduino Nano Arduino Nano: Hexapod4 Arduino: Servo motor?
and Visuino: Rotary Encoder Spider Control Servo Box by
Arduino(ATmega328P-
Control Servos With Visuino by Robot Instruction with Buttons by PU) 8MHz????? Nairod785
With Joystick by BoianM Manual by BoianM ? by SANUKI
BoianM ICStation UDON

Advertisements

Comments

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Servo-With-Rotary/

You might also like