Crystal Ong
Published

Smart Retail

A convenience & safety system that aims to enhance user experience. An Automated Door & Intruder Alarm is built using M5Stack.

IntermediateFull instructions provided520
Smart Retail

Things used in this project

Story

Read more

Schematics

Block Diagram

Flowchart

PowerPoint Presentation

Flowchart

Code

Main Store Code

Plain text
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
tof2 = unit.get(unit.TOF, unit.PORTA)
pir1 = unit.get(unit.PIR, unit.PORTB)
servo2 = unit.get(unit.SERVO, unit.PORTB)


on = None
off = None
stockchecker = None


label1 = M5TextBox(7, 31, "There is a customer", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(7, 32, "No customer Detected", lcd.FONT_Default, 0xFFFFFF, rotate=0)
title0 = M5Title(title="            safety & convenience system", x=3, fgcolor=0xFFFFFF, bgcolor=0x5050b2)
label2 = M5TextBox(146, 161, ".", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(146, 190, ".", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(32, 107, "ALERTING POLICE!!!", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label5 = M5TextBox(54, 107, "No one detected", lcd.FONT_DejaVu24, 0x1af326, rotate=0)
label4 = M5TextBox(26, 99, "INTRUDER!!!", lcd.FONT_DejaVu40, 0xe60f0f, rotate=0)



def buttonA_wasPressed():
  global on, off, stockchecker
  on = True
  off = False
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
  global on, off, stockchecker
  on = False
  off = True
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
  global on, off, stockchecker
  on = False
  off = False
  label6.show()
  rgb.setColorAll(0xffffff)
  pass
btnC.wasPressed(buttonC_wasPressed)


label1.setText('There is a customer')
label0.setText('No customer Detected')
label1.hide()
label4.hide()
label5.hide()
label0.hide()
label6.hide()
while True:
  if on == True:
    while on == True:
      label4.hide()
      stockchecker = tof2.distance
      label3.setText(str(tof2.distance))
      if stockchecker <= 50:
        label2.setText('stock is FULL')
        rgb.setColorAll(0x33ff33)
      elif stockchecker > 50 and stockchecker <= 150:
        label2.setText('stock level is MODERATE')
        rgb.setColorAll(0x3333ff)
      elif stockchecker > 150 and stockchecker <= 250:
        label2.setText('Stock level is LOW')
        rgb.setColorAll(0xff99ff)
      elif stockchecker > 250:
        label2.setText('NO stock detected')
        rgb.setColorAll(0xff0000)
      if (pir1.state) == 1:
        label0.hide()
        label1.show()
        rgb.setColorAll(0x33cc00)
        speaker.tone(1800, 1000)
        speaker.setVolume(0.2)
        servo2.write_angle(90)
        wait(3)
        servo2.write_angle(0)
        wait(3)
      else:
        label0.show()
        label1.hide()
        rgb.setColorAll(0x000000)
        servo2.write_angle(0)
  elif off == True:
    while off == True:
      label0.hide()
      label1.hide()
      label2.hide()
      label3.hide()
      label4.hide()
      label5.hide()
      servo2.write_angle(0)
      if (pir1.state) == 1:
        label4.show()
        label5.hide()
        speaker.tone(1800, 1000)
        rgb.setColorAll(0xcc0000)
      else:
        label4.hide()
        label5.show()
        rgb.setColorAll(0x000000)
  wait_ms(2)

Price Checker Code

Plain text
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
rfid0 = unit.get(unit.RFID, unit.PORTA)


i = None


label0 = M5TextBox(49, 74, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label1 = M5TextBox(0, 219, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)




while True:
  if rfid0.isCardOn():
    rgb.setColorAll(0xff0000)
    label0.setText(str(rfid0.readUid()))
    wait(1)
    if (rfid0.readUid()) == '33989cf0c7':
      label0.setText('Eggs : $1.50')
      speaker.tone(1800, 200)
      rgb.setColorAll(0x33cc00)
      wait(0.25)
    elif (rfid0.readUid()) == '978853eca0':
      label0.setText('Soju : $10.00')
      speaker.tone(1800, 200)
      rgb.setColorAll(0x33cc00)
      wait(0.25)
    elif (rfid0.readUid()) == '9359ce888c':
      label0.setText('Beer: $5.00')
      speaker.tone(1800, 200)
      rgb.setColorAll(0x33cc00)
      wait(0.25)
    for i in range(1, 21):
      label1.setText(str(i))
  else:
    label0.setText('Please scan an item')
    rgb.setColorAll(0x000000)
  wait_ms(2)

RFID Code

Plain text
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
rfid0 = unit.get(unit.RFID, unit.PORTA)


i = None


label0 = M5TextBox(104, 78, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(104, 128, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)




while True:
  if rfid0.isCardOn():
    label0.setText(str(rfid0.readUid()))
    wait(1)
    for i in range(1, 21):
      label1.setText(str(i))
  wait_ms(2)

Credits

Crystal Ong

Crystal Ong

1 project • 0 followers

Comments