Sidharth Parth Sarathi
Published © GPL3+

Laptop Screen Brightness Manager(Windows OS)

The goal of the project is to control the brightness level and notify the user about the change in brightness level using Bolt Iot System.

BeginnerFull instructions provided4 hours302
Laptop Screen Brightness Manager(Windows OS)

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×5
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Buzzer
Buzzer
×1
Mini Breadboard
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
You Should Upgrade Your Free Bolt Cloud account to Pro in order to get a better API access. Visit below link to know more about API Access Limits https://docs.boltiot.com/docs/api-access-rules
Bolt IoT Android App
Bolt IoT Android App
Windows 10
Microsoft Windows 10
Integrated Development and Learning Environment(IDLE)
Bolt Iot Python Library
VS Code
Microsoft VS Code
Optional If You're Using Python's (IDLE) Integrated Development and Learning Environment.
Windows Command Prompt(cmd)
Optional If you're executing your code through Python's IDLE(Integrated Development and Learning Environment)
Screen Brightness Control Module

Story

Read more

Schematics

Hardware Connections to Breadboard and Bolt Iot System

Longer end of the buzzer is Positive and Shorter end in Negative.
1)Connect the LDR as shown in the diagram.
2)Use 10k Resistor.
3)Always Connect Shorter end to GND pin and Longer end to pin 1(In this project longer end is connected to pin 1,but you can connect to any other GPIO digital pin of the bolt iot module).buzzer doesn't require a resistor.
4)the circuit connection requires,5 separated male/male jumper wires

Getting API Key,Device Id From Bolt Cloud and Connecting Device to Bolt Cloud

Steps(To get API Key And Device Id):
1) Type www.cloud.boltiot.com on googlce chrome or any web browser you're using.then press enter.
2) Click on "SignUp” if you haven't registered and do registration.Otherwise,Log in to bolt cloud with your user name and password.
3) After Successfully Logging,Get your Bolt Device Id From Devices Tab and Hardware Module Section.remember it or do copy and paste it in a separate notepad file.
4)Again in the API Tab,Click on Manage Your Api Key.Enable your Api Key And do copy and paste it in the same notepad file as mentioned in step 3.

Steps(Connecting Device to Bolt Cloud):
1)Download Bolt Iot Android App from google (playstore.https://play.google.com/store/apps/details?id=com.bolt.com.bolt&hl=en_IN&gl=US)
2)Then,Login to the cloud.
3)Open the Bolt Iot Docs and complete the steps.
(https://docs.boltiot.com/docs)

Installation of Python And Extra Modules

Steps:
1)Download the required version of Python for your device From https://www.python.org/downloads/windows/ and install it.
2)while installing Never Forget to Click on Add To Path.
3)You Can use VS Code Editor or Python's Integrated Development and Learning Environment.to use Python's IDLE,
Add This Path to Environment Variable in order to open IDLE from command line.
C:\Users\Your_User_Name\AppData\Local\Programs\Python\Python-Version\Lib\idlelib
replace Your_User_Name with your computer's User Name and replace Python-Version with the version you've installed.for example for python 3.8.5 folder name is Python38.
4)Open Command Prompt.
i) For installing boltiot module,type
pip install boltiot
then press enter.internet is required to install this package.
ii) For installing Screen-Brightness-Control Module,type
pip install screen-brightness-control
then,press enter.it will download and install the package from internet.
5)Then in command prompt change the directory in which you want to save your code.for changing the directory type,
cd Your_Path
replace Your_Path with the folder location.press enter.
6)To Create a python file,type
idle Brightness_Manager.py
Brightness_Manager is the name of the file and .py is the extension of python file.
you can replace the name of the file with whatever name you want.
remember the syntax is:idle File_Name.py
6)It will Open the IDLE.

Writing Code in IDLE

Steps:
1)Write the code
2)Save it by pressing CTRL+S
3)You can run your code through cmd or idle
i)in cmd,type
python File_Name.py
or File_Name.py
replace File_Name with the file name.then,press enter.
ii)in idle,go to Run, then Click on Run Module or you can press F5 to run your code.

Note:
Visit the following link to know more about screen-brightness-control
https://www.geeksforgeeks.org/how-to-control-laptop-screen-brightness-using-python/

Code

Brightness_Manager

Python
#Import Required Modules
import time,json,screen_brightness_control as sbc 
from boltiot import Bolt

#Api Key can be obtained from your bolt cloud account 
api_key = "########-####-####-####-############"

#Device Id can be obtained from your bolt cloud account 
device_id  = "##########"

#Initializing Bolt Class
mybolt = Bolt(api_key, device_id)

#Minimum Brightness Of Your Screen
minm_br=6

#Infinite Loop
while True:
   
   #Test a block of code for errors
   try:

      #get the current level of brightness
      a=sbc.get_brightness()
      print("Current Brightness Value:",a)

      #store the data in json format
      response =json.loads(mybolt.analogRead('A0'))

      #store the value of the response in a variable
      c=response['value']

      #check if it is a number or not
      if(c.isnumeric()):
         print("Light Sensor Value Is:",c)

         #conver the light sensor value to match the brightness level
         b=int(int(c)*(100/1024))
         print("Converted Value Of Light Sensor Is:",b)

         #assign the value of b to br for future use
         br=b

         #check if sensor value is less than brightness level and according to that decrease the brightness
         if(b<a):

            #minimum level of brightness is 6
            if(a!=minm_br):
               if(b<minm_br):

                  #minimum brightness can't be below 6 in windows
                  br=minm_br
               print("Your Brightness Will Be Decreased To:",br)

               #to produce a low frequency sound when brightness decreases
               mybolt.analogWrite('1','120')
               time.sleep(0.7)

               #off the buzzer after 0.7 seconds
               mybolt.digitalWrite('1','LOW')
               if(b<7):
                 
                  #For Decreasing Brightness
                  for i in range(a-1,minm_br-1,-1):
                     
                     #Set brightness
                     sbc.set_brightness(i)
               elif(b>minm_br):
                  
                  #For Decreasing Brightness
                  for i in range(a-1,int(b)-1,-1):

                     #Set brightness
                     sbc.set_brightness(i)

         #check if sensor value is more than brightness level and according to that increase the brightness
         elif(b>a):
            print("Your Brightness Will Be Increased To:",int(b))

            #to produce a high frequency sound when brightness decreases
            mybolt.analogWrite('1','255')
            time.sleep(0.7)

            #off the buzzer after 0.7 seconds
            mybolt.digitalWrite('1','LOW')
            if(b>minm_br):
              
               #For Increasing Brightness
               for i in range(a+1,int(b)+1):

                  #Set brightness
                  sbc.set_brightness(i)

      #if value of response is in string format then print it            
      else:
         print(c)

         #check for the condition "Command timed out" and allow buzzer to buzz
         if(c=="Command timed out"):
            mybolt.digitalWrite('1','HIGH')
            time.sleep(2)
            mybolt.digitalWrite('1','LOW')

   #Handle the errors
   except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)

   #Puts the program execution on hold for 1 second
   time.sleep(0.7)

Credits

Sidharth Parth Sarathi

Sidharth Parth Sarathi

1 project • 0 followers

Comments