2 pirren op een arduino om een mosfet te schakelen

Tsja
Dombo hier

Een hele dag druk om een turtiol aan de gang te krijgen.
Maar helaas..

Ik zoek dus eigenlijk een te simpele oplossing.
pir 1 ene kant van het bed.
pir 2 ander kant van het bed.

Bed uit led onder de rand van het bed aan voor x minuten.. en dan auto off

Veel sketches geprobeerd maar loop tegen de zelfde problemen aan.
Lijkt wel of de pir anders werk, beweging gaat hij uit, ipv aan.
Zelfs met de originele sketch van Arduino.
http://playground.arduino.cc/Code/PIRsense

Dan heb ik ook last een half brandende ledstrip.
Dus als ie uitschakeld, gaat hij niet helaaml uit.
dit gebeurd wel als ik de usb in mijn mega laat zitten.
Ik heb de ledstrip via een mosfet aangesloten, en die werk verder goed.
Dus eigenlijk hoef ik alleen maar 1 pin aan of uit teschakelen..

Dus HELLLLUPPP

Please..
Ik word er gek..
Zoiets simpels..

/* 
 * //////////////////////////////////////////////////
 * //making sense of the Parallax PIR sensor's output
 * //////////////////////////////////////////////////
 *
 * Switches a LED according to the state of the sensors output pin.
 * Determines the beginning and end of continuous motion sequences.
 *
// * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
 * date:   3. September 2006 
 *
 * kr1 (cleft) 2006 
 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license
 * http://creativecommons.org/licenses/by-nc-sa/2.0/de/
 *
 *
 * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. 
 * (http://www.parallax.com/detail.asp?product_id=555-28027)
 *
// * The sensor's output pin goes to HIGH if motion is present.
 * However, even if motion is present it goes to LOW from time to time, 
 * which might give the impression no motion is present. 
 * This program deals with this issue by ignoring LOW-phases shorter than a given time, 
 * assuming continuous motion is present during these phases.
 *  
 */

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 10;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 1000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);  // veranderd in HIGH niet

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){ // veranderd in LOW niets
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state // veranderd in LOW niets
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){   // Veranderd in HIGH    niets
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

Hee dylantje.

Ik zag je vraag in een ander forum ook al voorbij komen.
Maak ff een tekeningetje (of een duidelijke foto) van hoe je de PIR hebt aangesloten aan je Arduino.
Dan kunnen we wat beter zien wat de bedoeling is en of je daar niet iets over het hoofd hebt gezien.

Het lijkt er op dat je niet alles helemaal goed hebt zitten met de GND's, en dat geldt dus ook voor je uitgang die niet helemaal zo werkt als je wil, tenzij je de pc er aan laat hangen.

Mosfet:
https://learn.sparkfun.com/tutorials/led-light-bar-hookup/example-circuits

Deze manier de 1ste pir [ eerst die goed werkend krijgen ]

De sketch aangepast van makezin sensor:

// Uses a PIR sensor to detect movement, buzzes a buzzer
// more info here: http://blog.makezine.com/projects/pir-sensor-arduino-alarm/
// email me, John Park, at jp@jpixl.net
// based upon:
// PIR sensor tester by Limor Fried of Adafruit
// tone code by michael@thegrebs.com

 
int ledPin = 12;                // 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 = 1;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == LOW) {            // Zorgt dat hij de goed "richting"op gaat High is de pir anders om
  digitalWrite(ledPin, HIGH);  // turn LED ON
//      delay(10);      
    
    if (pirState == LOW) {      // 
     Serial.println("Motion detected!");      // 
      pirState = LOW;
//      delay(10000);
    }
  } else {     digitalWrite(ledPin, LOW); // 
             
    if (pirState == HIGH){      // we have just turned of
    Serial.println("Motion ended!");      // 
    pirState = HIGH;
//     delay(1000000);  // tijd dat lamp aan is
    }
  }
}

De originele aduino sketch:

