Click here to Skip to main content
11,795,848 members (82,390 online)
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 0: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 Maciej Los 410
1 Abhinav S 368
2 OriginalGriff 300
3 Sergey Alexandrovich Kryukov 266
4 KrunalRohit 249
0 OriginalGriff 1,852
1 Maciej Los 1,465
2 KrunalRohit 1,300
3 CPallini 840
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web02 | 2.8.151002.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