Ansh
Published

IoT Enabled 16x2 LCD screen

This project allows any Bolt user to control an LCD display via the internet.

BeginnerFull instructions provided1 hour2,953
IoT Enabled 16x2 LCD screen

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Working Model

Code

HTML Code

HTML
Type this code in any Open Source HTML editor
<!DOCTYPE html>
<html>
    <head>
        <title>Lcd Display Interface</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    </head>
    <body>
        <label>
            <input id="nightmode" type="checkbox">
            <span class="check"></span>
        </label>
        <script>
            document.getElementById("nightmode").addEventListener("change", function() {
  if (document.getElementById("nightmode").checked == false) {
    document.body.style.transition = "all 0.75s";
    document.body.style.backgroundColor = "#57afab";
    document.body.style.color="#000000";
    document.body.style.fontFamily="Apercu, Source Sans Pro, system, system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, sans-serif, Arial";
    document.body.style.fontSize="30px";
  } else {
    document.body.style.transition = "all 0.75s";
    document.body.style.backgroundColor = "#122736";
    document.body.style.color="#3878a0";
    document.body.style.fontFamily="Apercu, Source Sans Pro, system, system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, sans-serif, Arial";
    document.body.style.fontSize="30px";
  }
});
        </script>
        <div id="headings">Bolt IoT Smart LCD</div>
        <div>Bolt ID:<input type="Text" id="boltid" placeholder="xxxx"></div>
        <div>API key:<input type="Text" id="apikey" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxx"></div>
        <div>Enter the message you want to display below  <span style="font-size:30px"> &#128071;</span></div>
        <input id="command" type="text" size="40">
        <div style="margin-top: 10px;">
            <button onclick="SendCommand()" class="button">Send</button>
        </div>
        <div id="display"></div><br>
        <div id="commandstatus"></div><br>
        <div id="commandvalue"></div><br>
        <script>
            link="";
            function SendCommand(){
                var apikey=document.getElementById('apikey').value;
                var devicename=document.getElementById("boltid").value;
                var command=document.getElementById('command').value;
                link="https://cloud.boltiot.com/remote/"+apikey+"/serialWrite?data="+command+"&till=10&baud=9600&deviceName=BOLT"+devicename;
                if(apikey==""){
                    document.getElementById('commandstatus').innerHTML="Please enter an api key"
                    return;
                }
                if(devicename==""){
                    document.getElementById('commandstatus').innerHTML="Please enter a device name"
                    return;
                }
                if(command==""){
                    document.getElementById('commandstatus').innerHTML="Please enter some data"
                    return;
                }
                $.get(link,function(success,value){
                    if(value=="success"){
                        if(success['success']==1){
                            document.getElementById('commandstatus').innerHTML="The task was successful";
                        }else{
                            document.getElementById('commandstatus').innerHTML=success['value'];
                        }
                    }else{
                        document.getElementById('commandstatus').innerHTML="Please check the api key entered"
                    }
                });
            }
        </script>
    </body>
</html>

CSS Code

CSS
This is for the styling of the HTML Code. Make sure that you link the HTML and the CSS code and store them in the same folder.
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body{
    margin-left: 30px;
    text-align: left;
    background-color: #57afab;
    font-family: Apercu, Source Sans Pro, system, system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    font-size: 30px;
}
.button{
  background-color: rgb(76, 175, 80);
  cursor:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'  width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'></text></svg>") 16 0,auto;
  border: none;
  border-radius: 30px;
  margin-left: 110px;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}
input[type="text"]
{
    font-size: 20px;
    margin-bottom: 70px;
    margin-left: 20px;
    border: 2px solid red;
    border-radius: 4px;
    width: 300px;
}
input[type="checkbox"]
{
    -webkit-appearance: none;
    visibility: hidden;
    display: none;
}
.check
{
    margin-top: 60px;
    margin-bottom: 60px;
    margin-right: auto;
    position: relative;
    display: block;
    width: 53px;
    height: 25px;
    background: #092c3e;
    cursor: pointer;
    border-radius: 20px;
    overflow: hidden;
    transition: ease-in 0.75s;
}
input[type="checkbox"]:checked ~ .check
{
    background-color: #57afab;
    box-shadow:  0 0 0 0px #092c3e;
}
.check:before
{
    content: '';
    position: absolute;
    top: 3px;
    left: 2px;
    background: #fff;
    width: 19px;
    height: 19px;
    border-radius: 59%;
    transition: 0.75s;
    
}
input[type="checkbox"]:checked ~ .check:before
{
    transform: translateX(-50px);
}
.check:after
{
    content: '';
    position: absolute;
    top: 2px;
    right:  2px;
    background: #092c3e;
    width: 19px;
    height: 21px;
    border-radius: 60%;
    transition: 0.75s;
    transform: translateX(50px);
}
input[type="checkbox"]:checked ~ .check:after
{
    transform: translateX(0px);
}
#headings{
    color: aliceblue;
    font-weight: 600;
    margin-top: 50px;
    margin-bottom: 50px;
}
#commandstatus{
    color: #9b0b0b;
    margin-left: 20px;
}

Arduino Code

Arduino
Upload this code on your Arduino UNO. Make sure to remove the Bolt WiFi Module when you upload the code to the Arduino.
#include <BoltDeviceCredentials.h>
#include <BoltIoT-Arduino-Helper.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


long previous_print_time=millis();
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.print("Welcome");
}

void loop() {
  long current_time=millis();
  if((current_time-previous_print_time)>=1000){
    previous_print_time+=1000;
    if(Serial.available()>0){
      int start=0;
      lcd.clear();
    while(Serial.available()>0){
      char data=Serial.read();
      if(start==16){
        lcd.setCursor(0,1);
      }
      if(start==32){
        lcd.setCursor(0,0);
        start=0;
      }
      lcd.print(data);
      start++;
    }
    }
  }
}

GitHub Repository

Credits

Ansh

Ansh

1 project • 0 followers

Comments