Elektroda.com
Elektroda.com
X

Raspberry Pi 3 + WiFi + Camera + PIR = home monitoring

matti0010 11370 15
This content has been translated » The original version can be found here
  • Raspberry Pi 3 + WiFi + Camera + PIR = home monitoring
    Welcome,

    I would like to introduce you to a simple and easy project that anyone can quickly build. For this purpose, I used Raspberry Pi 3 model B with built-in WiFi. This is home monitoring that can be turned on when leaving the apartment. When the alarm is armed (60 seconds after pressing the button) and detects movement, a photo will be taken, which will then be sent to the indicated email address. After sending the photo, the system waits 1 second (total intervals are a few seconds) and checks whether the movement is still detected, if so, the process of taking the photo and sending the message is repeated until the movement disappears.

    For a project outside Raspberry Pi 3 you need:
    - HC-SR501 PIR motion sensor, which should be connected to GPIO14 (5V is available on pin number 4),
    - signaling diode (LED 3mm + resistor), which should be connected to GPIO16,
    - a camera dedicated to Raspberry Pi, which should be connected to the dedicated connector located on the board,
    - membrane keyboard, in which the selected character should be connected to the GPIO2 and GPIO3 pins

    Now a few words of explanation. The membrane keypad 4x4 characters gives great possibilities, e.g. you can enter codes to activate and deactivate the alarm. Here, however, I used a simplified version in which I selected one button from the entire keyboard and it is he who is responsible for turning the alarm on and off. We decide which button is connected (connecting it properly). The alarm operation is signaled by a lit LED. If the alarm is turned off, the LED goes out.

    Before starting the program, configure WiFi so that it can always connect to the network by itself. Alternatively, a cable can be used :)

    Python code:
    Code: python
    Log in, to see the code


    I warn you right away that I practically don't know Python so I know it could have been done better. I'm just learning the language in my free time :) If anyone has any valuable advice, I will gladly take it. Each photo taken is sent to an email address, which we will indicate in case the thief stole the device. Email support is configured for Gmail. You can choose the address to send email and the address to which this email should be sent.

    The housing and appearance of the device are shown in the pictures below (I know the tragic quality). Additional holes are for the camera and PIR mounting screws (I need to find some, this is temporarily stabilized by adhesive tape) :P ). I didn't take pictures from the inside because there is a small tangle of cables. As you can see, the keyboard comes out from the side. The power supply has also been led out. The cutouts are also not impressive, but the system works and fulfills its role, so I think it may be useful to someone.

    Raspberry Pi 3 + WiFi + Camera + PIR = home monitoring Raspberry Pi 3 + WiFi + Camera + PIR = home monitoring

    Cool! Ranking DIY
    Can you write similar article? Send message to me and you will get SD card 64GB.
    About Author
    matti0010
    Level 11  
    Offline 
    matti0010 wrote 319 posts with rating 21, helped 8 times. Been with us since 2012 year.
  • #2
    mr_grabarz
    Level 19  
    In the case of exactly one camera can and profitable
    while few cameras in this solution rather poor
    better is the recorder + IP cameras

    of the things that caught my eye:
    - what if there is no connection to WiFi?
    - why the email password explicitly saved in the code? better not to use RPi and put SMTP server on it? you can then push emails from other things, e.g. failed login attempts on RPi, info about WiFi problems, etc.
    - e-mail like e-mail, but you may want to consider the cloud (I mean dropboxes and stories of this type)
    - photo resolution / quality? (any example?)
    - motion detection is a difficult topic, how does PIR react to pets? (I mean dogs, cats?)
    - by using one specific button to activate / deactivate the alarm, over time it may happen that only this one will have traces of use, and this facilitates "disarming the system"

    When it comes to power supply, I successfully use easily available and cheap stepdown converters from the auction portal and power RPi over PoE
  • #3
    matti0010
    Level 11  
    mr_grabarz wrote:
    In the case of exactly one camera can and profitable
    while few cameras in this solution rather poor
    better is the recorder + IP cameras

    of the things that caught my eye:
    - what if there is no connection to WiFi?
    - why the email password explicitly saved in the code? better not to use RPi and put SMTP server on it? you can then push emails from other things, e.g. failed login attempts on RPi, info about WiFi problems, etc.
    - e-mail like e-mail, but you may want to consider the cloud (I mean dropboxes and stories of this type)
    - photo resolution / quality? (any example?)
    - motion detection is a difficult topic, how does PIR react to pets? (I mean dogs, cats?)
    - by using one specific button to activate / deactivate the alarm, over time it may happen that only this one will have traces of use, and this facilitates "disarming the system"

    When it comes to power supply, I successfully use easily available and cheap stepdown converters from the auction portal and power RPi over PoE


    Ultimately, I wanted to make only one camera that will monitor the entrance door along with the corridor. If I had to make several cameras, of course your idea would be much better.

    For the rest:
    - no connection = no email will be sent unless we have a Raspberry internet cable connected (no matter if we use the cable or WiFi),
    - in total, probably you can, but I wanted the system to be very simple. In addition, I'm limited by my current knowledge (I'd like to know how to do it, in my spare time I will look for information, there will probably be something on Google). Of course, I will gladly take a good example / guide if you have one and want / can share it :)
    - email if it comes to a phone, tablet or other device that we will have with us will inform us about it. With dropbox and cloud I don't know how it is.
    - I can place an example with resolution (if you or others care so much :) ), but it really depends on the camera we use. There are many varieties, some of better quality and others of worse quality, so everyone can get it differently.
    - from what I read it is difficult to determine because the animals have a different body temperature than humans and the PI system works by detecting the movement of an object at a human body temperature. Unfortunately, I don't have pets to test it and I'd love to find out what it looks like in their case. A blast of warm air could trigger the PIR, but for this purpose you can add a thermistor to the HC-SR501 that eliminates this problem (to some extent),
    - right, I did not take this into account but you can always change this button by unplugging one cable. In addition, the system will always take at least one photo after entering and before someone turns off the system, it will be photographed and we will receive an email with the message. Especially I did not give a lock to take a photo if someone enters and turns off the system within a certain time. Thanks to this, even if someone who knows this device and sees the worn key comes in, it will be photographed.

    PoE? I don't think I know, can you expand the subject a little? Power supply here is a side topic, we can, for example, power the Raspberry from the power supply and e.g. a power bank, which will be a spare battery.
  • #4
    mr_grabarz
    Level 19  
    matti0010 wrote:
    - no connection = no email will be sent unless we have a Raspberry internet cable connected (no matter if we use the cable or WiFi),

    nooo ok but how does everything behave?
    trying to send again?
    example:
    the IP connection has died, someone PIR is detecting something, the camera takes a picture, the script wants to send it - failed - OK
    try again after some time? discards photos?
    I'm aiming for a failure on your ISP's side to kill monitoring.
    If there is no attempt to send again, if it fails the first time it may be sneezing, I hope you know what I'm going to.
    matti0010 wrote:
    - from what I read it is difficult to determine because the animals have a different body temperature than humans and the PI system works by detecting the movement of an object at a human body temperature. Unfortunately, I don't have pets to test it and I'd love to find out what it looks like in their case. A blast of warm air could trigger the PIR, but for this purpose you can add a thermistor to the HC-SR501 that eliminates this problem (to some extent),

    In PIR detectors for alarms, sensitivity is determined based on the animal's weight (appropriate jumpers configuration)
    As for the air blast, dual alarms, i.e. PIR + MW (MicroWave) are used in alarm systems, the only sensible solution when the detector is e.g. in a boiler room where the stove operates and is medium well insulated, or e.g. a fireplace in the room :)

    matti0010 wrote:
    - email if it comes to a phone, tablet or other device that we will have with us will inform us about it. With dropbox and cloud I don't know how it is.

    100% you're right, but I thought about the cloud rather like an archive
    in my case, dig through X mail to dig something from x time rather badly :)

    matti0010 wrote:
    PoE? I don't think I know, can you expand the subject a little? Power supply here is a secondary topic, we can, for example, power the Raspberry from the power supply and e.g. a power bank, which will be a spare battery.

    PoE = Power Over Ethernet
    https://pl.wikipedia.org/wiki/Power_over_Ethernet
    I am not a WiFi fan so if I am flying with a toy cable anyway, why not immediately push the same power cable and the inverter will help me that the power supply for the cable always enters 24V while devices depending on needs, 12V, 5V
  • #5
    matti0010
    Level 11  
    If the photo fails to send, there are two possible cases:
    a) the motion is still detected so he takes a new photo and tries to send the new photo
    b) motion is not detected, then it does not take a new photo but also does not send the old one. The old photo, however, is in the folder on Raspberry Pi in which we have a Python script fired so we can look at it manually. In total, you can modify the code to send again (once or twice to try). The matter to add (or rather copy) a piece of code to the right place.
    I know what you are going to and you're right, I think I will develop this code so that it tries to send up to 3 times.

    With furnaces and other such, actually PIR would give bodies like a certain Sasha :P

    Not necessarily digging will be troublesome, just search the mail for the title "Motion detected !!" or with a different name that someone sets for themselves. The cloud would quickly clog up (gmail too :P ) if someone forgets to turn off the system after entering the house and walks hundreds of times nearby :P

    I didn't know PoE, though, in total I once read about powering devices from Ethernet (I didn't know this abbreviation). I am not surprised that you power it up because it is not only logical but also convenient :) If you like PoE, have you been interested in the topic of sending information using the power network (i.e. in a 230V network you send information to devices). Interesting topic, though heavy and has many disadvantages that must be tackled :)
  • #6
    mr_grabarz
    Level 19  
    matti0010 wrote:
    b) motion is not detected, then it does not take a new photo but also does not send the old one. The old photo, however, is in the folder on Raspberry Pi in which we have a Python script fired so we can look at it manually.

    I would think about trying to send a recent or recent photo if no motion is detected :)

    matti0010 wrote:
    If you like PoE, have you been interested in the topic of sending information using the power network (i.e. in a 230V network you send information to devices). Interesting topic, though heavy and has many disadvantages that must be tackled

    I was interested a few years back and the number of disadvantages far outweighed the number of advantages
    at the moment I'm at the 24V DC stage and in total a revelation,
    but I think we differ from the topic of your thread :)
  • #7
    matti0010
    Level 11  
    mr_grabarz wrote:
    matti0010 wrote:
    b) motion is not detected, then it does not take a new photo but also does not send the old one. The old photo, however, is in the folder on Raspberry Pi in which we have a Python script fired so we can look at it manually.

    I would think about trying to send a recent or recent photo if no motion is detected :)

    matti0010 wrote:
    If you like PoE, have you been interested in the topic of sending information using the power network (i.e. in a 230V network you send information to devices). Interesting topic, though heavy and has many disadvantages that must be tackled

    I was interested a few years back and the number of disadvantages far outweighed the number of advantages
    at the moment I'm at the 24V DC stage and in total a revelation,
    but I think we differ from the topic of your thread :)


    I think I'll add the option to resend because it's a good idea.

    From what I read, I also found that there are more disadvantages than advantages. However, some may be interested :) What to leave, if the topic is interesting, why not leave? :P
  • #8
    mr_grabarz
    Level 19  
    matti0010 wrote:
    What to leave, if the topic is interesting, why not leave?
    because it is so-called off-topic and is inconsistent with the regulations?
    makes searching for information more difficult, because it is rather difficult to look for information about data transmission over the 230V AC network in the topic about monitoring:>?

    matti0010 wrote:
    Not necessarily digging will be troublesome, just search the mail for the title "Motion detected !!" or with a different name that someone sets for themselves. The cloud would quickly clog up (gmail too :P ) if someone forgets to turn off the system after entering the house and walks hundreds of times nearby :P

    Yes and no
    Email may make sense if there is one camera of this type, and how do you know I don't shoot 10?
    on the cloud you can do it straight away camera = folder
    otherwise
    keeping the amount of space occupied in the cloud is simpler than blocking the email

    example:
    script looped for some reason (OS error or something)
    it packs a dedicated cloud: nooo ok it's hard
    he smells me an email - RPi goes to a meat grinder (well I can't imagine :) )

    Besides - cloud cloud I'm not a fan
    but a network drive is another toy - I have and I'm happy
    at the moment it is RAID5 with 3x1TB free about 50% hard it would be to collapse photos from this particular project :)
  • #9
    Heinzek
    Network and Internet Specialist
    Nice construction.
    As for motion detection, it can be done on a "webcam". Read about motion which, when motion is detected on the camera, automatically saves photos to the designated place. It can also run a designated application / program when it detects traffic, e.g. sendmail
    You can also choose the detection zone (only 9 zones)
  • #10
    matti0010
    Level 11  
    We discussed possible ways of powering and transmitting the signal, which is an inseparable element of monitoring :P

    It makes sense with a clogged email, in that case a cloud and a better disk is a better idea :)

    @Heinzek, I didn't know that, nice idea :) I'll read about it.
  • #11
    romulus73
    Level 21  
    An interesting project I am doing now, alarm for the garage, but on Arduino
    The cloud is a linden I mean dropbox, buy yourself a NAS and there you have 4 cameras as standard.
    When you configure it, you can have emails or sms, after all it's your own cloud without restrictions. I have Synology myself, slow but everything works great.
  • #12
    mr_grabarz
    Level 19  
    romulus73 wrote:
    Cloud is a linden I mean dropbox, buy yourself NAS napkins and there you have 4 cameras as standard.

    cloud is one thing, network disk is another

    romulus73 wrote:
    after all, it's your own cloud without restrictions. I myself have Synology slow but everything works great.

    they sum it up like this:
    people are divided into three groups:
    1. those who do backups
    2. those who will do backups
    3. those who think they are backing up :)

    limits you:
    - size
    - data redundancy
    - confusing cloud and network drive concepts

    for the author of the topic:
    cloud = YES
    single disk network drive = NO
    why? I don't think I have to translate ... taking the above posts ...
  • #13
    Freddy
    Level 43  
    romulus73 wrote:
    Cloud is a lime I mean dropbox ...
    Why?
    Regular backups are different, and a copy of files in the cloud is different - they can coexist.
  • #14
    romulus73
    Level 21  
    Colleagues cloud is a network folder with synchronization placed on the NAS.
    Why do you think I have one disk?
    I have a cloud with full synchronization, you have a dropbox without a beckap and the account is not yours.
    I have a domain, Cloud, DNS MX, NS, Cname - that is a website, my own domain - my own E-mail server and everything you have on one hundred hosting plans. on your server, so concentrate before you write about the clouds again

    mr_grabarz Dude, do not confuse the concept of a network drive with a NAS server
  • #15
    ..::MariuszB::..
    Level 16  
    The cloud today because of the costs and profits associated with it is implemented quite often on one rack and in the same room with the marketing slogan "in the cloud safer". But everyone believes in what they want and pays who they want ;)
  • #16
    matti0010
    Level 11  
    I noticed an interesting problem. Sometimes the system will arm or disarm itself. It is as if the state on the keyboard pin was unstable. A pull-up polarizing resistor would probably help (because I'm not sure if there is a Raspberry Pi). I haven't tested it yet.