This project has primarily three functionalities i.e. to find the percentage of CPU utilised, to check the CPU percentage is above threshold and to turn on/off the green and red LEDs accordingly. When the CPU percentage is above threshold, the red LED turns on and the green turns off. When the CPU percentage is below threshold, the green LED turns on and the red LED turns off. This way, the CPU could shout out at you and flash LEDs every time it's feeling stressed out.
On the breadboard, the Green LED's positive leg is connected to digital pin 0 through a resistor of 330 ohms and a male/male jumper wire. The Green LED's negative leg is connected to GND through a male/male jumper wire. The Red LED's positive leg is connected to digital pin 1 through a resistor of 330 ohms and a male/male jumper wire. The Red LED's negative leg is connected to GND through the same male/male jumper wire which connects the Green LED to GND.
After the circuit connection is over, plug in the circuit to a laptop/PC or a power source using USB cable and setup your bolt device using the Bolt IoT Android/iOS app.
Copy the API Key and the Bolt Device ID after setting up your Bolt IoT Cloud account from the dashboard. Before we start coding of the CPU stress level in python, we need to make a configuration file which will have the specific keys for each user/device. We will import this file in our main code and use the attributes - API_KEY and DEVICE_ID which are the same API Key and the Bolt Device ID which are copied from the dashboard.
The following is the configuration file (named as conf.py):
API_KEY = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" # Bolt Cloud API Key
DEVICE_ID = "BOLTXXXXXXX" # Device ID of the Bolt Module
The main code file is named as cpu_stress_level.py given in the Code section. It implements all the three functionalities of the project as mentioned in the Introduction. Run the Python script on your machine by running the below command on your PC or remote server.
python cpu_stress_level.py
4. Demonstration4.1. OutputScreenshots of Python Code (CPU is not under stress)
4.2. OutputScreenshots of Python Code (CPU isunder stress)
Comments