Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB VB10.0 Arduino
hello guys.. i wondering is there any wrong with my code since i try to run it just now and noting happen
code of arduino
const int threhold = 100;
int sensorReading;
int irs=0;
void setup()
 pinMode(irs, INPUT);
void loop()
  sensorReading = analogRead(irs);
  if(sensorReading > threhold)
code of vb
Imports System.IO
Imports System.IO.Ports
Dim val As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Encoding = System.Text.Encoding.Default
        val = SerialPort1.ReadLine
        If val = 0 Then
            PictureBox1.Image = My.Resources.Button_Blank_Red_icon__1_
        ElseIf val = 1 Then
            PictureBox1.Image = My.Resources.Button_Blank_Green_icon_2
        End If
    End Sub
Posted 18-Jun-13 1:00am
ThePhantomUpvoter at 18-Jun-13 8:13am
Try sending a newline from the arduino side since that is what the serial port ReadLine is waiting for,
arnoldxx at 19-Jun-13 5:53am
can u gime an example bro.. sorry i m still new in this progress.. might need some help from you guys.. thanks..

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are sending (Arduino side) string values and checking (on VB side) for integer values. Instead you should either:
  • send integer values (e.g. Serial.Write(1)) and check for integer values.
  • send string values and check for string values (e.g. if str = "0" ).
arnoldxx at 18-Jun-13 6:57am
ty for the feedback..
i have follow the step that u show it to me by changing the if val = 0 to if val = "0"
but it still won't work to me..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 424
1 OriginalGriff 375
2 CHill60 230
3 CPallini 220
4 Maciej Los 210
0 Sascha Lefévre 75
1 OriginalGriff 70
2 F-ES Sitecore 55
3 Peter Leow 50
4 Dave Kreskowiak 40

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 18 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100