Ever wanted to control the Intensity of the LED and change the Buzzer sound connected to the Bolt at once. This Project is all about that. Here, we not only change the intensity of the LED connected to the Bolt IoT but also change the sound of the Buzzer connected to the Bolt IoT with using something known as PWM (Pulse Width Modulation) so, lets get started.
Step 1: Connection of LED and BUZZER with Bolt wifi moduleyou need to connect the LED +ve terminal (longer leg) to the GPIO 1 and -ve terminal of the LED (shorter leg) to GPIO 2 of the Bolt IoT as shown in the image below
Note: To switch on the LED we have to set the GPIO 2 of Bolt IoT to LOW, then we can switch the LED ON or OFF by changing the value of GPIO 1 to HIGH or LOW
now let's connect the buzzer to the Bolt IoT for this, connect the +ve terminal (longer leg) of the buzzer to the GPIO 0 -ve terminal (shorter leg) of the buzzer to the GND pin of Bolt IoT.. You can use the male/female jumper wires to do the connections as I've used.
after making the connections the circuit should look like the circuit shown in the image below.
after making connections we have to put our attention towards coding which is our next section
Step 2: Codinglogin to your account on bolt cloud which you can visit at https://cloud.boltiot.com
after login follow the following steps:
- Create Product by navigating to the product page
- choose the output device and GPIO in the options and move over to the code tab
Now, after creating the product move over to the code tab and choose the file type as HTML and give it a suitable name then paste the following code:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Variable Pin Control</title>
<style>
body{background-color:grey;}
.centerTxt{text-align: center;}
.centerBtn{width: 6em; margin-left: auto; margin-right: auto;}
.centerRng{width: 17em; margin: 0 auto;}
</style>
<script src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
</head>
<body>
<script>
setKey("{{ApiKey}}", "{{Name}}");
digitalWrite(2, 'LOW'); //to light up the let at pin 1 we have to set pin 2 to 0
function setAnalogOutput(rangeId, pin){
let value = document.getElementById(rangeId).value;
analogWrite(pin, value);
}
function setOutput(rangeId, rangeOutput){
let value = document.getElementById(rangeId).value;
document.getElementById(rangeOutput).value = value;
}
</script>
<h1 class="centerTxt">Led and Buzzer Controller</h1>
<div>
<h2 class="centerTxt">LED Control at GPIO 1</h2>
<div class="centerBtn">
<input type="button"
value="ON"
onclick="digitalWrite(1, 'HIGH');"/>
<input type="button"
value="OFF"
onclick="digitalWrite(1, 'LOW');"/>
</div>
<p class="centerTxt">Choose your value for the output voltage 0 is OFF and 255 is FULL INTENSITY</p>
<div class="centerRng">
<input type="range"
id="range1"
min="0"
max="255"
value="128"
onchange="setOutput('range1', 'output1')">
<output id="output1"></output>
<button type="buttokn" onclick="setAnalogOutput('range1', 1)">Make Request</button>
</div>
</div>
<div>
<h2 class="centerTxt">Buzz Controll at GPIO 0</h2>
<div class="centerBtn">
<button type="button" onclick="digitalWrite(0, 'HIGH')">ON</button>
<button type="button" onclick="digitalWrite(0, 'LOW')">OFF</button>
</div>
<p class="centerTxt">Choose your value for the output voltage 0 is OFF and 255 is FULL INTENSITY</p>
<div class="centerRng">
<input type="range"
id="range0"
min="0"
max="255"
value="128"
onchange="setOutput('range0', 'output0')">
<output id="output0"></output>
<button type="button" onclick="setAnalogOutput('range0',0)">Make Request</button>
</div>
</div>
</body>
</html>now the save the code and close the editor. by clicking the close button.
Step 3: Running the code by linking the bolt to the productnow after closing the editor by clicking the close icon choose the link icon and link your Bolt IoT wifi module to the product we've just created.
to get the control page you have to click on the view device icon which is located on the device details in your dashboard or where ever the device is shown. When you click the view device button, you will be directed to the following page:
On this page you can choose different intensity of the LED by choosing the value using slider and then making request of just by simply clicking the ON or OFF buttons.










Comments