LED Intensity Control

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.noComponentType
1Bolt cloudsoftware
2Bolt Wi-Fi moduleHardware
3LEDHardware

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. 

  1. Power up the Bolt Wi-Fi module by a USB cable.
  2. 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,

  1. Firstly,sign-in to your Bolt Cloud
  2. Then set-up your Wi-Fi module. ( click here to know how).
  3. Now create a new product and give a name to it.
  4. As you control the LED, select the type of device as an output device and collect data using Gpio pins.

  1. Now the product is created. Link it with your Bolt Wi-Fi module.
  2. Select configure product.
  3. In the hardware, section select ‘0’ pin and give a variable name
  4. Select code to begin.

CODE EXPLANATION:

The coding is done using HTML and JavaScript. Its detailed explanation is below.

  1. 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
  1. Update two JavaScript codes which describe the functions and the working of code
  2. 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
  1. Create a div block with ID to display real-time brightness of the LED
  2. 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

Leave a Comment

Your email address will not be published. Required fields are marked *