beanzGracia HanVanya TehXavier Leong
Created January 13, 2025

Smart Factory

Our aim is to reduce workplace hazards, operational downtime, and costs associated with injuries and repairs, creating a safer environment.

51
Smart Factory

Things used in this project

Hardware components

M5Stack FIRE IoT Development Kit (PSRAM 2.0)
M5Stack FIRE IoT Development Kit (PSRAM 2.0)
×2
Time-of-Flight (ToF) VL53L0X Laser Ranging Unit (MCP4725/)
M5Stack Time-of-Flight (ToF) VL53L0X Laser Ranging Unit (MCP4725/)
×1
Light Unit with Photo-resistance
M5Stack Light Unit with Photo-resistance
×1
M5Stack RGB Unit with NeoPixel RGB LED (SK6812)
M5Stack RGB Unit with NeoPixel RGB LED (SK6812)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

M5Stack UIFlow-Desktop-IDE

Hand tools and fabrication machines

Cardboard
Scissors, Free Fall
Scissors, Free Fall
Hot glue gun (generic)
Hot glue gun (generic)
Blu Tack
String

Story

Read more

Schematics

Flowchart for Main M5Stack

Provides OUTPUT

Flowchart for Secondary M5Stack

Provides INPUT

Block Diagram for Main M5Stack

Provides OUTPUT

Block Diagram for Secondary M5Stack

Provides INPUT

Code

Main M5Stack Code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time
import unit

setScreenColor(0x222222)
servo2 = unit.get(unit.SERVO, unit.PORTB)
rgb_0 = unit.get(unit.RGB, unit.PORTA)


mac_add = None
receive_data = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

label10 = M5TextBox(132, 90, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label11 = M5TextBox(132, 40, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(27, 90, "Conveyor:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(24, 40, "Mac Address:", lcd.FONT_Default, 0xFFFFFF, rotate=0)




def recv_cb(_):
  global mac_add,receive_data
  mac_add, _, receive_data = espnow.recv_data(encoder='str')

  pass
espnow.recv_cb(recv_cb)



label11.setText(str(espnow.get_mac_addr()))
servo2.write_angle(0)
while True:
  if receive_data == 'On':
    rgb_0.setColorAll(0x009900)
    servo2.write_angle(0)
    wait(0.5)
    servo2.write_angle(90)
    wait(0.5)
    rgb_0.setColorAll(0x009900)
  elif receive_data == 'Off':
    rgb_0.setColorAll(0xff0000)
    servo2.write_angle(0)
    wait(0.5)
  wait_ms(2)

Secondary M5Stack Code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import unit

setScreenColor(0x222222)
tof_2 = unit.get(unit.TOF, unit.PORTA)
light_0 = unit.get(unit.LIGHT, unit.PORTB)


ToF = None
light = None
receive_data = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

label1 = M5TextBox(12, 123, "ToF Sensor:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
Input = M5Title(title="Input (Secondary M5Stack)", x=6, fgcolor=0xFFFFFF, bgcolor=0x0000FF)
label2 = M5TextBox(12, 75, "Light Sensor:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label0 = M5TextBox(0, 219, "Data:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label5 = M5TextBox(186, 80, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label6 = M5TextBox(186, 128, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)




espnow.add_peer('2c:bc:bb:81:fe:b9', id=1)
label0.setText(str(receive_data))
while True:
  ToF = int(((tof_2.distance) + 10))
  light = light_0.analogValue
  label5.setText(str(light))
  label6.setText(str(ToF))
  if light < 300:
    receive_data = 'Off'
    espnow.send(id=1, data=str(receive_data))
  elif light >= 300 and ToF >= 160:
    receive_data = 'On'
    espnow.send(id=1, data=str(receive_data))
  else:
    receive_data = 'Off'
    espnow.send(id=1, data=str(receive_data))
  wait_ms(2)


def send_cb(flag):
  global receive_data,ToF,light
  receive_data = flag
  label0.setText('Data Sent')

  pass
espnow.send_cb(send_cb)

Credits

beanz
1 project • 1 follower
Gracia Han
1 project • 1 follower
Vanya Teh
1 project • 1 follower
Xavier Leong
1 project • 0 followers

Comments