I am trying to use arduino with my laptop (Ubuntu-gnome 16.04 installed) to control the screen lock using RFID Module (Screen lock/unlock is controlled by an RFID card)

Here in this particular case, I trigger some action in arduino (swiping of RFID card) which should be able to perform the following tasks:

  1. Lock the screen.
  2. Unlock the locked screen (obviously without asking for password).

I want to get task number 2 done.


Figured a way out.

Keep a python script running at the background and use the serial library in python to connect to a particular serial port. Now serial write the data from arduino whenever the desired action in executed in arduino. Read the value written on serial in python script and based on that value execute shell command for locking and unlocking the system, which are as follows:

gnome-screensaver-command -l (to lock)

gnome-screensaver-command -d (to unlock)

Python code:

import serial, os
port_name = '/dev/ttyACM0' # Change accordingly
arduino = serial.Serial(port_name, 9600)
while True:
    word = str(arduino.readline())
    if word == 'l': # Lock the screen
        os.system('gnome-screensaver-command -l')
    elif word == 'u': # Unlock the screen
        os.system('gnome-screensaver-command -d')

Now using Serial.write() function of arduino, write 'l' or 'u' on the serial based on your requirement (RFID Swipe as in my case).

Happy Hacking :-)

  • it gives me that /dev/tty* device is busy which Arduino is listening. Should I bring up another serial for this script? – Novitoll May 5 '18 at 12:08
  • mutliple serials are possible in Arduino Mega and higher, did you get this working with Arduino Uno R3? – Novitoll May 5 '18 at 12:09

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.