Hi Robtillaart,
I've tested all the UNOs with the blink sketch all work as they should.
Hesr is my Arduino code and I have included my Processing code as the sketch outputs a sound in Processing. All of this works perfectly with the ATMEGA 328
Link to motion sensor/////http://www.skpang.co.uk/catalog/pir-motion-sensor-p-796.html
Many thanks for your attention. Frank
Arduino
/*
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 AllahuAkbarAdan;
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);
AllahuAkbarAdan = minim.loadFile ("AllahuAkbarAdan.mp3");
AllahuAkbarAdan. loop();
AllahuAkbarAdan.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){
AllahuAkbarAdan.unmute();
}else{
AllahuAkbarAdan.mute();
}
soundSwitch = !soundSwitch;
}
}
previousInByte = inByte;
}
}
void drawTestingMINIM(){
float currentms = millis() - startms;
if (currentms > 2000){
val = !val;
if (val == true){
AllahuAkbarAdan.unmute();
}else{
AllahuAkbarAdan.mute();
}
startms = millis();
}
}