element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Problem with Arduino UNO
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 8 replies
  • Subscribers 401 subscribers
  • Views 618 views
  • Users 0 members are here
  • processing
  • detection
  • motion
  • arduino
Related

Problem with Arduino UNO

Former Member
Former Member over 14 years ago

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();

}

}

/*
* 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);
    }
}

Attachments:
Archive.zip
  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 14 years ago

    Hi Frank,  As I look at your photos, I do not see a connection to analog in 2 but instead to digital pin 2.

    Best Regards,

    Lee

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Lee,

    the sensor is supposed to be attached to a digital pin.

     

    Best,

     

    Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Frank,

    I have no clue how I thought that an analog pin was involved, tired perhaps.

    Debug time –

    • Does another Uno show the same erratic response?
    • Does moving the input to another pin make a difference?
    • Do you have another way of monitoring the PIR signal, scope or meter ?
    • If you connect both the Uno and Duemilanove to receive the PIR signal do they show the same response – insure that both are powered by the same supply so supply current from one is not flowing into the other.

     

    Since I don't know the actual behavior, the following may work but doesn't isolate the fault.  We use the following to eliminate responding to relay chatter.  At each change of state of the PIR wait a fixed delay and check the state again, if it is the same state assume it is stable and use that value.  If not delay again until you get the same states.

     

    This delay and check could be extended to a fixed number of samples with delays between and only when all samples come back with the same state do you assume it is stable.

     

    Best regards,

    Lee

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Frank,

    I have no clue how I thought that an analog pin was involved, tired perhaps.

    Debug time –

    • Does another Uno show the same erratic response?
    • Does moving the input to another pin make a difference?
    • Do you have another way of monitoring the PIR signal, scope or meter ?
    • If you connect both the Uno and Duemilanove to receive the PIR signal do they show the same response – insure that both are powered by the same supply so supply current from one is not flowing into the other.

     

    Since I don't know the actual behavior, the following may work but doesn't isolate the fault.  We use the following to eliminate responding to relay chatter.  At each change of state of the PIR wait a fixed delay and check the state again, if it is the same state assume it is stable and use that value.  If not delay again until you get the same states.

     

    This delay and check could be extended to a fixed number of samples with delays between and only when all samples come back with the same state do you assume it is stable.

     

    Best regards,

    Lee

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Lee,

    thanks for your response, I bought 3 Unos and all respond in the same way.

    Being rather a newbie to Arduino and Processing I understand what you mean

    re. delay but have no idea how to write that into my code. Could you do a

    sample for me to follow?

     

    Many thanks,

     

    Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Frank,

    Since you already have a delay of 100 milliseconds,  I added two variables and then an if statement after the readDigital statement.  After a change in PIR value the loop will run one additional time to  verify that the same PIR value has been seen twice.  I don't like not knowing what the cause of the erratic response is but this may help.  Question for the group: has anyone seen different pin charactistics between the Uno and Duemilanove?

    Regards,

    Lee

     

     

    /*
    * 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 = LOW;   // variable for reading the pin status
    int waitDelay = 10;  // delay, milliseconds, modify as necessary
    int lastVal = LOW;  // for comparison
    int setVal = LOW; // changes only when val and lastVal match twice
    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
      /* If val and lastVal match, fall through the if statement.
         If not, set the lastVal to this changed value but put val
         back to previous state before 'chatter' started and go though
         loop until val and lastVal match.
       */
      if( val != lastVal )
      {
        lastVal = val;
        val = setVal
      }
      setVal = val;  // this is set each time which is redundant if
      //  the PIR did not change.
      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);
        }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Lee,

    thanks for this I'll have a go in the morning when I'm back in my studio.

    I'll let you know how it goes, and I'm interested to hear the response  from

    any others  who may have had similar issues.

     

    Best,

     

    Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Lee,

    Frank here again,

    I'm glad to say that using your advice and spending hours altering the delay

    in both Arduino and Processing and changing the Baud rate I hit on the right

    combination and all of my boards now work in the way I need them to.

    Many thanks for your help and suggestions. I can post my codes here if you

    like.

     

    With best wishes,

     

    Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to Former Member

    Hi Frank,  It's great that you have everything working as you want.  I am interested in what you discovered in finding the solution.  Others may be converting from Duemilanove to Uno based projects and what you found may help them as well.

    Best regards,

    Lee

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube