Hi, I am doing a project using Arduino and Processing. I am running Duemilanove ATMEGA 328 with a PIR sensor to capture motion which the triggers sound in Processing. This works perfectly and now to develop the project I bought another 4 Arduino UNOs - an upgrade to the Duemilanove. i'm using the same sensors, wiring and all other conditions are identical and it doesn't work. The sensor reading with the UNOs is erratic and of no use for my purpose. I was advised to use a capacitor between 5v and grnd and use a battery to power Arduino, all of this helps but it is still erratic. I have enclosed my Arduino and Processing codes as well as a picture of my set up. Are you able to offer any advice?
many thanks,
Frank
Arduino//
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
float startms = millis();
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
digitalWrite(ledPin, 0);
}
void loopTEST(){
float currentms = millis() - startms;
if (currentms > 500){
val = !val;
digitalWrite(ledPin, val);
startms = millis();
}
}
void loop(){
delay(100);
val = digitalRead(inputPin); // read input value
digitalWrite(ledPin, val); // turn LED ON or OFF
// Serial.print(val) BUT SEE BELOW. DON'T UNCOMMENT!!!!
if (val == 1){
Serial.print(1, BYTE); // There is a potential reason for this verbose version:--
}else{
Serial.print(0, BYTE);
}
}
Processing//
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
//name it
Minim minim;
//Name the track
AudioPlayer StartOfMass6BellsFirst;
boolean flag = false;
//Processing:
import processing.serial.*;
Serial port;
String inputString;
float inputConvertedToFloat;
float minimumDelayUntilStasis = 1000;
float startOfMillisecondCount = millis();
float startms = millis();
boolean val = false;
boolean hasTimedOut = false;
boolean soundSwitch = true;
int previousInByte = 1; // 1 means NOT moving
void setup(){
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600); // [0] may have to change
frameRate(200);
///////////////
minim = new Minim (this);
StartOfMass6BellsFirst = minim.loadFile ("Start of mass 6 bells first.mp3");
StartOfMass6BellsFirst. loop();
StartOfMass6BellsFirst.mute();
/////////////////////
}
void draw() {
//lully.setVolume(0.00001);
if (port.available() > 0) {
int inByte = port.readChar(); // N.B. Oddly, a zero reading means there IS motion
print(inByte);
if (inByte == 0){
if (previousInByte == 1){
print("change to zero");
if (soundSwitch == true){
StartOfMass6BellsFirst.unmute();
}else{
StartOfMass6BellsFirst.mute();
}
soundSwitch = !soundSwitch;
}
}
previousInByte = inByte;
}
}
void drawTestingMINIM(){
float currentms = millis() - startms;
if (currentms > 2000){
val = !val;
if (val == true){
StartOfMass6BellsFirst.unmute();
}else{
StartOfMass6BellsFirst.mute();
}
startms = millis();
}
}