prabeen
Published © GPL3+

Arduino Nano BLE 33 Sense Game Controller

I made this game controller by using Arduino Nano BLE 33 Sense which has onboard proximity sensor

BeginnerProtip1 hour469
Arduino Nano BLE 33 Sense Game Controller

Things used in this project

Hardware components

Nano 33 BLE Sense
Arduino Nano 33 BLE Sense
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Arduino Code

C/C++
#include <Arduino_APDS9960.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!APDS.begin()) {
    Serial.println("Error initializing APDS9960 sensor!");
  }
}

void loop() {
  // check if a proximity reading is available
  if (APDS.proximityAvailable()) {
    // read the proximity
    // - 0   => close
    // - 255 => far
    // - -1  => error
    int proximity = APDS.readProximity();
    if (proximity==0){
         Serial.println('d');
      
    }

    // print value to the Serial Monitor
 
  }

  // wait a bit before reading again
  delay(100);
}

Python Code

Python
import serial
from pynput.keyboard import Key, Controller
ser = serial.Serial('COM5', 9600)
keyboard = Controller()
while True:
    data = ser.readline()
    
    if data.decode().strip() == "d":
        keyboard.press("d")
        keyboard.release("d")

Arduino and Python Code

Credits

prabeen
4 projects • 1 follower
Engineering In India , Electronics Hobbist , Work With Arduino
Contact

Comments

Please log in or sign up to comment.