Switching LED ON and OFF has been existing for many years. As time passed, IoT has made it possible to control devices in a smart way. Now people are not only able to control the LED state but also LED intensity using the PWM technique. In this article, we will see a project on how to control LED and its brightness from one’s mobile or laptop using the Bolt IoT platform.
First, let’s know what PWM is –
- Pulse width modulation(PWM) is a technique for producing an Analog output through a digital GPIO pin by controlling the width of the pulse generated.
Using PWM we can write the Input from a range of ‘0-255’.
software and components used for LED Intensity Control:
s.no | Component | Type |
1 | Bolt cloud | software |
2 | Bolt Wi-Fi module | Hardware |
3 | LED | Hardware |
Bolt Wi-Fi module:
The BOLT Wi-Fi Module is an ESP8266 based self-contained SOC with an integrated TCP/IP protocol stack that can give any microcontroller access to your Wi-Fi network. This module has a powerful enough on-board processing and storage capability that allows it to be interconnected with the sensors and other application-specific devices through its GPIOs.
HARDWARE CONNECTION:
Connections are quite simple.
- Power up the Bolt Wi-Fi module by a USB cable.
- Now insert the positive terminal of LED into ‘0’ pin and the negative terminal of LED into the ground pin.
SOFT-WARE CONFIGURATION:
let’s see the coding part or software configuration of the project,
- Firstly,sign-in to your Bolt Cloud.
- Then set-up your Wi-Fi module. ( click here to know how).
- Now create a new product and give a name to it.
- As you control the LED, select the type of device as an output device and collect data using Gpio pins.
- Now the product is created. Link it with your Bolt Wi-Fi module.
- Select configure product.
- In the hardware, section select ‘0’ pin and give a variable name
- Select code to begin.
CODE EXPLANATION:
The coding is done using HTML and JavaScript. Its detailed explanation is below.
- Write a basic Html layout page with a title and a range input slider with id as ‘PWM Value’ and range of slider from 0 to 255, and an initial value.
In the input tag, the mentioned settings are used:
- Type – To specify the type of input
- Id – To give an id for the input
- Min – Specify the min value of the slider
- Max – Specify the max value of the slider
- Value – It is the value of the slider, which is used to access slider data
- Update two JavaScript codes which describe the functions and the working of code
- First JavaScript code is used to import functions from “https://cloud.boltiot.com/static/js/boltCommands.js“
- setInterval – To run a function after a certain amount of time.
- analogWrite(pin, value) – To write PWM output in the pin specified
- Create a div block with ID to display real-time brightness of the LED
- Second JavaScript code is to write our code for the project, which continuously monitors slider input and updates light intensity every 1 sec.
Complete code:
Now, it’s time to run the code and control the LED.
As coding is complete, save it and deploy the configuration to the wifi module. To control the LED click on view this device which will open the webpage created.
- Deploy configuration
- View this device
Webpage control of circuit:
You can adjust the slider to control the intensity of the LED, and the real-time brightness will be displayed. For a better understanding, check out our video on Youtube.
Click here to watch – Led Intensity Control
CONCLUSION:
We hope you enjoyed doing this. In this article, We have seen what is PWM and how to achieve it, and the components needed, circuit connection, software configuration, coding required for controlling LED intensity using the Bolt IoT platform.
Written by: Batta Pruthvi
If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs