Go Down

Topic: trouble sending sensor data to visual basic program (Read 766 times) previous topic - next topic


Ok guys, first post on here so let me know if i am posting in the wrong thread. I have this visual basic program which every half second reads the existing serial data sent by my arduino mega microcontroller. the controller reads 6 motion sensors (soon to be more if i can get this fixed) and sends a character through the usb serial according to which moiton sensor is triggered. the problem is that after a few hours of the arduino sending serial data my visual basic program sends me an error saying that the com port does not exist or is closed, the port which the controller is connected to. i have tried programming my arduino mega several different ways and am fed up with it so here i am. i think (think) the issue is in my mega programming and that it is disconnecting because of the amount of serial print it is doing, the only thing that fixes my problem is unplugging the arduino and plugging it back in the usb port.ill post the code below. thanks in advance! (oh and i know there is un needed code, i am in the process of adding more sensors but hit this speed bump..)

const int motion = 7;
const int motioncabinet = 8;

const int narvin = 5;

const int frontmotion = 10;
const int frontmotion2 = 11;
const int backmotion = 12;
const int backmotion2 = 13;

int val = 0;

const int phase = 0;   

void setup() {
  // set the digital pin as output;

  pinMode(frontmotion, INPUT);
  pinMode(frontmotion2, INPUT);
  pinMode(backmotion, INPUT);
  pinMode(backmotion2, INPUT);

  pinMode(narvin, INPUT);

  pinMode(motion, INPUT);
  pinMode(motioncabinet, INPUT);

void loop()

int narvinnum = 1;
int sensor = digitalRead(motion);
int sensorcabinet = digitalRead(motioncabinet);
int sensorfront = digitalRead(frontmotion);
int sensorfront2 = digitalRead(frontmotion2);
int sensorback = digitalRead(backmotion);
int sensorback2 = digitalRead(backmotion2);
int narvininput = digitalRead(narvin);

String tosend = "a";
String addedsend = "a";
   if (Serial.available()) {
  if(narvininput == HIGH){
    //tosend = addedsend + 'b';
   if(sensor == HIGH){
      //tosend = addedsend + 'g';
   if(sensorcabinet == HIGH){
      //tosend = addedsend + 'i';
   if(sensorfront == HIGH){
      //tosend = addedsend + 'c';
  if(sensorfront2 == HIGH){
      //tosend = addedsend + 'd';
   if(sensorback == HIGH){
      //tosend = addedsend + 'e';
   if(sensorback2 == HIGH){
      //tosend = addedsend + 'f';
   //tosend = ('a');


oh i forgot to add the //then code under each if statement was my previously tried thoughts that did not work.


blame windows ...
if you look up "usb disconnecting" you see a raft of issues

looks like the "power down scheme" is the thing to blame

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131