/* 
 * //////////////////////////////////////////////////
 * //making sense of the Parallax PIR sensor's output
 * //////////////////////////////////////////////////
 *
 * Switches a LED according to the state of the sensors output pin.
 * Determines the beginning and end of continuous motion sequences.
 *
// * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
 * date:   3. September 2006 
 *
 * kr1 (cleft) 2006 
 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license
 * http://creativecommons.org/licenses/by-nc-sa/2.0/de/
 *
 *
 * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. 
 * (http://www.parallax.com/detail.asp?product_id=555-28027)
 *
// * The sensor's output pin goes to HIGH if motion is present.
 * However, even if motion is present it goes to LOW from time to time, 
 * which might give the impression no motion is present. 
 * This program deals with this issue by ignoring LOW-phases shorter than a given time, 
 * assuming continuous motion is present during these phases.
 *  
 */

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 20;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 1000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);  // veranderd in HIGH niet

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(500);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){ // veranderd in LOW niets
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state // veranderd in LOW niets
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){   // Veranderd in HIGH    niets
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

Ik heb ook geprobeerd de + en de - van de pir om te draaien maar dan werkt hij niet.
De sketch van makezin is simpel, maar werkt niet goed. kan geen tijd instellen.

Bij de sketch van arduino werkt de pir andersom. [ dus uit bij beweging.]
En die is best ingewikkeld, maar dat is leuk om mee te spelen..
Ik wil graag 2 pirren hebben 1 links en de ander rechts.

Dan blijft er bij beide sketches de leds half branden als ik de usb van de mega eraf haal.
Dus hij wordt niet spanningsloos oid..

Ik zou blij zijn als je tijd hebt..
En helaas ben ik te oud en te doem om de arduino goed te doorgronden.
Ik ben meer een blije 60+ gebruiker... 8) 8) 8)

Leeftijd doet niet ter zake volgens mij.
Als je er in geïnteresseerd bent en er de tijd in wil steken, zul je een eind komen.
En veelal zul je dan wat meer tijd hebben voor de hobby dan ik heb.

Als je PIR sensor niet zo werkt als beschreven in je voorbeeld, welke PIR sensor gebruik je dan ?
Dat zal niet dat ding van Parallax zijn.
Als we het type weten kunnen we mogelijk ook meer zeggen over hoe je dat het best kunt aansluiten.
En welke FET gebruik je ?

Mwhaa leeftijd doet niet ter zake.. =( =( =(
Mijn eerste pc was een xp en ik ben nu meer als 50+ :disappointed_relieved: XD :fearful:
Dus mijn digitale tijdperk is erg beperkt. 8) al zou ik graag anders wilen als ik al dat moois zie.. :frowning:
En mijn kennis over vanalles ook, tijd is een vijand.[ tik tak tik tak, en je bent 60 ]
Aangezien ik een gezin werk enz enz enz[ maar daar zeur ik niet over] want zijn veel meer mensen met dat probleem.. :slight_smile: :%

Het lastige is dat ik van die code niet veel snap, en die voorbeelden zijn erg mooi, maar als je iets anders wil.
Loop ik per direct vast...
dus ik hoop dat jullie wat t..d over hebben..

Mijn mosfet:

Mijn pir:
http://www.ebay.com/itm/PIR-Sensor-Human-Body-detecting-module-Pyroelectric-HC-SR501-For-Arduino-MCU-NEW-/390562753724?pt=LH_DefaultDomain_0&hash=item5aef5aacbc

Ik kom er niet uit..
Wat ik ook aanpas in de sketch.
De leds blijven half branden als ik de usb eraf haal.
En bij de tutoril van Arduino, blijft de pir verkeerd om werken..
Pir uit lampen aan..

Please...
Iemand..

Probeer eens het nivo van je de Gate van je FET naar nul te trekken.
Dat kun je doen door een weerstand van 100K ofzo van die gate naar GND te schakelen.
Het is wel de bedoeling dat die weerstand beduidend hoger is dan de weerstand van de Gate naar je Arduino.

Alles werkend..
Alleen de leds helemaal uit lukt niet...
Als ze uit moeten zijn, branden ze nog een beetje..

Tips...

Heb je een multimeter ?
Meet dan eens de spanning over je LED strip.

Ook opgelost....

Ik had de mosfet aangesloten met weerstandjes enz enz

alles eraf en zo aangesloten:

En werken..
Als ik dat eens eerder had geweten...

Bedankt...

Ik zoek nu nog een 433MHz sketch die 1-wire uitleest en meteen via 433MHz verzend om de x minuten..
Dus als iemand die weet.[ evt tegen een vergoeding. ] laat maar horen...

Dit is wel een schakeling die lijkt op wat ik wil maken, ook een pir waarmee ik een wand met een stuk of 10 à 20 ledjes kort wil laten oplichten, als een soort vallende sterrenregen. Maar die strips onder het bed kan een leuke aanvulling zijn!

Ik heb voor een paar euro zo'n pir nachtlampje van de action liggen die ik wil gaan misbruiken voor dit doel :slight_smile: