harshitmehra2007
Published © GPL3+

eye protector

It is a project made to reduce the brightness of the computer screen based on the distance of us from the screen

BeginnerFull instructions provided364
eye protector

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The connections

Here are the connections you can see them for further clearfication

Code

The code

C/C++
 int trigPin = 9; //Trigger pin of 1st Sesnor
 int echoPin = 8; //Echo pin of 1st Sesnor

 
float duration_us, distance_cm;// variable for the distance_cm measurement

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
  Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
  Serial.println("with Arduino UNO R3");
}
void loop() {
 digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // measure duration of pulse from ECHO pin
  duration_us = pulseIn(echoPin, HIGH);

  // calculate the distance_cm
  distance_cm= 0.017 * duration_us;

  // print the value to Serial Monitor


  delay(500);
 if ((distance_cm=60)&&(distance_cm<50))
 {
  Serial.println("Increase Brightness alittle");
 }
else if(distance_cm>=100){
  Serial.print("Maximum Brightness Object too far");
 }
else if(distance_cm<=30){
  Serial.println("Decrease Brightness");
 }
else if(distance_cm<=20){
  Serial.println("Decrease even more");
 }
 else if(distance_cm<=10){
  Serial.println("Zero brightness");
 }
 else {
  Serial.println("No INPUT");
 }
}

Python code

Pascal
import serial #Serial imported for Serial communication
import time #Required to use delay functions
import screen_brightness_control as sbc
ArduinoSerial = serial.Serial('com4',9600) #Create Serial port object called arduinoSerialData
time.sleep(2) #wait for 2 seconds for the communication to get established
print("working")
current_brightness = sbc.get_brightness()
print(current_brightness)
while 1:
    incoming = str (ArduinoSerial.readline()) #read the serial data and print it as line
    print (incoming)
    
    if 'Increase Brightness alittle' in incoming:
         sbc.set_brightness(60)

    if 'Maximum Brightness' in incoming:
        sbc.set_brightness(100)

    if 'Maximum Brightness Object too far' in incoming:
         sbc.set_brightness(100)

    if 'Decrease Brightness' in incoming:
        sbc.set_brightness(40)
        

    if 'Decrease even more' in incoming:
        sbc.set_brightness(30)

        
    if 'Zero brightness' in incoming:
        sbc.set_brightness(0)

    incoming = "";
    



    

Credits

harshitmehra2007
3 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.