Go Down

Topic: Interactive Art Object Using Arduino+PIR sensors, hardware and code questions (Read 4582 times) previous topic - next topic

Terry King

Quote
Last question so far: Do you know how to incorporate the PIR sensor? Do I need a sensor shield? (i'm working with 5 PIR sensors, each has to work seperately from the others)


I just used one of those today for writing up in my Arduino-Info Wiki (http://arduino-info.wikispaces.com/)

Take a look here and you will see how I connected them:

See the discussion here: http://arduino-info.wikispaces.com/Brick-Pushbuttons%26OtherSwitches#Motion

A  Sensor Shield http://arduino-info.wikispaces.com/SensorShield just makes it easy to connect lots of different things to Arduino without the wiring getting out of control..  With cables that plug in etc.. like on this page: http://arduino-info.wikispaces.com/BrickStarterSet


Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

doerack

Terry the links are great, i can work with that!

I will be able to hooking up the different components with the info on the website. First ordering some stuff (i would like to order from your website, but would be sending to the Netherlans be a problem, or get really expensive? I have recieved more electronic components from China, they posted the package as a "gift-package", is that an idea?)

Then hooking it up, en try my luck with the programming. The more i read the more enthousiatic i become of this little arduino board. The options are really limitless! wooohooo!

Terry King

#17
May 28, 2011, 06:50 am Last Edit: May 28, 2011, 07:03 am by Terry King Reason: 1
Hi Mark,

Shipping to Nederlands is not a problem -- the Shipping part.

Nederlands Customs is a problem.. I try to make the value not too high, but Nederlands sometimes charges Customs duty even on the shipping cost!  I would try to mark the shipping cost on the outside of the package so they don't charge the Max.  Let's email offline on business stuff..  But if you have a good low-cost supplier inside Nederlands, I'm sad to say that might be the best option.

About Starter Sets: It depends on if you are comfortable with wiring things up on a breadboard like these: http://yourduino.com/Breadboard-Wire-Parts.htm  but the easy way with lots of different input and output devices you can quickly hook up is an Electronic Brick set like these:
http://arduino-info.wikispaces.com/BrickStarterSet
Click on the image of any device to see more about it, and example software sketches...

Let us know how we can help...  you have a cool project in mind there!


DISCLAIMER: I mentioned stuff from my own Shop...
Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

doerack

Alright

I've been reading allot, and just trying to hook the diffent parts together, i'm really a newbie, trying to read and understand the different components en how they need to be wired.

What do i want?
I need to stop, run and reverse DC Wiper motors  (start current 2ah, drive current 6 ah). To control the motor i want to use a 2-channel relay for the up/down motion.

I'm using the sensor shield.

* Run motor, use 1 channel of the relay.
* Reverse motor, the other channel of the relay. (switching the + and - cable makes the motor turn in reverse)
* Stopping will be done by limit switches (or just use arduino to control the stopping, dont know if that it possible.)

I created an schematic in paint, am i going in the right direction here?


Thanks!


Terry King

Hi,

The sensor looks right.

I think the motor is a little confused.  The Motor has basically 2 terminals you are going to use, right? "GND" and (Pick one of "FAST" or "SLOW"??)..  so you need to be able to reverse the connections to BOTH terminals. I would draw it like this:


Tell us if this makes sense??

--- 1 Relay makes it run one way, other relay makes it run the other way. NO or BOTH relays is stop....
Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

doerack

Terry thanks for the schematic
I'm using 2 terminals of the motor GND and FAST.

It took me a little while, but i think it does make sense now.  Because i cannot read circuit schematics correctly, i always like to make my own visual image that makes sensce to me (that's what art-school makes you do haha).

Yet another drawings! I think i got it right this time :smiley-red:. Please tell me if i'm wrong  :).

The sensor is ok now, did i connect the relay correctly? I doubt the IN1 and IN2 connection from the relays to the sensorshield.
Link to image: https://lh6.googleusercontent.com/-ySggLwiAzz4/TeK_ABrHjWI/AAAAAAAABoc/ejuE8HezAJg/Wire%2525202.jpg

This is the second one, did I connect motor relay,s switches and battery correctly?
Link to image: https://lh6.googleusercontent.com/-0zAto-aLUys/TeK_d04gERI/AAAAAAAABog/KCEVEh_4zec/s912/Motor%25252C%252520relays%25252C%252520battery.jpg

If i get this right i can start to think about programming, a whole different challenge!






doerack

Alright, i had a little bit of time today so i started to think about writing the code for my art project. I've been reading starterguides and tried to come up with a simple code to control my arduino using a 2-channel relay (hooked up to a dc motor) and a PIR-sensor. It's all really difficult for me, but yopu have to start somewhere. Of course a have a few questions:

In the post before this one, i was working with the different handware components.
Can anyone cofirm i did hook up the different parts correctly?

Before i post my code, i thought that it would be a smart idea to visualize my art project to make it more understandable:
Link to larger image: https://lh6.googleusercontent.com/-oN7VznzigN8/TeUurotmrNI/AAAAAAAABo0/L4zJ6au0pEU/s1440/Artwork%252520sequence%252520%252520finished.jpg



This is the first code i've ever written, go easy on me  :* Am i going in the right direction here?

/*
* PIR sensor tester
*/
Code: [Select]
int inputPin = 13;                // choose the input pin (for PIR sensor)
int r1Pin = 12;                   // choose the pin for the relay-channel 1 (up)
int r2Pin = 11;                   // choose the pin for the relay-channel 2 (down)
int pirState = LOW;               // we start, assuming no motion detected
int val = 0;                     // variable for reading the pin status


void setup()                    // SETUP:runs once
{
  pinMode(inputPin, INPUT);     // declare PIR-sensor as input
  pinMode(r1Pin, OUTPUT);      // declare RELAY-channel 1 as output
  pinMode(r2Pin, OUTPUT);      // declare RELAY-channel 2 as output

  Serial.begin(9600);
}

void loop()
{
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(r1Pin, HIGH);  // turn relay-1 (up) ON
    delay(5000);                 // for 5 seconds
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(r2Pin, HIGH); // turn relay-2 (down) ON
    delay(5000);              // for 5 seconds
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}






doerack

After a long and hectic time, i'm starting again with the project. Still need to order some parts, but i'm having correspondance about it. Ik would like to ask someone to check out my code, it woul be a great help!

Greetings an overexited art student from the netherlands.

Mark


doerack

Alright, after I got the parts, i started to experimate some with teh arduino and pir sensors.

The first sketch for 1 pir 1 two-channel relay and 1 motor worked, now i'm trying to get more parts working. Eventually  5 pairs of pir sensor, relay and motor have to work independantly.
The sketch below is based on 2 pir sensors, 2 two channel relays which drive two motors.

The problems:
* I would like to get more pairs (pir, relay and motor) working separetely from each other. One pair worked fine, when i added another, it skipped some of the code. ( it goes from motion detected pir 1 to motion ended pir 2, skipping the 'else' part from pair pir1+relay1, and skipping the if part from pir2+relay2
* I would like to get the pir's working separately, at the moment if one pir is activated the other cannot be activated.

This is my code so far:

Code: [Select]
/*
* PIR sensor tester
*/

int PIR1 = A0;                // choose the input pin (for PIR sensor 1)
int PIR2 = A1;                // choose the input pin (for PIR sensor 2)
int r1Pin = 2;                   // choose the pin for the relay1-channel 1 (up)
int r2Pin = 3;                   // choose the pin for the relay1-channel 2 (down)
int r3Pin = 4;                   // choose the pin for the relay2-channel 1 (up)
int r4Pin = 5;                   // choose the pin for the relay2-channel 2 (down)
int pirState = LOW;               // we start, assuming no motion detected
int val = 0;                     // variable for reading the pin status

void setup()                    // SETUP:runs once
{
 Serial.begin(9600);
 // PIR
 pinMode(PIR1, INPUT);     // declare PIR-sensor1 as input
 pinMode(PIR2, INPUT);      // declare PIR-sensor2 as input
 // RELAY 1
 pinMode(r1Pin, OUTPUT);      
 digitalWrite(r1Pin, LOW);       // switch off by default
 pinMode(r2Pin, OUTPUT);
 digitalWrite(r2Pin, LOW);       //  switch off by default
 
// RELAY 2
 pinMode(r3Pin, OUTPUT);
 digitalWrite(r3Pin, LOW);       //  switch off by default
 pinMode(r4Pin, OUTPUT);
 digitalWrite(r4Pin, LOW);       //  switch off by default
}


void loop()
{
 // PIR-1+RELAY-1
val = analogRead(PIR1);  // read input value
  if (val > 500)
 {
   if (pirState == LOW)
   {
     // FEEDBACK
     Serial.println("Motion detected pir 1!");

     // UP
     digitalWrite(r1Pin, HIGH);  // turn relay-1 (up) ON
     delay(5000);                     // for 5 seconds
     digitalWrite(r1Pin, LOW);   // turn relay-1 (up) OFF    
     // NEW STATE
     pirState = HIGH;
   }
 } else {
   if (pirState == HIGH){
     // FEEDBACK
     Serial.println("Motion ended pir 1!");

     // DOWN
     digitalWrite(r2Pin, HIGH); // turn relay-2 (down) ON
     delay(5000);                   // for 5 seconds
     digitalWrite(r2Pin, LOW); // turn relay-2 (down) OFF

     // NEW STATE
     pirState = LOW;
   }
 }
// PIR-2+RELAY-2
val = analogRead(PIR2);  // read input value
  if (val > 500)
 {
   if (pirState == LOW)
   {
     // FEEDBACK
     Serial.println("Motion detected pir 2!");

     // UP
     digitalWrite(r3Pin, HIGH);  // turn relay-1 (up) ON
     delay(5000);                     // for 5 seconds
     digitalWrite(r3Pin, LOW);   // turn relay-1 (up) OFF    
     // NEW STATE
     pirState = HIGH;
   }
 } else {
   if (pirState == HIGH){
     // FEEDBACK
     Serial.println("Motion ended pir 2!");

     // DOWN
     digitalWrite(r4Pin, HIGH); // turn relay-2 (down) ON
     delay(5000);                   // for 5 seconds
     digitalWrite(r4Pin, LOW); // turn relay-2 (down) OFF

     // NEW STATE
     pirState = LOW;
   }
 }
}



Moderator edit: [code] [/code] tags added.

Go Up