MetallicGR Posted July 20, 2015 Share Posted July 20, 2015 [NEWS_IMG=DIY: Ανιχνευτής κίνησης με Arduino]http://www.hwbox.gr/members/2195-albums497-picture34930.jpg[/NEWS_IMG] Ένας απλός ανιχνευτής κίνησης με βάση έναν αισθητήρα τύπου P.I.R. Με ένα Arduino, έναν αισθητήρα P.I.R, μερικά jumper wires, μια οθόνη 16x2 LCD ένα buzzer, μια μεταβλητή αντίσταση και ένα breadboard για τις δοκιμές μας. Τα υλικά περιγράφονται παρακάτω και μπορείτε να τα δείτε στην πρώτη εικόνα. 1 : Arduino UNO 2 : P.I.R Sensor 3 : 16 x 2 LCD Screen 4 : Bread Board 5 : Jumper Wires 6 : Small Jumper Wires 7 : Buzzer 8 : 10K Resistor 9 : ِAnd Of course a USB Cable [img_alt=DIY: Ανιχνευτής κίνησης με Arduino]http://www.hwbox.gr/members/2195-albums570-picture49901.png[/img_alt] Βήμα 1. Το σχεδιάγραμμα που καλείστε να ακολουθήσετε για την ολοκλήρωση του DIY. Οι συνδέσεις περιγράφονται παρακάτω: The LCD Screen : Pin 1 : To Ground Pin 2 : To +5 Pin 3 : To The Middle Pin Of The Variable Resistor Pin 4 : To Arduino Digital Pin 13 Pin 5 : To Ground Pin 6 : To Arduino Digital Pin 12 Pin 7 : X Pin 8 : X Pin 9 : X Pin 10 : X Pin 11 : To Arduino Digital Pin 11 ~ Pin 12 : To Arduino Digital Pin 10 ~ Pin 13 : To Arduino Digital Pin 9 ~ Pin 14 : To Arduino Digital Pin 8 Pin 15 : To Arduino Digital Pin 6 ~ Pin 16 : Ground The Variable Resistor : Most Right Pin To +5 Most Left Pin To Ground The P.I.R Sensor : GND to Ground VCC to +5 OUT to Arduino Digital Pin 7 The Buzzer : N=egative to Ground Positive to Arduino Digital Pin 6 ~ [img_alt=DIY: Ανιχνευτής κίνησης με Arduino]http://www.hwbox.gr/members/2195-albums570-picture49902.png[/img_alt] Βήμα 2. Ο κώδικας που θα πρέπει να ανεβάσετε με το Arduino IDE: #include <LiquidCrystal.h> //including the LiquidCrystal Library const int BGLCD = 6; //Definition the background liquid crystal display pin or BGLCD for short const int SensorPin = 7; //Definition the P.I.R sensor pin const int Speaker = 5; //Definition the Speaker pin LiquidCrystal lcd(13, 12, 11, 10, 9, 8); //Definition the LCD pins void setup() { //begining the setup function lcd.begin(16, 2); //begining the lcd (16 rows by 2 column) Serial.begin(9600); //begining the Serial Communication at 9600 baud pinMode(Speaker, OUTPUT); //Setting the Speaker pin as an OUTPUT pinMode(SensorPin, INPUT); //Setting the Sensor pin as an INPUT pinMode(BGLCD, OUTPUT); //Setting the BGLCD as an OUTPUT digitalWrite(BGLCD, HIGH); //turning the LCD back light on while displaying lcd.setCursor(5, 0); //setting the cursor of the lcd to(5, 0) lcd.print("Motion"); //displaying "Motion" lcd.setCursor(4, 1); //setting the cursor of the lcd to (4, 1); lcd.print("Detector"); //displaying "Detector" delay(2000); //delay for tow seconds lcd.clear(); //clearing the lcd aka delete lcd.setCursor(4, 0); //setting the cursor to (4, 0) lcd.print("By Baraa"); //displaying my name lcd.setCursor(5, 1); //setting the cursor to (5, 1) lcd.print("Halabi"); //displaying my name delay(2000); //delay tow seconds lcd.clear(); //clearing the lcd lcd.setCursor(3, 0); //setting the cursor of the lcd to (3, 0) lcd.print("Processing"); //displaying "processing" lcd.setCursor(6, 1); //setting the cursor of the lcd to (6, 1) lcd.print("Data"); //displaying "data" delay(8000); //delay eight seconds lcd.clear(); //clearing the lcd digitalWrite(BGLCD, LOW); //turning the lcd back light off } void loop () { //begining the loop function int Sense = digitalRead(SensorPin); //creating an integer that is the motion sensing is a digitalRead from the sensor pin if (Sense == HIGH){ //if the integer sense equal HIGH or 1 do... Serial.println("Motion Detected"); //print on Serial "motion detected" on a new line lcd.setCursor(5, 0); //setting the cursor of the lcd to (5, 0) lcd.print("Motion"); //displaying "motion" lcd.setCursor(4, 1); //setting the cursor of the lcd to (4, 1) lcd.print("Detected"); //displaying "detected" Sound(200, 200); //playing a tone(duration, freq) for(int Brightness = 0; Brightness <= 255; Brightness = Brightness + 5) { //setting for loops the brightness is counting +5 evry 3 milliseconds from 0 to 255 (fading efect) analogWrite(BGLCD, Brightness); //pwm BGLCD to brightness delay(3); //evry 3 milliseconds } for(int Brightness = 255; Brightness >= 0; Brightness = Brightness - 5) { //setting for loops the brightness is counting down -5 evry 3 milliseconds from 255 to 0 (fading efect) analogWrite(BGLCD, Brightness); //pwm BGLCD to brightness delay(3); //evry 3 milliseconds } } else { //if no motion sensing do... digitalWrite(BGLCD, LOW); //turning the BGLCD off or low or 0 lcd.clear(); //and clearing the lcd } } void Sound(long duration, int freq) { //creating a tone function duration *= 1000; int period = (1.0 / freq) * 100000; long elapsed_time = 0; while (elapsed_time < duration) { digitalWrite(Speaker,HIGH); delayMicroseconds(period / 2); digitalWrite(Speaker, LOW); delayMicroseconds(period / 2); elapsed_time = elapsed_time + (period); } } Το πρόγραμμα θα δείξει στην οθόνη, Motion Detector, ύστερα θα δείξει το όνομα που φαίνεται στον κώδικα και τέλος, θα γράψει "Processing data", δίνοντας παράλληλα χρόνο 8 δευτερολέπτων για να φύγετε μακριά. Οτιδήποτε ανιχνευτεί μετά το διάστημα των 8 δευτερολέπτων, θα σημάνει το buzzer, ενώ η μεταβλητή αντίσταση των 10 kohm θα ρυθμίσει την ευαισθησία του αισθητήρα. [img_alt=DIY: Ανιχνευτής κίνησης με Arduino]http://www.hwbox.gr/members/2195-albums570-picture49903.png[/img_alt] [img_alt=DIY: Ανιχνευτής κίνησης με Arduino]http://www.hwbox.gr/members/2195-albums570-picture49904.png[/img_alt] Διαβάστε περισσότερα εδώ... Link to comment Share on other sites More sharing options...