Thanks for taking the time to answer me ![]()
Think I'm nearly there now, just have to re-read your posts and do some more research.
No errors now, but it still wont read values to the text boxes.. Probably some easy fix..
I'll just post my codes as they are atm. Dont want to be the guy that comes with stupid questions, soon I'll be the one answering other people in trouble ![]()
Arduino code:
#define soilSensor1 A0
#define soilSensor2 A1
#define pump1 2
#define pump2 3
const int dry = 534;
const int wet = 297;
const int dry1 = 534;
const int wet1 = 297;
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);
}
VB code:
Public Class Form1
' set up delegate to display data received from serial port
Private Delegate Sub myDelegate(ByVal Buffer As String)
' character received from serial port
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
SerialPort1.ReadTimeout = 1000
Dim sData As String = Nothing
Try
sData = SerialPort1.ReadLine
Catch ex As Exception
End Try
Me.BeginInvoke((New myDelegate(AddressOf DisplayData)), sData)
End Sub
' delegate to display string received
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
' on form load open serial port
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SerialPort1.Open()
End Sub
Private Sub Form1_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
SerialPort1.Close()
End Sub
End Class
Thanks again!

