Harsh Kaushal
Published © GPL3+

Drawer Light

Whenever you open a drawer, the LED connected to the Bolt will light up.

BeginnerFull instructions provided30 minutes465
Drawer Light

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LDR, 1 Mohm
LDR, 1 Mohm
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App

Story

Read more

Schematics

drawer lights

ldr to analog pin ,leds to digital pin

Code

drawer lights

HTML
the value of ldr is passed to a variable which is then checked if its greater or less than a fixed number if its greater then led will glow and if not then led will not glow
  <html>
    <head>
    <title>BOLT</title>
    <script type="text/javascript" src="/serveFile?filename=bolt.js"> setDebug(true);  </script>	
    <script>

        var output;
        var sensor_output;
        var sensor_output_array;
        var sensor_val;

        function start(){
    //the format of the digital or analog read provided in bolt.js is "Pin Value=x"
	// so instead of just writing my own ajax request or editing the js file like a normal person
	// i decided to do it like coz i was lazy
            digitalRead(3,"hidden");
            sensor_output= document.getElementById("hidden").innerHTML;
            sensor_output_array = sensor_output.split("=");
            sensor_val=sensor_output_array[1];

            if(sensor_val==0){
                document.getElementById("light").innerHTML ="something detected";
                digitalWrite(5,HIGH);
            }
            else{
                document.getElementById("light").innerHTML ="all clear";
                digitalWrite(5,LOW);

            }
            
    document.getElementById("output").innerHTML =sensor_val;

    //anything less than 2.5 seconds causes alot of problems for me.
// it hangs the board and i gotto restart it.
    //im assuming its because it take that long to handle one request but i might be wrong.
    //if anyone has a reason for this i would like to know
            setTimeout(start,3000);
    }


    </script>

    </head>
    <body bgcolor="#01FFFF" > 
    <center>
    <h3> Sensor data</h3>
    <span id="hidden" style="display: none"> </span>
    <span id="output"> </span>
    <p id="light"></p></center>
    <button onclick="start();">ON</button>
    </body> 
    </html>

Credits

Harsh Kaushal
2 projects • 0 followers

Comments