Need help with code for sending sensor data to software through serial com

Hi,

I'm using a PIR sensor as input through an Arduino which will be 'listened to' by VPT (video projection tool). I need to send it a control number and value through the serial port. I've included the code I have below.

I'm not sure whether I need the analog input if i'm using a digital sensor? Although it's saying pin 0 in the code which recieves information (rx), I'm not sure of the function of this in my sketch, does anyone have an idea?

If I just try to use the code as is with the PIR sensor and Arduino I'm getting this message: avrdude: stk500_getsync(): not in sync: resp=0x30

Also, there is the code for picking up input from a PIR sensor but that just turns up in the serial port 'HIGH' or 'LOW', VPT needs a control number and value number, basically, I'm having trouble altering this code to work with a PIR sensor, and if anyone can help me that would be amazing because I have to have this ready for Tuesday..

I have this code for sending information to VPT:

int inputPin1 = 0; //analoginput range 0-1024 int inputPin2 = 7; //digital input int id = -1; //the two bytes from the incoming data from VPT int data;

void setup() { pinMode(inputPin2, INPUT); //configure digital pin as input Serial.begin(9600); delay(100); Serial.flush(); delay(1000); Serial.println(-1,DEC); }

void loop() { if (Serial.available() > 1) { // get incoming byte, do nothing // we are ignoring the incoming bytes, they are used to sample data from arduino id = Serial.read(); data = Serial.read(); if(id==0) { Serial.print("1 "); Serial.println(analogRead(inputPin1)); //"1 value_input1" sent to VPT

Serial.print("2 "); Serial.println(digitalRead(inputPin2)); //"2 value_input1" sent to VPT delay(100); //delay before reading the inputs again } id=-1; }

}

Here is an outline of what I think you need.

setup and initialise variables, pins and serial output

start of loop
  read the PIR
  if PIR is active
    send codeA to VPT via serial
  end of if
  else
    send codeB to VPT
  end of else
end of loop

Does that match what you need ? In practice codeA and codeB will probably be a series of bytes. Do you have details of the codes required and their format ? Will there be any feedback from the VPT ? Does the PIR output a digital (on/off) signal or an analogue (changing voltage) signal ? Is this the first program that you have tried on the Arduino or have you tried some the the examples ?

Although it's saying pin 0 in the code which recieves information (rx),

Take another look at your board. There are pins on both sides. One of the pins is a digital-only pin, numbered 0 or RX.

The other is an analog pin, numbered 0, that can also be used as a digital pin (using A0 as the identifier).

Do not confuse the two, as you are doing.

Hi,

I don't think there is any feedback from VPT, it's just listening to what comes through on the serial port. It needs to pick up a control number and a value number between 0 and 1. So receiving the numbers only when the PIR is active. The PIR is a digital signal and on the code I've looked at comes through as HIGH when active.. I've tried the examples and they don't provide the control and value bytes I need. I'm unsure of how to write this..

This is the code that VPT provides, so I need to format this to work with the PIR sensor I have, I've looked at both the code for PIR sensors on Arduino and this, but can't seem to figure a way of using bits of them together to get what I need.

int inputPin1 = 7; //digital input int id = -1; //the two bytes from the incoming data from VPT int data;

void setup() { pinMode(inputPin1, INPUT); //configure digital pin as input Serial.begin(9600); delay(100); Serial.flush(); delay(1000); Serial.println(-1,DEC); }

void loop() { if (Serial.available() > 1) { // get incoming byte, do nothing // we are ignoring the incoming bytes, they are used to sample data from arduino id = Serial.read(); data = Serial.read(); if(id==0) { Serial.print("1 "); Serial.println(digitalRead(inputPin1)); //"1 value_input1" sent to VPT delay(100); //delay before reading the inputs again } id=-1; }

}

I'm new to this but have tried the examples, It's just adapting the code where i'm having problems,

Thanks for your reply

Looking at the code you provided it sends -1 to the VPT as part of its setup then reads 2 bytes of data from the VPT which the comments say are ignored, whereas they are tested to see if the first one is Q which won't work because Q is neither a byte nor a char. Pin 7 is read and its value (HIGH or LOW) is sent to the VPT. What is that all about ?

What is the code supposed to do ? What is this mysterious VPT device that you need to communicate with ?

On the face of it there will be no problem sending data to the VPT when the PIR is activated but what codes need to be sent when the PIR is on and off ?

Have you written any code to use the PIR such as turning on an LED when it is triggered and turning it off when it is not ?

At a minimum, you need to get the VPT device off of the hardware serial port. Use SoftwareSerial to talk to it. Use the hardware serial instance to talk to the Serial Monitor.

My guess is that the VPT thing expects binary data, not strings.