Group Presentation·smart door — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by xuejinchen12345.

Components

Sketch code

//assuming system is never powered off
//remember to install 'Seeed Studio Grove LCD RGB Backlight library' 



const int  lightPin = A1; //binds the light value to port A1
#include <Wire.h> //tells system to use a Library when running
#include "rgb_lcd.h" //tells system to use a Library when running
rgb_lcd screen; //tells system that we have a LCD, name LCD as 'screen'


void setup() 


{
  Serial.begin(9600); //direct info to serial port 9600
  screen.begin(16, 2); // states that screen has 16 columns and 2 rows allowing at most 32 characters to be displayed


  screen.setRGB(240,255,240); // RGB color code for the background screen, color code devirived from https://www.rapidtables.com/web/color/RGB_Color.html#color-table

 
  

}

void loop()

{
  int  lightLevel = analogRead(lightPin); //allocates anolog port value to variable lightLevel
  Serial.print("Light sensor = ");
  Serial.println(lightLevel);

  if (lightLevel < 500 ) //set light level threshold triggers when covered
  {
    screen.clear(); //refresh screen to 'wake it up'

    screen.setCursor(0, 0); 
    screen.print("Opening");

  
    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);



    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);
    
    screen.clear();
    screen.print("Opened");

    while (lightLevel < 500 ) //keeps door open if covered continously 

    {

      lightLevel = analogRead(lightPin); // tells system to detect ligthlevel to prevent loop freezing (note, perviously there was a int  before 'lightlevel' causing variable Shadowing which defines lightlevel again but loop doesn't have lightpin value so circuit crashes)

      Serial.print("Light sensor = "); //allows monitor to display lightlevel during while for observing purposes
      Serial.println(lightLevel); 

      delay(100); //check lightlevel every 100ms, note bug:in simulation, releasing mouse button that is controling light too early may cause a crash, either use keyboard to alter value or hold the button until changing lightlevel to be less than 500, shouldn't be a issues in practical
      
    }

    screen.setCursor(0, 1); //locates the display value to the first character cell on the second row 
    
    screen.setCursor(0, 0); 
    screen.print("Closing in");
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);
   
    screen.setCursor(0, 1); 
    screen.print("5 second");
    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);

    screen.setCursor(0, 1); 
    screen.print("4 second");
    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);

    screen.setCursor(0, 1); 
    screen.print("3 second");
    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);

    screen.setCursor(0, 1); 
    screen.print("2 second");
    delay(1000); 
    Serial.print("Light sensor = ");
    Serial.println(lightLevel);

    screen.setCur