Introduction: CONTROLLING DC WITH VISUAL BASIC

in this instructables where I will try to bring more Novelty des often.

Today theme is with Arduino and Visual Basic. The project that we see today is controller one dc motor with Arduino and Visual Basic. To control a dc motor is not enough voltage of 5 v arduino I used a BC547C NPN transistor because as you know allows us to control a great power with a small.

Step 1: HARDWARE REQUIRED:-

Materials:

  • · A one Arduino ·
  • A DC motor ·
  • An NPN transistor BC547C ·
  • Cables to connect ·
  • A breadboard ·
  • A resistor of 220 ohms

Step 2: CONSTRUCTION:-

I did not put resistance to connect the pin of arduino to the base of transistor because the values of the resistors that I have not allowed to circulate much voltage the motor you need in my case a lot of power so I tried without resistance and works but recommend the use of a 220 ohm resistor.

transistor connection:-

  • emmiter to ground
  • collector to motor and from motor to D2
  • base to 5V

Step 3: CODING:-

Public Class Motor_Control

'Here we make declaration of the variables that we use 'Variable "Conectado" allows us to know the status of conection Dim Conectado As Boolean 'The variable "valor" will be the one that receives the value that we will send to Arduino

Dim value As String 'At Close "Motor_Control" form also close the serial port "SPort" Private Sub Motor_Control_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed SPort.Close() End Sub

'When loading the form we disable the "ON" button and "OFF"

Private Sub Motor_Control_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load CmdON.Enabled = False CmdOFF.Enabled = False End Sub

'The button "Connect" allows us to connect the PC to the Arduino after select serial port in the Combobox "cmbSerialPorts"

CmdConectar_Click Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConectar.Click 'If there is no conection If Conectado = False Then

'Load the combobox with the PC serial ports For Each PuertosDisponibles As String In My.Computer.Ports.SerialPortNames cmbSerialPorts.Items.Add (PuertosDisponibles) Next

'If anything in Combobox list If cmbSerialPorts.Items.Count> 0 Then 'Change the combobox text cmbSerialPorts.Text = cmbSerialPorts.Items (0) 'Change the value of the name of the serial port to selected value in combobox list SPort.PortName = cmbSerialPorts.Text 'Open the serial port SPort.Open () 'And activate the "ON" button "OFF" CmdON.Enabled = True CmdOFF.Enabled = True 'We disabled the button "Connectar" cmdConectar.Enabled = False MsgBox ("CONECTADO") 'The variable "Conectado" is true "Conectado" = True else 'If no ports show a message MsgBox ("NO PORT FOUND") End If Else 'At the end we close the port SPort.Close () MsgBox ("DISCONECTED") Conectado = False End If End Sub

Private Sub CmdON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdON.Click 'If there conection If Conectado = True Then 'The variable "value" have the value "1" to activate the motor value = "1" 'Send the value to the port SPort.Write (value) 'Discards data from the serial port transmit buffer SPort.DiscardOutBuffer () End If End Sub

CmdOFF_Click Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOFF.Click If Conectado = True Then 'The variable "value" have the value "0" to desactivate the motor value = "0" SPort.Write (value) SPort.DiscardOutBuffer () End If End Sub