Binny Naik
Published © GPL3+

Smart Alarm Clock with Automated Room Lighting

This Smart Alarm Clock wakes you on time, turns ON room's light AUTOMATICALLY when you STOP the alarm & send SMS when light is turned ON/OFF

BeginnerFull instructions provided1 hour325
Smart Alarm Clock with Automated Room Lighting

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
PHPoC Bread Board
PHPoC Bread Board
×1
Male/Male Jumper Wires
×5
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

Fritzing Schematic

It shows the hardware circuit connection

Code

Setting and Stopping Alarm, Turning ON and OFF light

HTML
This code enables to create the alarm clock wherein the alarm can be set and operated accordingly. Also the light can be switched ON/OFF here.
<!DOCTYPE html>
<html>
    <head>
        <title>Bolt IoT Platform</title>
        <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
        <script>setKey('{{ApiKey}}','{{Name}}');</script>
  
        <style>

            #tpick {
            margin: 0 auto;
            max-width: 350px;
            padding: 10px;
            background: black;
            white-space: nowrap;
            font-family: Arial;
            }
            
            #tpick select {
              box-sizing: padding-box;
              width: 100%;
              font-size: 1.2em;
              font-weight: bold;
              margin: 20px 0;
            }
            
            #tset, #treset, #onlight, #offlight {
              box-sizing: padding-box;
              width: 50%;
              background: red;
              color: #fff;
              padding: 10px;
              border: 0;
              cursor: pointer;
            }
            
            #tset:disabled, #treset:disabled, #onlight:disabled, #offlight:disabled{
              background: #aaa;
              color: #888;
            }
            
           .text {
              margin-top: 10px;
              color: #ddd;
           }
           
           .square {
              display: inline-block;
              padding: 10px;
              margin: 5px;
           }
           
        </style>
    </head>    
    
    <body>
     <div id="tpick">
      <h1 class="header" style="color:pink"><center>SET ALARM</center></h1>
      
      <center>
     
      <div class="square">
        <input type="number" id="hour" name="hour" min="0" max="23" step="1" value="00">
        <div class="text">Hr</div>
     </div>
     
     <div class="square">
        <input type="number" id="min" name="min" min="0" max="59" step="1" value="00">
        <div class="text">Min</div>
     </div>
     
     <div class="square">
        <input type="number" id="sec" name="sec" min="0" max="59" step="1" value="00">
        <div class="text">Sec</div>
     </div>
   
     </center>
     
     <br>
     
     <div>
        <input type="button" value="START ALARM" id="tset" onclick="get_confirm();this.disabled=true;treset.disabled=false;myVar = setInterval(timer,1000)"/>
        <input type="button" value="STOP ALARM" id="treset" onclick="clearInterval(myVar);this.disabled=true;tset.disabled=false;offlight.disabled=false;analogWrite('0','0');digitalWrite('1','HIGH');alert('Your alarm is stopped and rooms lights are turned on')" disabled/>
        <br><br><input type="button" value="ON LIGHTS" id="onlight" onclick="digitalWrite('1','HIGH');this.disabled=true;offlight.disabled=false;alert('Your rooms lights are turned on')" disabled/>
        <input type="button" value="OFF LIGHTS" id="offlight" onclick="digitalWrite('1','LOW');this.disabled=true;onlight.disabled=false;alert('Your rooms lights are turned off')" disabled/>
    </div>
    </div>
  
    <script>
        
                function get_confirm()
                {
                     var hr = document.getElementById("hour").value;
                     var min = document.getElementById("min").value;
                     var sec = document.getElementById("sec").value;
                     
            
                     if(confirm("You have set an alarm for " + hr + " hrs " + min + " mins " + sec + " secs. Do you want to continue?"))
                    {
                        alert("Sure, Your alarm has been set for " + hr + " hrs " + min + " mins " + sec + " secs");
                    }
                    else
                    {
                        if(confirm("You have clicked cancel! Do you want to exit or reset the Alarm?"))
                        {
                            location.reload();
                            alert("You have exited from previous alarm. If you want, you can now set another alarm")
                        }
                        
                        else
                        {
                            alert("Your alarm is not being canceled and has been set for " + hr + " hrs " + min + " mins " + sec + " secs");
                        }
                    }
                }
                
                
                
                function  timer()
                {
                     var hr = document.getElementById("hour").value;
                     var min = document.getElementById("min").value;
                     var sec = document.getElementById("sec").value;
                     
                            var date = new Date();
                            var chr = date.getHours();
                            var cmin = date.getMinutes();
                            var csec = date.getSeconds();
                            
                           if((chr == hr) && (cmin == min) && (csec == sec))
                            {
                                analogWrite('0','255');
                                alert("Your alarm is ringing");
                            }
                }
             
    </script>
    </body>
</html>

Credits

Binny Naik

Binny Naik

1 project • 1 follower

Comments