Slot machines and juvenile theft

I was about ten years old.

There is a slot machine in the shop at my door. Every day when I pass by the shop after school, there are many onlookers around the machine.

I loved going to the store after dinner and watching people bet, keystroke, laugh, swear, and stamp their feet. I loved the position on the side of the slot machine where, through the cracks in the machine, I could see the circuit boards inside, the numbers flashing irregularly

Since a long time, I have been very strong interest in the slot machines, many years later, in the one horn of the university library, and read with great interest to the slot machine algorithm is the author of the book, he talks about you could not have won the machine, there is only one win the opportunity to win your partner, you will be the machine as a mediation, according to participants in front of the outcome, determine your strategy, it is your only a chance of winning

Early one morning, there were police cars parked outside the shop, and it was the kind of thing a 10-year-old would love to be part of. I squeeze into the shop, and I see four dejected teenagers, hands cuffed, 15, 16 years old. I was a regular at the slot machine.

The perpetrators have asked the reason, the boss smiling, talking about this group of teenagers, how repeatedly, burglary, exquisite technique, act prudently.

Then they ask how you caught them when you said they were clever.

The boss and so on is this sentence, immediately like the podium to do the acceptance speech. The boss said he had discovered the burglary early, and in order to prove it, he devised an elaborate trap: a rope was tied to the entrance of the counter, near the ground, and the rope led to the boss’s bedroom, where he was sleeping, and the can was tied to the bedroom. The teenagers come again, trigger the switch, knock down the boss bedroom can, the boss woke up, well prepared, the teenagers have no consciousness, to a sure catch

Finally, the boss sighed that such a clever, used to learn how good

People praised

Raspberry PI based alarm

In the story, there is one place is not beautiful: the alarm is made of rope! If the teenagers had been more vigilant, seen the rope, or stepped on it and fled, the boss would have been disappointed.

We can reconstruct the alarm based on the raspberry PI

Train of thought

By placing ultrasonic sensors (or infrared) under the counter and sending a text message (or email) to the boss’s phone when someone walks by, PI’s invisible guard is almost unassailable

Implementation (hardware)

For hardware, we use mobile power to power raspberry PI, which is easy to hide (mobile power lasts about a week)

The wiring diagram is as follows (just pay attention to the ultrasonic sensor) :

Implementation (software)

For the software part, I’ve put the source code here: Raspberrypi_lab

The core of this project is the use of ultrasonic sensor ranging, when there is an object in front of the sensor, the distance will change, so trigger other functions (mail) can be, the core source code is: ECHO_main

If you want to send email, use Python’s SMTP library. If you want to send SMS, use Twilio’s API:

from twilio.rest import TwilioRestClient
account = "xxx"
token = "xxx"
client = TwilioRestClient(account. token)
message = client.messages.create(to="+86137xxx". from_="+166xxx". body="Wake up!")

After running up the code, put it under the counter, when someone passes by, you can quietly send SMS alarm!

Guard your private space

Let’s continue to play the guardian concept, this time to protect you in the room do not study, love to play around

Think of watching Doraemon in your room (but you can watch something else)

The head teacher is visiting your living room. You can’t even watch cartoons, and you’re afraid someone’s breaking in

Let’s embrace the geek spirit and make Raspberry PI the guardian of privacy. The guardian’s duty is: when someone enters the room, put a smiley face on the LED matrix to welcome them and play a song with the buzzer to attract attention (I used gourd doll, you can use teacher window etc.).

Led matrix source code is as follows: smile.py

The source code for the buzzer part is beep.py

When the door is opened, ultrasonic sensors will sense the presence of obstacles, which is triggered by smiley faces and music, the most interesting is the next step

Switching computer screens

You should know that you are watching Doraemon at this time, you may be addicted to the music and have no time to change the computer screen, work this action is A typical trigger mode, suitable for the machine to do, to automate it!

We run a process on our computer, and this process is a Web service that can be invoked, and when it’s invoked (an HTTP request from Raspberry PI), our computer screen automatically switches to the iBook reading interface in milliseconds, and the teacher/parent comes in and sees you reading a book, Because you haven’t recovered from the animation, you must be staring at the book on the screen. The teacher was glad to leave

This is before opening your screen:

Oh no, wrong picture:

This is your screen after the door opens:

The source code for this web service is here: pc_server, which involves a very short code of just a few lines:

@app.route('/study')
def study() :
    print('to study')
    command = ["open"."/Applications/iBooks.app"] 
    subprocess.call(command)
    return 'study'

With raspberry PI Guardian, you can do everything on your computer without having to lock your door