Saturday, 19 March 2016

Criterion D

Objective D: Evaluating
My Raspberry Pi motion sensor alarm worked as per the design specification. However, the design specification left a few details. The motion sensor detected movement very quickly and after 0.25 seconds, the ‘computer beeps’ sound occurred. Under Sensor block palette, the GPIO sensor value ranged from 0 to 1. Note: This was a test to see whether the GPIO pin 4, connected to OUT pin of motion sensor, would respond when the sensor detects movement.
However, the display connection from Raspberry Pi to Laptop was the hardest part. I used a Wi-Fi dongle to connect Pi to laptop but it wasn’t successful as I needed the monitor to get the ip address and include it in Putty client. Instead, I used an Ethernet cable. I first set up a DHCP server client. Then, I ran the client wizard and configured the settings. I selected the adapter (Ethernet) and gave a fixed ip address: 192.168.2.100 and the range was from 100 to 110. Therefore, it was easier to connect to the device in a swift way. Putty, an application, was used to connect to the device using network protocol SSH (Secure Shell). I entered the ip address and took me to the command line of the Pi where I could issue commands. From here on, I setup a VNC Server by executing command vncserver :1. After VNC server was established, I used VNC Viewer client where I the ip address of the Pi is already given. Then, after logging in, I could see the graphical user interface of the Pi.
 Then it came to the code writing. I used Python 3 DLE software to check whether the motion sensor was working. When it came to writing the code in Python 3 program, I wasn’t able to understand what the code meant. There were always problems regarding incorrect syntax, etc. Here is the correct code below:
(nano pirtest.py)
import RPi.GPIO as GPIO
import time

sensor = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

previous_state = False
current_state = False

while True:
    time.sleep(0.1)
    previous_state = current_state
    current_state = GPIO.input(sensor)
    if current_state != previous_state:
        new_state = "HIGH" if current_state else "LOW"
        print("GPIO pin %s is %s" % (sensor, new_state))
(sudo python3 pirtest.py)
The mistake in this code was that I added nano pirtest.py at the start of the code and sudo python3 pirtest.py at the end. Nano pirtest.py is a command to start the Python 3 program named ‘pirtest.py’ and sudo python3 pirtest.py is a command to run the python file ‘pirtest.py’. I cleared these two mistakes from the code. As a result, the code was run and the motion sensor was able to detect movement.
In this code, we are first setting up the GPIO pins of Pi to see whether they will allow us to use pin 4 as an input; then it can detect once PIR module sends power. Therefore, we use a while True loop to check the pin continuously for any changes to be made. This is an infinite loop which can be stopped using Ctrl + C. Then two Boolean variables (a variable (motion sensor) that can have two possible values), that is True (1) and False (0), for the previous and current states of the pin. Inside this loop, we also want to compare the previous state to the current state when they are different.
Finally, the creating of the code sequence in Scratch. Here to I experienced difficulties when using block palettes (where were the specific blocks located?). I researched on the internet and found out. First, I started GPIO server which will locate the pin 4 of the GPIO header of Pi. Then, in the control block palette, I clicked and dropped broadcast block into the script. In the block, I typed config4in and double-clicked the block. This shows that pin 4 will be used as an input by configuring it. Under the sensor block palette, I click the drop-down menu on Sensor block and choose GPIO 4. In addition, I ticked the checkbox to display on screen. By doing this, you can also check whether the motion detects movement by examining the value on the screen change from 0 to 1. Then, I added a sprite and included the following code sequence for that particular sprite. Here is the code sequence:
 

·         It makes the sprite appear out of nowhere and increases its size once movement is detected. If there is no movement, the sprite diminishes and disappears.
·         After 0.25secs, the ‘whoop’ sound is played.
Feedback from a friend, Alberto:
"Good try and useful product.  Remote configuration should be done so that it can be installed in houses, inside the front door, when the residents are out of town."
Improvements:
·         An easy step by step instruction manual for setup of the system.
·         Add an ultrasonic rangefinder so that when movement is located through echolocation, the alarm will immediately occur.
·         Add a method of accessing Pi through laptop into the instruction manual.
·         Add an additional feature such as a solderless breadboard where circuits can be built and others such as LED’s, resistors, etc. which are also used to alarm the users.
·         Use longer jumper wires when installing in various places of the house (doors, windows, etc.)
Due to this alarm, users can be more alert and prepared when an intruder enters the house.
Strengths
Weakness
·         Comes with a step by step instruction manual for the setup of the Raspberry Pi system.
·         Can detect movement immediately and the alarm comes in the form of sound.
·         The code or code sequence can be edited according to the user’s perspectives.
·         Low power consumption.
·         Has a low cost.
·         You can use it as a troubleshooting tool.
·         Can open some applications without the internet.
·         Due to its independent network connectivity, you can set it up using SSH or transfer file via FTP.
·         The Linux operating system makes it easy for pi to be used as a media streamer, video game emulator, etc.








·         Jumper cables, micro USB power adapter wire and Ethernet cable are too small. Therefore, it might cause problems for installation in different places of the house.
·         Not waterproof.
·         If it is connected to a high source of power, then it may overload or malfunction.
·         In addition, randomly plugging in wires in different pins of the GPIO header may kill Pi.
·         Due to its processor, it cannot run x86 operating systems such as Windows and Linux distros.

No comments:

Post a Comment