Hi guys,

Today I'll show how you can control a servo with Visual basic. Before this project I’ve never used Visual basic so if anyone finds any mistake in my code please leave a comment here and help me improve it.

you can visit my website for more electronic projects, interesting news and tips:

I've always used the Serial Monitor of the Arduino IDE to communicate with the Arduino, but today we will use a visual basic program that I've created. Basically in the VB program we have 4 buttons that will interact with the Arduino when we press them.

I’ll be showing program in Visual Basic that allows the user to rotate a servo attached to the Arduino. You need to make 3 connections from the servo to your arduino:

   Red: 3.3V (depends on your Servo motor)
   Brown: Ground
   Orange: Digital Pin 9

   Click here to download the VB code
   Click here to download the Arduino Sketch

   When you're using the Visual Basic Program the Serial monitor on the Arduino IDE must be closed
   You need to match the com port on your Visual Basic Code to the right com port you're Arduino is using

I don't know why but youtube cropped my video, the Last two buttons are "Rotate 180º Left" and "Rotate 180º right" . anyway watch it working :)

If you have any questions leave a comment!
<p>Hi Sir, i have my project using Visual basic connected to an arduino to drive 5led and 5 servo motors to do a sweep (once) movement. can someone help me to figure out why my servos are not rotating? the led are working well except for the servos which likely receiving a pulse signal only. i already tried sweep but not activating when triggered by serial from my vb program. below is my code: appreciate very much your help..</p><p>#include &lt;Servo.h&gt;</p><p>Servo myservo1;</p><p>Servo myservo2;</p><p>Servo myservo3;</p><p>Servo myservo4;</p><p>Servo myservo5;</p><p>int ledPin1 = 13; </p><p>int ledPin2 = 12;</p><p>int ledPin3 = 11;</p><p>int ledPin4 = 10;</p><p>int ledPin5 = 9;</p><p>void setup() {</p><p>Serial.begin(9600); // set serial spee</p><p>pinMode(ledPin1, OUTPUT); // set LED as output</p><p>pinMode(ledPin2, OUTPUT);</p><p>pinMode(ledPin3, OUTPUT);</p><p>pinMode(ledPin4, OUTPUT);</p><p>pinMode(ledPin5, OUTPUT);</p><p>digitalWrite(ledPin1, LOW); //turn off LED</p><p>digitalWrite(ledPin2,LOW);</p><p>digitalWrite(ledPin3,LOW);</p><p>digitalWrite(ledPin4,LOW);</p><p>digitalWrite(ledPin5,LOW);</p><p>myservo1.attach(1);</p><p>myservo2.attach(2);</p><p>myservo3.attach(3);</p><p>myservo4.attach(4);</p><p>myservo5.attach(5);</p><p>}</p><p>void loop()</p><p>{</p><p>while (Serial.available() == 0); // do nothing if nothing sent</p><p>int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number</p><p>if (val == 1) { </p><p>Serial.println(&quot;LED on&quot;);</p><p>digitalWrite(ledPin1, HIGH); </p><p>delay(500); </p><p>myservo1.write(180);</p><p>delay(20); </p><p>myservo1.write(0);</p><p>delay(20); </p><p>digitalWrite(ledPin1, LOW);</p><p>}</p><p>else if (val == 2) { </p><p>Serial.println(&quot;LED on&quot;);</p><p>digitalWrite(ledPin2, HIGH); </p><p>delay(500); </p><p>myservo2.write(180);</p><p>delay(20);</p><p>myservo2.write(0);</p><p>delay(20);</p><p>digitalWrite(ledPin2, LOW);</p><p>}</p><p>else if (val == 3) { </p><p>Serial.println(&quot;LED on&quot;);</p><p>digitalWrite(ledPin3, HIGH);</p><p>delay(500); </p><p>myservo3.write(180);</p><p>delay(20);</p><p>myservo3.write(0);</p><p>delay(20);</p><p>digitalWrite(ledPin3, LOW);</p><p>}</p><p>else if (val == 4) {</p><p>Serial.println(&quot;LED on&quot;);</p><p>digitalWrite(ledPin4, HIGH);</p><p>delay(500); </p><p>myservo4.write(180);</p><p>delay(20);</p><p>myservo4.write(0);</p><p>delay(20);</p><p>digitalWrite(ledPin4, LOW);</p><p>}</p><p>else if (val == 5) {</p><p>Serial.println(&quot;LED on&quot;);</p><p>digitalWrite(ledPin5, HIGH);</p><p>delay(500); </p><p>myservo5.write(180);</p><p>delay(20);</p><p>myservo5.write(0);</p><p>delay(20);</p><p>digitalWrite(ledPin5, LOW);</p><p>}else </p><p>{</p><p>//val = val;</p><p>}</p><p>Serial.println(val);</p><p>Serial.flush(); </p><p>}</p>
<p>Hi.. </p><p>how to reduce speed movement the servo?</p><p>i have tried to use delay. but it not success.</p><p>any idea?</p>
<p>Thank you for this tutorial.i successfully running the single servo.</p><p>how to connect the more than four servo to vb +arduino</p>
<p>You could cut the VB code down 1/3 by adding this:</p><p>Sub send(number As String)</p><p> SerialPort1.Open()</p><p> SerialPort1.Write(num)</p><p> SerialPort1.Close()</p><p> End Sub</p><p>call it like this: send(&quot;1&quot;)</p>
<p>here book is available to make some basic cool project with arduino + visual basic 6.0</p><p><a href="http://www.amazon.com/Arduino-Visual-Basic-6-0-software/dp/1511667753" rel="nofollow">http://www.amazon.com/Arduino-Visual-Basic-6-0-software/dp/1511667753</a></p>
<p>Hi i couldnt upload arduino port driver. i'we installed but does not appear in the device manager</p>
<p>Hi,<br>i had tried this with two servos but a problem was found which is the buttons won't work at the same time.<br>any help please?</p>
<p>Hii!, What Visual Basic Do you used in this proyect? </p><p>Because I have a Visual Basic 6 But I can&acute;t see the visual basic code.</p>
<p>Hii!, What Visual Basic Do you used in this proyect? </p><p>Because I have a Visual Basic 6 But I can&acute;t see the visual basic code.</p>
<p>Excellent tutorial. I succeeded in properly running this.</p>
<p>ur stuff is really nice, can u make the vb code for the following video</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/VTTzI3z3jpc" width="500"></iframe></p><p>for my home purpose </p><p>thanx in advance</p>
<p>thanks, but I wish this vid was longer. I'd like an explanation of how VB is interacting with the Arduino, the concept is fascinating. </p>
<p>How to connect VB to Arduino ?</p>
<p>Hi, how can I download the source code for this project?</p><p>The source code link provided does not allow me to download the file.</p><p>Thanks! :)</p>
<p>What's exactly you mean ?</p><p><a href="https://app.box.com/s/2663yu97s9to5i1snw9o" rel="nofollow">https://app.box.com/s/2663yu97s9to5i1snw9o</a></p><p><a href="https://gist.github.com/ruisantos16/4773241" rel="nofollow">https://gist.github.com/ruisantos16/4773241<br><br></a>I've just tried and both links works fine for me :)</p><p>Please try again,</p><p>Rui</p>
<p>Hi thank you for the links. The first one:</p><p><a href="https://app.box.com/s/2663yu97s9to5i1snw9o" rel="nofollow">https://app.box.com/s/2663yu97s9to5i1snw9o</a></p><p>downloads as a internet explorer file which does not allow me to download the code.</p><p>The second one, however, <a href="https://gist.github.com/ruisantos16/4773241" rel="nofollow">https://gist.github.com/ruisantos16/4773241</a></p><p>is good enough, but where's the servo.h file?</p><p>Thanks! :)</p>
<p>Try to download with mozilla or something<br><a href="https://app.box.com/s/2663yu97s9to5i1snw9o" rel="nofollow">https://app.box.com/s/2663yu97s9to5i1snw9o<br><br></a>That file is hosted by box.com. (similar to dropbox, and that folder is shared so anyone can download... try with another browser, because everyone downloaded the code successfully.. :) ).</p><p>the servo.h file is included in the Arduino IDE (1.0+) by default.</p><p>I hope this helps,</p><p>Rui</p>
<p>Hey guy,</p><p>Thank you for all your job, it's really interesting.</p><p>However, I don't really understand some step of the program. For example, why do you differenciate if the angle is under 10 or 100?</p><p>I would like to use your code in order to create a sinusoidal movement, do you think that's possible?</p><p>Thank You,</p><p>BDS29</p>

About This Instructable




Bio: Author, Blogger, Electronics Enthusiast and Entrepreneur. For complete Electronics Projects and Tutorials go to: http://randomnerdtutorials.com/start-here
More by RuiSantos:ESP8266 Web Server (Without Arduino) Arduino Simple Memory Game Arduino – Datalogger with Temperature Sensor and Photoresistor 
Add instructable to: