Go Down

Topic: Arduino uses at work (Read 865 times) previous topic - next topic

Jeremy Jackson


Here is a simple project that incorporate communication between the Arduino and vb.net.  I use another Arduino at my work to control a couple of valves and to read a pressure.  This project will break 120VAC power to a hi-pot tester, which will allow the operator to only use the equipment when other conditions are met.

Anyways, here is the Arduino code, vb.net code, and wiring diagram:
// programmer: Jeremy Jackson
// company:    WaterFurnace Intl
// date:       23 FEB 10
// program:    HiPotOnOff
// purpose:    Interface between hi-pot power supply and Line Scanner Software.
//             This program will enable and disable the hi-pot 120VAC power
// notes:      Pin 0 and 1 used for USB commo to computer
//             Pins 2 for digital output

int HiPotPowerControl = 2;                 //Crydom CMD2425 SSR used to turn 120VAC on and off
char incomingByte;                         //Var to store commo between Arduino and Computer

void setup()
pinMode(HiPotPowerControl, OUTPUT);       //set to output mode
digitalWrite(HiPotPowerControl,LOW);      //set initial output state to Low or OFF
Serial.begin(9600);                       //start serial commo

void loop()
   if (Serial.available() > 0)
       // read the incoming byte from Line Scanner:
       incomingByte = Serial.read();
       switch (incomingByte)
            case 'F':// turn off output
              digitalWrite(HiPotPowerControl, LOW);
            case 'O'://  turn on output
              digitalWrite(HiPotPowerControl, HIGH);
            case 'S'://  get status of output
                  Serial.println("STATUS ->> Power Off");
                  Serial.println("STATUS ->> Power On");

  'vb.net test code for communicating between Arduino and vb.net program:
  '                   !!!vb project setup instructions!!!
  '                   drop a timer, serial port, two buttons, two picture objects, and a text box
  '                   onto a blank form.  Rename form1 to frmArduinoComTest, and rename
  '                   one picture box to "indOn" and the other to "indOff"
  '                   Change the text property of button1  to "Turn On" and the
  '                   text property of button2 to "Turn Off"
  '                   Finally, past the code below into the project!
Public Class frmArduinoComTest
 Dim data As String 'hold serial data from Arduino

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   If SerialPort1.IsOpen = False Then SerialPort1.Open() 'if port is closed then open it
 End Sub

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
   SerialPort1.WriteLine("S") 'ask for status of output
   TextBox1.Text = data 'display serial data in textbox
 End Sub

 Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
   Dim strLen As Integer
   'depending on what you are doing, the 250
   'millisecond delay may need adjusted, for this
   'example, the timer was set to run every
   '750 milliseconds, giving a screen
   'update once a second
   'the only thing the Arduino will output
   'is "STATUS ->> Power Off"
   'or "STATUS ->> Power On"
   data = SerialPort1.ReadExisting
   If data <> "" Then 'check to make sure something is there
     strLen = Len(data) 'get length of data string
     data = Mid(data, 1, strLen - 2) 'remove 2 carriage returns from the end of the string
   End If
   If InStr(data, "On") Then 'indOn is "on indicator" and indOff is "off indicator"
     indOn.BackColor = Color.Green
     indOff.BackColor = Color.Red
     indOn.BackColor = Color.Red
     indOff.BackColor = Color.Green
   End If
 End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   SerialPort1.WriteLine("O") 'turn on output
 End Sub

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
   SerialPort1.WriteLine("F") 'turn off output
 End Sub
End Class


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131