Not shure exactly what i did to get it working, but think the problem was that i forgot to add
Imports System.IO.Ports
This is my working VB code:
Imports System.IO.Ports
Public Class Form1
Private Delegate Sub myDelegate(ByVal Buffer As String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
SerialPort1.Open()
End Sub
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
SerialPort1.ReadTimeout = 50
Dim sData As String = Nothing
Try
sData = SerialPort1.ReadLine
Catch ex As Exception
End Try
Me.BeginInvoke((New myDelegate(AddressOf DisplayData)), sData)
End Sub
Private Sub DisplayData(ByVal sdata As String)
Dim txtarray As String() = Split(sdata, ",")
If txtarray.Count = 2 Then
If txtarray(0) = "Sensor1" Then
TextBox1.Text = "Sensor 1 value=" & txtarray(1) & " %"
End If
If txtarray(0) = "Sensor2" Then
TextBox2.Text = "Sensor 2 value=" & txtarray(1) & " %"
End If
End If
End Sub
End Class
And this is my working Arduino code:
#define soilSensor1 A0
#define soilSensor2 A1
#define pump1 2
#define pump2 3
const int dry = 558;
const int wet = 290;
const int dry1 = 562;
const int wet1 = 310;
int percentageHumididy;
int percentageHumididy2;
const unsigned long Seconds = 1000;
const unsigned long Minutes = 60 * Seconds;
unsigned long PreviousMillis = 0;
void setup() {
pinMode(pump1, OUTPUT);
pinMode(pump2, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int sensorVal1 = analogRead(soilSensor1);
int percentageHumididy = map(sensorVal1, wet, dry, 100, 0)
;Serial.print("Sensor1,");
Serial.println(percentageHumididy);
int sensorVal2 = analogRead(soilSensor2);
int percentageHumididy2 = map(sensorVal2, wet1, dry1, 100, 0)
;Serial.print("Sensor2,");
Serial.println(percentageHumididy2);
{
if (millis() - PreviousMillis >= 1 * Minutes)
{
PreviousMillis += 1 * Minutes;
if (sensorVal1 > 380 )
{
digitalWrite(pump1, HIGH);
delay(10000);
digitalWrite(pump1, LOW);
}
}
}
{
if (millis() - PreviousMillis >= 1 * Minutes)
{
PreviousMillis += 1 * Minutes;
if (sensorVal2 > 380 )
{
digitalWrite(pump2, HIGH);
delay(10000);
digitalWrite(pump2, LOW);
}
}
}
delay(1000);
}
I allready got some projects with "buttons to open and close" "baud-rates" and "available COM ports", so I'll take a look at that..
I would like to get it to work with "circular_progress_bar" and maybe a chart of some kind, so if you could tell me where to start, please do ![]()
Fonts and other stuff i will manage myself ![]()