arduino nano and visuino: control stepper ... - instructables.com

9
http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/ technology workshop craft home food play outside costumes Arduino Nano and Visuino: Control Stepper Motor with Rotary Encoder by BoianM on June 10, 2016 Table of Contents Arduino Nano and Visuino: Control Stepper Motor with Rotary Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: Arduino Nano and Visuino: Control Stepper Motor with Rotary Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: Connect the Stepper Motor to Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 3: Connect the Rotary Encoder to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 4: Start Visuino, and select the Arduino Board type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 5: In Visuino: Add Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Step 6: In Visuino: Add Reversed pin to the Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Step 7: In Visuino: Connect the Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Step 8: Generate, Compile, and Upload the Arduino code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Step 9: And Play... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Upload: khangminh22

Post on 15-Jan-2023

0 views

Category:

Documents


0 download

TRANSCRIPT

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

technology      workshop      craft      home      food      play      outside      costumes     

Arduino Nano and Visuino: Control Stepper Motor with Rotary Encoderby BoianM on June 10, 2016

Table of Contents

Arduino Nano and Visuino: Control Stepper Motor with Rotary Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

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

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

Step 2:   Connect the Stepper Motor to Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 3:   Connect the Rotary Encoder to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

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

Step 5:   In Visuino: Add Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 6:   In Visuino: Add Reversed pin to the Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 7:   In Visuino: Connect the Stepper Motor component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

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

Step 9:   And Play... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

Intro:  Arduino Nano and Visuino: Control Stepper Motor with Rotary EncoderSometimes it is necessary to have a Stepper Motor follow the rotation of a Rotary Encoder for precise positioning. I have been planning Instructable on this for a longtime, but finally couple of days ago after yet another question by Visuino user, on how to do this, I decided that the time is now.

In this Instructable, I will show you how easy it is to connect a Stepper Motor and Rotary Encoder to Arduino and program with Visuino the Stepper Motor to followthe rotations of the Rotary Encoder.

Step 1: ComponentsOne Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)1.One Rotary Encoder module I got from this cheap 37 sensors set2.One 5V Stepper Motor with Driver Board (I used 28BYJ-48 stepper with ULN2003 driver board )3.One small Breadboard (Any breadboard can be used, or any other way to connect 3 wires together)4.8 Female-Female jumper wires5.3 Male-Female jumper wires (Red)6.

Step 2: Connect the Stepper Motor to ArduinoIf not already connected, plug the Stepper Motor connector into the Driver Board1.Connect one end of Female-Female jumper wires(Blue, Green, Yellow and Orange wires) to the IN1 to IN4 pins of the Stepper Driver(Picture 1)2.Connect Female-Female Ground(Black wire), to the Ground(-) pin the Stepper Driver Module (Picture 2)3.Connect the Female end of a Female-Male Power(Red wire), to the Power(+) pin of the Stepper Driver Module (Picture 2)4.Connect the Female End of another Female-Male Power wire(Red wire) to the 5V power pin of the Arduino board (Picture 3)5.Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board (Picture 3)6.Connect the IN1 wire(Blue wire) to the Digital pin 2 of the Arduino board (Picture 4)7.Connect the IN2 wire(Green wire) to the Digital pin 3 of the Arduino board (Picture 4)8.Connect the IN3 wire(Yellow wire) to the Digital pin 4 of the Arduino board (Picture 4)9.Connect the IN4 wire(Orange wire) to the Digital pin 5 of the Arduino board (Picture 4)10.Picture 5 shows where are the Ground, 5V Power, and Digital 2 to Digital 5 pins of the Arduino Nano11.

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

Step 3: Connect the Rotary Encoder to the ArduinoConnect the Female end of a Female-Male Power(Red wire) to the power pin of the Rotary Encoder Module (Picture 1)1.Connect Ground(Black wire), Direction(Purtle wire), and Clock(Gray 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(Gray wire) to Digital pin 6 of the Arduino board(Picture 2)5.Connect the Direction wire(Purple wire) to Digital pin 7 of the Arduino board(Picture 2)6.Connect the Male ends of the 3 Power wires(Red wires) - from the Rotary Encoder Module, the Stepper Motor Driver, and the Arduino together as example7.with the help of a Breadboard (Picture 3) - In my case I used a small BreadboardPicture 4 shows in Red where are the Ground, Digital 6 and Digital 7 pins of the Arduino Nano. In Blue are shown the pins connected in the previous step.8.

Step 4: Start Visuino, and select the Arduino Board typeTo 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 higher, otherwise this Instructable will not work!

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

Start Visuino as shown in the first picture1.Click on the "Tools" button on the Arduino component (Picture 1) in Visuino2.When the dialog appears, select "Arduino Nano" as shown in Picture 23.

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

Image Notes1. Click on this "Tools" button

Step 5: In Visuino: Add Stepper Motor componentType "step" in the Filter box of the Component Toolbox then select the "4 Wire Stepper Motor" component (Picture 1), and drop it in the design area1.In the Object Inspector set the value of the "Enabled" property to "False" (Picture 2)2.

Image Notes1. Select this component

Image Notes1. Set this property

Step 6: In Visuino: Add Reversed pin to the Stepper Motor componentIn the Object Inspector click on the Pin button at front of the Reversed property(Picture 1), and select "Boolean SinkPin" (Picture 2)1.A new "Reversed" Pin will appear on the component (Picture 3)2.

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

Image Notes1. Click on this button

Image Notes1. Select this

Image Notes1. You will see this new pin

Step 7: In Visuino: Connect the Stepper Motor componentClick in the "Out" box containing the pins of the Stepper component to start connecting all the Out pins at once (Picture 1)1.Move the mouse over the "Digital" input pin of the "Digital[ 2 ]" channel of the Arduino component. The Visuino will automatically spread the wires so they will2.connect correctly to the rest of the pins(Picture 1)Connect the "Out" output pin of the "Digital[ 6 ]" channel of the Arduino component to the "Reversed" input pin of the Stepper1 component (Picture 2)3.Connect the "Out" output pin of the "Digital[ 7 ]" channel of the Arduino component to the "Step" input pin of the Stepper1 component (Picture 2)4.

Image Notes

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

1. Click here to start connecting all the pins at once

Step 8: Generate, Compile, and Upload the Arduino codeIn Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE1.In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)2.

Image Notes1. Click here or press F9 to generate the code

Image Notes1. Click here to compile and upload the code

http://www.instructables.com/id/Arduino-Nano-and-Visuino-Control-Stepper-Motor-Wit-1/

Step 9: And Play...Congratulations! You have completed the project.

Picture 1 and the Video show the connected and powered up project.

If you rotate the Rotary Encoder, the Stepper Motor will rotate in the same direction as the encoder as you can see from 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-Stepper-Motor-Wit-1/

File Downloads

ControlStepperWithRotaryEncoderInstructable.zip (906 bytes)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'ControlStepperWithRotaryEncoderInstructable.zip']

Related Instructables

ARDUINOstepper motorcontrolled withrotary encoderand l293d orSN754410NEchip by Z-HUT

Going BeyondStandardFirmata- Adding NewDevice Supportby MrYsLab

Arduino Nanoand Visuino:Control StepperMotor withButtons byBoianM

ITTT Robot armarcade game byNLruben

Arduino Nano:Rotary Encoderwith Visuino byBoianM

Arduino Nanoand Visuino:Measure MotorSpeed (RPM)WithOptocouplerand EncoderDisk by BoianM

Advertisements

Comments