Devices & Components
Arduino Uno Rev3
Ultrasonic Sensor
Arduino USB 2.0 CABLE TYPE A/B 1M
Hardware & Tools
Power Supply
Cardboard, markers, scissors, cutter
Breadboard, 170 Pin
Software & Tools
TINKERCAD
Python IDLE
Arduino IDE
tinkercad circuits
Project description
Code
Python Code - For Computer
python
Run this on computer, this will switch Tabs
1import serial 2import time 3import subprocess 4 5chrome_path = "C:\Program Files\Google\Chrome\Application\\chrome.exe" 6 7url="https://en.wikipedia.org/wiki/Neural_network_(machine_learning)" 8url="https://docs.arduino.cc/language-reference/en/functions/communication/serial/print/" 9url="https://docs.python.org/3/tutorial/controlflow.html#the-range-function" 10 11threshold=50 12 13try: 14 ser = serial.Serial('COM21', 9600, timeout=1) 15except Exception as e: 16 pass 17 print(e) 18 19while True: 20 21 try: 22 key = ser.readline().decode().strip() 23 key = int(key) 24 25 26 if key<=threshold: 27 subprocess.run([chrome_path,"--new-window", "--incognito", url]) 28 print(key) 29 break 30 31 except Exception as e: 32 pass 33 34 35 36print("done")
Arduino Code
js
Arduino Code
1int d; 2int t = 8; //trigger 3int e = 9; //echo 4 5 6void setup() { 7 pinMode(t, OUTPUT); //trigger pin 8 pinMode(e, INPUT); //echo pin 9 10 Serial.begin(9600); 11} 12 13float distance(){ 14 15 float duration, cm; 16 17 digitalWrite(t, LOW); 18 delayMicroseconds(2); 19 digitalWrite(t, HIGH); 20 delayMicroseconds(5); 21 digitalWrite(t, LOW); 22 23 duration = pulseIn(e, HIGH); 24 25 cm = duration/ 29 / 2; 26 27 return cm; //returns distance in centimeters 28} 29 30void loop() { 31 32 int dis = distance(); 33 Serial.println(dis); 34 delay(50); 35 36 37}
Downloadable files
Arduino Switch Tab With Ultrasonic Sensor
CAD design of the environment for this setup
Arduino Switch Tab With Ultrasonic Sensor.stl
Documentation
Circuit DIagram Of Arduino Switch Tab With Ultrasonic Sensor
Arduino and ultrasonic sensor to control laptop
Arduino Switch Tab With Ultrasonic Sensor.pdf
Comments
Only logged in users can leave comments