# 'Too Close to the Screen' Alarm

1,129

11

## Introduction: 'Too Close to the Screen' Alarm

This is an alarm that alerts the user if they are staring at a computer screen too close and too long. It uses an ultrasonic depth sensor mounted just above the laptop's webcam to check if there's a person in front of it and how long they have been 'glued' to it. If it's too close or too long, it will sound an alarm continuously and annoyingly until you move away from it!

As a software develop I spend the majority of my day staring at the computer screen. When I get home, due to my slight internet addiction problem, the first thing I do is crack open my laptop. In total I probably spend 16 hours in front of a computer screen, so I wanted an alarm that tells me if I get too close to it to prevent further damage to my already poor eyesight.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Connections

Follow the following table for the connections that are made between the peripherals (Ultrasonic and Buzzer) and the Arduino board.

I/OPin #Arduino Pin #
Buzzer*16
Buzzer*2GND**
Ultrasonic Trig 9
UltrasonicEcho10
UltrasonicVCC3.3V
UltrasonicGNDGND**

* In any order - no order constraint.

** There are at least 3 GND pins on the Arduino board

## Step 2: Code

`// defines pins numbers`
```const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 6;```
```// defines variables
long duration;
int distance;
int safetyDistance;```
```void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);```
```  safetyDistance = 100;
tone(buzzer, 2500);
delay(500);
tone (buzzer, 2500);  ```
```Serial.begin(9600); // Starts the serial communication
}```
`void loop() {`
```// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);```
```// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);```
```// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);```
```// Calculating the distance
distance= duration*0.034/2;```
```if (distance <= safetyDistance){
tone(buzzer, 2500);
delay(500);
tone (buzzer, 2500);
}
else{
noTone (buzzer);
}```
```// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(dist);
}```

## Step 3: Mount

Tape the Arduino to the back of your Laptop.

Tape the Ultrasonic sensor just over your webcam. It would naturally balance there due to the overhang but it's safer to tape the wires securely so it doesn't move.

Lastly, tape the buzzer onto the corner of the laptop.

## Step 4: Done!

Hang it on your laptop or computer monitor and start using your computer healthier!

Live long and Prosper!

Participated in the
Makerspace Contest 2017

158 11K
92 8.9K
203 14K