1

I have recently bought Raspberry Pi and equipped it with temperature sensor DS18S20.

I would like to put this Raspberry in my server room so that measures temperature in it (that's not the hardest part). I wanted to connect a touch switch to the this Raspberry. So I could touch the switch and it goes through to the Raspberry which enables a circuit or disables it; This will lead to a door opening. It will also need to make a record with a date and time when this switch has been touched.

I have searched through the network for a long time and here I am.

Does anyone know any tutorial for something similar?

  • 1
    Very good project idea. Welcome the Pi Question and Answser. I doubt there will be one tutorial for this. You might have to try step by step and ask specific questions. Most will not be related to the Pi. BUt maybe programming, Robotics or Electronic Engineering. – Piotr Kula Sep 11 '13 at 13:42
2

The touch buttons are "active low" so you connect 3.3V to button's VCC, GND to button's GND and any standard GPIO to button's OUT. In your program that is to run this, you configure this to a pulled up input. For example, if you choose to write the application in shell, using the WiringPI gpio utility, and connect the output to GPIO 0 (pin 11), the commands will be

 gpio mode 0 in
 gpio mode 0 up

Now, to test, issue:

 gpio read 0

It should output "1" when the button is not touched, "0" while you're touching it.

To drive the door lock, you will need signal stronger than what the pins can provide. You probably could do it with some triac or something like that, but I'd rather recommend a relay board, like this one.

Connect VCC to +5V power (if your RPi USB power supply is strong enough - at least 1000mA - you can use the +5V pin on the RPi board. If not, get any other 5V power supply.) Connect GND to GND of that power supply (or RPi if you use RPi +5V pin). In case you use a separate power supply, remove the jumper and connect COM to any GND on the RPi board. Connect IN1 to any GPIO pin, say, GPIO 1 (pin 12).

To configure the output issue:

 gpio mode 1 out

Test if you can switch the relay. Audible click should be heard and a LED is lit on the relay board:

gpio write 1 1
gpio write 1 0

Now that you have it working, time to attach it to the electric door lock.

You need an electric door strike installed in your door. Most door locks are powered by 12 or 24V and you need to provide that from yet another power supply. You connect in line: +12V - lock "in" ; lock "gnd" - relay board "in" screw (central screw of first relay) ; relay board "N/O" screw (right screw of first relay) - GND of power supply.

Since you want your door to remain unlocked for several seconds after the button is pressed, we'll introduce a function that does it.

  #!/bin/bash 

  function unlock {
           date >> /var/log/door.log
           gpio write 1 1
           sleep 5
           gpio write 1 0
  }

  gpio mode 0 in
  gpio mode 0 up
  gpio mode 1 out
  gpio write 1 0

  while `true` ; do
     [  `gpio read 1` -eq "0" ] && unlock
     sleep 1
  done

Test if it works and launch it in background from one of startup scripts.

| improve this answer | |
  • Wow, thanks for you answer, I will test it as soon as possible. I found this tutorial, do you think this one would work too? raspberrywebserver.com/gpio/… – user2768573 Sep 12 '13 at 7:34
  • @user2768573: Yes, although it covers maybe 30% of the problem: just reading the button. Lock actuator is much more of a problem. Also note, that tutorial uses external pull-up. You don't really need to do that, you can just activate the built-in one by setting the input up with GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP) instead. – SF. Sep 12 '13 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.