Click here to Skip to main content
Rate this: bad
good
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);
Serial.begin(9600);
}
void loop()
{
  sensorReading = analogRead(irs);
  if(sensorReading > threhold)
  {
   Serial.write("1");
  }
  else
  {
   Serial.write("0");
  }
  delay(100);
}
 
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
        SerialPort1.Open()
        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
Comments
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
good
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.
or
  • send string values and check for string values (e.g. if str = "0" ).
  Permalink  
Comments
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)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 18 Jun 2013
Copyright © CodeProject, 1999-2014
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