0

members

Easy Basics: Project 077b Control SG90 Micro Servo Motor with Csharp app

of Acoptex.com in UNO

Basics: Project 077b

Project name: Control SG90 Micro Servo Motor with Csharp app

Tags: Arduino, Arduino Uno, servo, Csharp app, SG90 Micro Servo Motor, C# language, C# app. Visual Studio 2017 Community IDE

Attachments: sketch, servocontrolappcode

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1.Arduino Uno R3 (you can also use the other version of Arduino)

2. Arduino IDE ( you can download it from here  )

3.Jumper cables M-M

4. SG90 Micro Servo Motor 1 pc

5. Capacitor 100 uF 1 pc

6. Visual Studio 2017 Community IDE

General

We will learn how to control SG90 Micro Servo Motor attached to Arduino board with Csharp app.

 

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. 

 

We are normally using the Serial Monitor of the Arduino IDE to communicate with the Arduino board but today we will use a C# app that we’ve created. Basically in the C# app we have 4 buttons which will interact with the Arduino when we press them.

We will show you how to make the C# app that allows the user to rotate a servo attached to the Arduino. 

Important Notes:

 

  1. When you’re using the C# app the Serial monitor on the Arduino IDE must be closed.
  2. You need to match the com port in your C# code to the right com port you have your Arduino board attached.

 

Understanding the servo motor

You can read more about them here.

Signals and connections of the servo motor

Wiring

The following picture shows the needed connections with the Arduino Uno.

Step by Step instruction

1. Installing Visual Studio 2017 Community IDE

  • See how to do it here.

2. Making Csharp app

  1. Once Visual Studio is successfully installed, launch it.
  2. If you are using Windows 10, you can find Visual Studio by typing in the search textbox beside the Start Menu icon - Visual Studio 2017
  3. You will see that the IDE is loading.
  4. After logging in you will see a Start Page.
  5. Make a New project by either following the link on the Start page or from the file menu: File -> New -> Project
  6. You will see the New Project window. Go to the Installed Templates-> Visual C# -> Select template Windows Forms App (.NET Framework). Framework version (for example we have 4.7.2), change the name of your project to RelayControlApp and click on OK button. Please Note that you need to have Net.Framework 4.7.2 installed in your Windows OS.
  7. Visual Studio will create a new project for you. Double-click on Form1.cs in Solution Explorer section. You will see the Form1.cs (Design) tab opened.
  8. Change the Size and Height of the shape by selecting it and going to the Properties in the right bottom corner. You will need to scroll and find Layout->Size, Height and Width.
  9. Go to Properties->Appearance->Change Text from Form1 to Servo Control App.
  10. Go to Properties -> Layout->Start position and change from Windows Default Location to CenterScreen.
  11. Go to Toolbox and find a Server Control called Button. Drag it to shape and drop. Do that 4 times. If the Toolbox is not visible for you, you can make it visible by going to View -> Toolbox
  12. You can move it to other location too. 
  13. Select Button1 and change Text from Button1 to Rotate 90º Left in the Properties. Do the same with other buttons - Button2, Button3, Button4. Change the Text to Rotate 90º Right, Rotate 180º Left, Rotate 180º Right accordingly.
  14. Go to Toolbox and find a Server Control called Label. Drag it to shape and drop. 
  15. Select Label1 and change Text from Label1 to Servo Control APP , Text Align change to MiddleCenter and Font Size from Appearance to 15 in the Properties.

  16. Select Rotate 90º Left button and go to its Properties. Select Lightning icon and change Action Click to btn90L_Click. Do the same for other buttons: Rotate 90º Right button - btn90R_Click, Rotate 180º Left button - btn180L_Click, Rotate 180º Right button - btn180R_Click. 
  17. Congrats!!! Design is done. Let's start with code.
  18. Double-click on Rotate 90º Left button. The Form1.cs file with code opens. 
  19. Press Save all button to save all modifications done.
  20. Open this file in any Editor program (Notepad, Wordpad, MS Word), select and copy all code to Form1.cs. You need to modify PortName, it should be the port where your Arduino Uno attached (you can check it in Arduino IDE: Tools ->Port->Serial Ports
  21. Click on References from Solution Explorer section with right mouse button and select Manage NuGet packages...
  22. We will need to install two packages: System.IO.Ports and System.IO. Go to Browse tab and in Search field enter System.IO.Ports. Select it from the list and click on Install button. Then click on Accept button and the package will be installed. Do the same with System.IO package.
  23. Save all of your work. Click on the Save All icon in the Visual Studio menu or from the menu select File -> Save All. Let’s get the result of all of our work by running the application. Click on the green arrow icon in the Visual Studio menu to run the application.
  24. The compiled exe file saved in:

3. Uploading Sketch

  1. Do wiring.
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port
  4. Open sketch, verify and upload it to your Adruino Uno.

Summary

We learnt how to control SG90 Micro Servo Motor attached to Arduino board with Csharp app.

Libraries:

  • Servo library included in Arduino IDE

Sketch:

  • See attachment on the begining of this project


Other projects of Acoptex.com
Easy Basics: Project 086d ESP-12E module, BME280 sensor - Web server of Acoptex.com in ESP8266 ESP-12 18-07-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 30-10-2018
Viewed: 268 times