Shivali Bhagat
Published © GPL3+

Lappy battery alert and CPU usage

This is the project which gives laptop battery alert via buzzer and also notify heavy cpu usage using LED.

BeginnerFull instructions provided2 days387
Lappy battery alert and CPU usage

Things used in this project

Story

Read more

Custom parts and enclosures

Lappy battery alert and CPU usage

Schematics

Lappy battery alert and CPU usage

Code

Lappy battery alert and CPU usage

Python
import psutil
from boltiot import Bolt
api_key = "def66fbf-e033-403c-a4eb-16fa5bde5bc4"
d_id = "BOLT7422217"

buzzer = Bolt(api_key, d_id)

interval = 3
alert_battery = 20
alert_cpu = 80.0

def control_buzzer(pin, value):
    response = buzzer.digitalWrite(pin, value)

def control_buzzer_frq(pin, value):
    response = buzzer.analogWrite(pin, value)

def control_led(pin, value):
    response = buzzer.digitalWrite(pin, value)
    
while True:
 cpu_alert = psutil.cpu_percent(interval = interval)
 print ("CPU usage is", cpu_alert)
 if cpu_alert > alert_cpu:
     control_led('1','LOW')
     control_led('2','HIGH')
 else:
     print ("Less utilization")
     control_led('1','LOW')
     control_led('2','LOW')
 battery = psutil.sensors_battery()
 plugged = battery.power_plugged
 percent = str(battery.percent)
 if alert_battery >= int(percent):
     if plugged==False:
         print ("Not Charging alert will generated and Buzzer will sound!!!!")
         control_buzzer('0','HIGH')
     else:
         print ("Charging alert will not generated...")
         control_buzzer('0','LOW')      
 else:
     print ("Charging is sufficient")
 battery = psutil.sensors_battery()
 Battery = battery.percent
 if Battery == 100:
     print("Battery Full")
     control_buzzer_frq('0','50')    
    

Credits

Shivali Bhagat
1 project • 0 followers

Comments