📜 ⬆️ ⬇️

Touch Sensor for Arduino and creepy paranoid admin device

An interesting library for organizing touch control was discovered here for Arduino: www.arduino.cc/playground/Main/CapSense .
The principle of operation is simple - we connect two any legs with a mega-ohm resistor for several, one leg will be the output, the second will be the input. We catch a wire sensor at the entrance, and even better, something flat and conductive - like a piece of copper foil. If the output is switched from 0 to 1 and vice versa, the input state will also switch, but due to various parasitic capacitances the process will take place with some delay, and the larger the capacity (say, the closer the human hand is), the greater this inertia. Here is an illustration from the author of the library:

image
The library hides all these switches and measurements of time from us - we get a convenient function:
capSenseRaw (foot_exit, foot_inv, number_measures).
In the course of experiments with the library and various pieces of hardware hooked to the Arduino, the idea of ​​a funny device was born in my fevered admin-paranoid mind, which I can imagine.
The point is this: place in a chair (on which the administrator spends his work time) a sufficient amount of wire and cover it with matter, connect the wire to the Arduino - let the piece of iron determine whether someone is sitting on the chair or not. And at that very moment, when the administrator leaves the workplace, the Arduino sends a signal to the computer, and that one automatically locks out.
... I can also play .wav like "work, negros! the sun is still high
Consider a draft version of the implementation of this idea, which turned out for me.
Iron
The most difficult was to find a resistor of about 10 MΩ. The farm was 2.2 MΩ - I soldered 4 of them in series - about 9 MΩ came out, but it looked ugly. I looked into the radio shop - I found resistors for 15 MΩ - I took a few pieces. We take a piece of matter, sew a wire to it, connect everything according to the scheme: I use Freeduino - an Arduino clone. They are fully compatible, i.e. there is no difference either electrically or programmatically.
Computer Software
The choice of language for writing a reciprocal part, working on a computer, was made by me in favor of Python - under Windows there is still no normal scripting language bundled in, and if it’s something to deliver, let it be a popular project with a wide community a lot of libraries
A bunch of examples, and normally ported under all more or less live OS.
For Python, there is a simple and convenient pySerial library for working with a COM port (Arduino is represented in the system with a COM port on the USB bus): pySerial .
In addition, under Windows you will need more pyWin32 After that, working with Arduino from Python is simplified to disgrace.
How to lock a car from a script?
Under Windows like this:
"Rundll32.exe user32.dll, LockWorkStation".
Under GNOME (I checked under Ubuntu 8.04) like this:
"Gnome-screensaver-command --lock" or this:
"Xdg-screensaver lock".
Under KDE, I didn’t search and I don’t know how - I think it’s also no problem
So, we have everything we need, it remains to put everything together.
The source for the Arduino with comments is here: CapSenseSrc.zip
The program is simple - when a man appears, Arduino writes “Hello!” To the port,
and when a man leaves, “Bye!”
The source code of the script on python, though it lies in the archive, but due to its simplicity, I will give here:
 --- AutoLock.py ---
 # - * - coding: windows-1251 - * -
 import serial
 import os

 ser = serial.Serial ('COM3', 9600) # Here you need to put your port
 while 1:
     s = ser.readline (). strip () # Read the line and remove the line breaks
 # print (s) # uncomment for debugging
     if s == 'Bye!': # if a person is gone, lock the system
         os.system ('rundll32.exe user32.dll, LockWorkStation')
 ---

Under Ubuntu, it worked successfully with changes in 2 lines:
the port opens like this:
 ser = serial.Serial ('/ dev / ttyUSB0', 9600)

The machine closes like this:
         os.system ('gnome-screensaver-command --lock')

A small video showing the work:

PS About my experiments with Arduino, I am still writing on the blog arduino-ru.blogspot.com , but there will be reports in the form of reports, and I plan to post more detailed descriptions on Habr with the analysis of source codes and schemes. In particular, I will be glad to do this if it is interesting to someone. Are there people in the audience who are close to software, but who want to understand a little bit of self-made hardware?
Or vice versa, those born with a soldering iron in their hands, but never got close to the microcontrollers? In general, I want feedback - waiting for comments good and different :)

')

Source: https://habr.com/ru/post/54763/


All Articles