In a plant requires a control to detect how altitude and how the volume of a materials that is in a certain area.
For example in a tube filled with fluid material, wherein the liquid used in a particular process so that the fluid can not be empty, so that the process can continue.
Let’s find out how it’s work….
here is the arduino and vb code
#include ;
int valve1=12;
int valve2=11;
LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
int volume1=900;
int sensorMin = 100; // minimum sensor value
int sensorMax = 900;
void setup()
{
Serial.begin(9600);
pinMode(valve1,OUTPUT);
pinMode(valve2,OUTPUT);
lcd.begin(16, 2);
}
void loop()
{
//int analogValue1 = analogRead(0);
if(Serial.available())
{
int terimadata=Serial.read();
if (terimadata==’a’)
{
digitalWrite(valve1,HIGH);
digitalWrite(valve2,LOW);
}
if (terimadata==’b’)
{
digitalWrite(valve1,LOW);
digitalWrite(valve2,HIGH);
}
}
analogReference(EXTERNAL);
int analogValue = (analogRead(0));
if (analogValue > sensorMax) {
analogValue = sensorMax;
}
if (analogValue < sensorMin) {
analogValue = sensorMin;
}
Serial.print(analogValue);//+78);
lcd.setCursor(0, 0);
lcd.print(“Volume = “);
lcd.print(volume1 – analogValue);
lcd.setCursor(0, 1);
lcd.print(“level = “);
lcd.print(analogValue);
delay(100);
}
===========================================================================================================
Private Sub Form_Load()
‘Slider1.Max = 500
Slider1.Max = 900
Slider1.Min = 100
Slider1.TickFrequency = 20
Slider1.LargeChange = 20
MSComm1.RThreshold = 4
MSComm1.InputLen = 3
MSComm1.Settings = “9600,n,8,1”
MSComm1.CommPort = 6
MSComm1.PortOpen = True
MSComm1.DTREnable = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
Dim hasil As Integer
Dim DataIn As String
Dim nilai As Integer
If MSComm1.CommEvent = comEvReceive Then
DataIn = MSComm1.Input
Level = Str(Mid$(DataIn, 1, 4))
hasil = Level
If hasil > 690 Then
Image5.Visible = True
Image1.Visible = False
logic_out = “a”
MSComm1.Output = logic_out
End If
If hasil <= 250 Then
Image5.Visible = False
Image1.Visible = True
logic_out = “b”
MSComm1.Output = logic_out
End If
Label6.Caption = hasil
Text1.Text = hasil
Text2.Text = 900 – hasil
Slider1.Value = hasil
End If
End Sub
you can copy paste this code and try how it’s work