Vibrating and Beeping Keyboard

by scuffed_braggers in Circuits > Arduino

150 Views, 0 Favorites, 0 Comments

Vibrating and Beeping Keyboard

Screenshot 2022-05-23 11.10.06 AM.png
BoxAltog1.png

Using technology may be a huge struggle for many individuals with sensory disabilities. Unfortunately, adaptive technology can be very expensive. A keyboard that vibrates and beeps when each keystroke is detected can help connect the motion pushing a button to a physical feeling and sound.

This program, while running, will detect key presses. It will play a beep sound, as well as send a signal to a custom USB device, activating a vibration, when a key is pressed. The beep and buzz functions can be toggled on/off via the keys F7 and F8. If the USB device is not available/plugged in, only the sound effect will be played. There are four different beep sounds: letter, number, symbol, and control. The sounds play respectively to the type of key that has been pressed to help the user differentiate between the different keys. The files may be replaced with other preferred sound effects.

Supplies

Assembling the Vibrating Piece

VibratingPic4.png
VibratingPic3.png
VibratingPic2.png
VibratingPic1.png

In this step we will interface a vibration motor with Arduino.

The vibration motor is compact in size and vibrates on receiving signals.

Now, grab all 5 of the wires (all the wires are the same and can be used interchangeably).

1. Take your first wire and place it in the Arduino at 5V and its other end in the Relay Module at COM. *The voltage can be manipulated on the Arduino by placing the wire at a different voltage level

2. Take your second wire and place it in the Arduino at GND (next to the previous wire in 5V) and its other end in the Relay Module at DC+.

3. Take your third wire and place it in the Arduino at GND (next to the previous wire in GND) and its other end in the Relay Module at DC-.

4. Take your fourth wire and place it in the Arduino at 3 (on the opposite side as all of the previous wires) and its other end in the Relay Module at NI.

5. Take one of the wires from the vibration motor (should come attached) and plug it in the Arduino at GND.

6. Take one of the wires from the vibration motor (should come attached) and plug it in the Relay Module at NO.

Vibrating and Sound on Keystrokes

Now, we will detect keystrokes with vibrations.

The code (C++) below runs on Arduino to turn on the vibration motor for a set amount of time.

int incomingByte = 0;

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
}

void loop() {
  while (Serial.available() == 0) {}
    if (Serial.read() != -1) {
      digitalWrite(3, HIGH);
      delay(75);
      digitalWrite(3, LOW);
      Serial.println("Buzz");
    }
    Serial.println(Serial.available());
    Serial.println(Serial.read());
}

This program, while running, will detect key presses. It will play a beep sound or send a signal to a custom USB device, activating a vibration, when a key is pressed. Whether the program will prompt a beep or buzz can be toggled via the F7 key while the program is running. If the USB device is unplugged after the program begins, only the sound effect will be played. Occasionally, the program may encounter an error and crash. If this happens, simply restart the program. It isn't perfect, and we apologize for any inconvenience. The python code is listed below:

"""
spawns key press listener, plays audio notification and sends serial signal to vibrating motor device on key press
"""

#imports
from pynput.keyboard import Key, Listener
import serial
import serial.tools.list_ports
import time

#wait until port available
print("Waiting for USB...")
while serial.tools.list_ports.comports() == []:
    time.sleep(1)

#initialize variables
print("Initializing...")
port = serial.tools.list_ports.comports()[0]
port = str(port[0]).split()[0]
serialDevice = serial.Serial(port, 9600, timeout = 0.1)
buzz = True
times = {
    "lastInput": 0
}

def onInput(key):
    """
    runs on key press
    sends buzz if enabled and prints the result, OR toggles buzz setting if F7 key is pressed
    """
    #check time since last input, skip output if it is less than 1 second
    if time.time() - times["lastInput"] < 1:
        return None
    times["lastInput"] = time.time()
   
    #toggle buzz if toggle button was pressed, exit function
    if str(key) == "Key.f7":
        global buzz
        buzz = not buzz
        if buzz:
            print()
            print("BUZZ ENABLED", "\n")
        else:
            print()
            print("BUZZ DISABLED", "\n")
        return None
       
    #turn key into properly formatted string
    key = str(key)
    if "." in key:
        key = (key.split(".")[1]).upper()
    else:
        key = (key.split("'")[1]).upper()
       
    #buzz, print results
    print()
    print("'" + key + "' was pressed.")
    if buzz and serial.tools.list_ports.comports() == []:
        print("Buzz not sent. (No USB detected)")
        return None
    if buzz:
        serialDevice.write(7) #vibration (external)
        print("Buzz sent.", "\n")
    else:
        print("Buzz not sent. (Buzz disabled)", "\n")

#confirm
print("Ready.")

#create listener
with Listener(on_press = onInput) as listener:
    listener.join()

#confirm
print("Program ready.")

HOW TO USE:

1. Download the latest version of Python from https://www.python.org/downloads/

2. Open a windows command prompt, and enter the following commands, consecutively:
pip install pynput
pip install pyserial
pip install playsound

3. Plug the custom USB device into your computer

4. Launch the Python program. You may be able to right-click the file and select "Open with", and then the version of Python you installed, or you may have to launch it using the command line.

5. Toggle the buzz/beep setting as you wish

6. Close the terminal when you are finished using the program

Assembling the Tray

BoxPic1.png
BoxPic2.png
BoxPic3.png
BoxMeasurements.png
BoxPic4.png

For this step we used makercase.com to create a laser-cut wooden tray. The measurements may change according to the keyboard, but for this project the outside measurements of our tray are set as width: 441.5 mm, height: 31.5 mm, and length: 158.5 mm. The material thickness is 3 mm, an opened box, finger joints, and finger size as 14.63.

During this process you may use the program to create a hole on the side of the tray to fit the size of your choice of USB cord. In this project we used a drill to drill a hole.

Downloads

Putting It All Together

BoxAltog2.png
BoxAltog1.png

Place the tray down with the open side facing up. Lay down the vibrating pieces inside and trace around them. Put the side of the Arduino with the USB cord closest to the edge for easiest use and access. Take the painter's tape and tape down all of the pieces inside the box in place.