ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

joi, 6 martie 2014

Senzorul de prezenta HC-SR501 si Arduino (II)

   In primul articol am facut o scurte prezentare si am dat niste adrese unde pot fi gasite informatii despre acest senzor...
   Acum am luat primele 2 articole de acolo si am facut mici teste, folosind intrarea analogica A0 ca una analogica sau ca una.. digitala, adica D14... ce primeste placa Arduino fiind evidentiat de LED-ul conectat la pinul D13 si/sau pe ecranul de monitorizare seriala...
   Primul sketch folosit de mine este:
// http://blog.roman-mueller.ch/index.php/2013/01/26/hc-sr501-passive-infrared-sensor-with-arduino/
#define pir A0
#define led 13

void setup() {
  pinMode(pir, INPUT);
  pinMode(led, OUTPUT);
}
void loop() {
  digitalWrite(led, digitalRead(pir));
  delay(100);
}
   Apoi am incercat pe cel prezentat in celalalt articole:
// http://robotic-controls.com/learn/sensors/pir-sensor-hc-sr501

int pirPin = 14; //is A0 :P
int val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(pirPin); //read state of the PIR
  
  if (val == LOW) {
    Serial.println("No motion"); //if the value read is low, there was no motion
  }
  else {
    Serial.println("Motion!"); //if the value read was high, there was motion
  }
  
  delay(1000);
}
   Am "mixat" cele 2 sketch-uri, cand A0 este intrare digitala si a rezultat sketch-ul:
// http://robotic-controls.com/learn/sensors/pir-sensor-hc-sr501
// http://blog.roman-mueller.ch/index.php/2013/01/26/hc-sr501-passive-infrared-sensor-with-arduino/
// http://nicuflorica.blogspot.ro/2014/02/senzorul-de-prezenta-hc-sr501-si-arduino.html

int pirPin = 14;  //is A0
int val;
#define led 13

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  val = digitalRead(pirPin); //read state of the PIR
  
  if (val == LOW) {
    Serial.println("No motion"); //if the value read is low, there was no motion
    digitalWrite(led, digitalRead(pirPin));
  }
  else {
    Serial.println("Motion!"); //if the value read was high, there was motion
    digitalWrite(led, digitalRead(pirPin));
  }
  
  delay(1000);
}
   Apoi am folosit intrarea analogica 0 ca intrare analogica...
// http://blog.roman-mueller.ch/index.php/2013/01/26/hc-sr501-passive-infrared-sensor-with-arduino/
// http://robotic-controls.com/learn/sensors/pir-sensor-hc-sr501
// http://nicuflorica.blogspot.ro/2014/02/senzorul-de-prezenta-hc-sr501-si-arduino.html

#define pir A0
#define led 13

void setup() {
  Serial.begin(9600);
  pinMode(pir, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {
  int val = analogRead(pir);
  float val1 = val*5.00/1023.00;
  digitalWrite(led, LOW);
  if (val <650) {
    Serial.print(val);
    Serial.print("/1023 = ");
    Serial.print(val1);
    Serial.println("V - No motion"); //if the value read is low, there was no motion
    
  }
  else {
    Serial.print(val);
    Serial.print("/1023 = ");
    Serial.print(val1);
    Serial.println("V - Motion!"); //if the value read was high, there was motion
    digitalWrite(led, HIGH);
  }
  delay(500);
}
    Am realizat si un filmulet numit HC-SR501 PIR sensor (4)

Niciun comentariu:

Trimiteți un comentariu

Senzor de masurare tensiune si curent INA219

   Am achizitionat de curand, de la colaboratorii mei de la  ArduShop.ro , un modul cu senzor INA219, care poate masura tensiuni pana la 26V...