Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Robotics EveryDay
Published © GPL3+

The Auto-Tab Switcher | Ultrasonic Savior

Ultrasonic sensor, microcontroller, and Python auto-switch tabs/software, ensuring privacy and versatile control over devices.

BeginnerFull instructions provided2 hours58
The Auto-Tab Switcher | Ultrasonic Savior

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE
Python IDE

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical
Scissor, Electrician
Scissor, Electrician

Story

Read more

Custom parts and enclosures

CAD Design of the whole setup

Sketchfab still processing.

Schematics

Circuit Schematic

Code

Arduino Code

Arduino
Code to get the distance from ultrasonic sensor and send it serially to computer
int d;
int t = 8; //trigger
int e = 9; //echo


void setup() {
  pinMode(t, OUTPUT);  //trigger pin
  pinMode(e, INPUT);  //echo pin

  Serial.begin(9600);
}

float distance(){
  
  float duration, cm;
  
  digitalWrite(t, LOW);
  delayMicroseconds(2);
  digitalWrite(t, HIGH);
  delayMicroseconds(5);
  digitalWrite(t, LOW);
  
  duration = pulseIn(e, HIGH);

  cm = duration/ 29 / 2;
  
  return cm; //returns distance in centimeters
}

void loop() {
  
  int dis = distance();
  Serial.println(dis);  
  delay(50);

  
}

Python Code To Control Computer

Python
Run this code on computer, it will get data from arduino and do actions on computer
import serial
import time
import subprocess

chrome_path = "C:\Program Files\Google\Chrome\Application\\chrome.exe"
url="https://docs.arduino.cc/language-reference/en/functions/communication/serial/print/"
url="https://docs.python.org/3/tutorial/controlflow.html#the-range-function"

threshold=50

try:
    ser = serial.Serial('COM21', 9600, timeout=1)
except Exception as e:
    pass
    print(e)

while True:
    
    try:
        key = ser.readline().decode().strip()
        key = int(key)

        if key<=threshold:
            subprocess.run([chrome_path,"--new-window", "--incognito", url])
            print(key)
            break
        
    except Exception as e:
        pass
        
print("done")

Credits

Robotics EveryDay

Robotics EveryDay

3 projects • 9 followers

Comments