HadrianShiftyCloudsJw19
Published

Auto-Management of Livestock Farming

We make auto-management of livestock farming using M5Stack to make forming more automated and convenient

BeginnerShowcase (no instructions)128
Auto-Management of Livestock Farming

Things used in this project

Story

Read more

Schematics

Blocky Code of food dispenser and gate, using LIGHT Unit and servo motors

Purpose of food dispenser is to give food to livestock depending on the time of day using the LIGHT Unit. When a certain time, light has reached, the food will be dispensed for a time limit before resetting back to its original position.

Blocky Code of Livestock count with RFID, LIGHT, and ENV II Unit

Livestock Management System (Feeding, Statistics & Counting)
Tof Unit -> Pa.Hub -> M5stack
ENV Ⅱ Unit -> Pa.Hub -> M5stack
RFID Unit -> Pa.Hub -> M5stack

Code

LIGHT and Servo Motor

Python
Purpose of food dispenser is to give food to livestock depending on the time of day using the LIGHT Unit. When a certain time, light has reached, the food will be dispensed for a time limit before resetting back to its original position.
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
light_0 = unit.get(unit.LIGHT, unit.PORTB)
servo_3 = unit.get(unit.SERVO, unit.PORTA)


lightrequired = None



label0 = M5TextBox(162, 82, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(49, 41, "Dispensing Food", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(162, 112, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(54, 112, "Light Required:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(64, 82, "Light Amount:", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonA_wasPressed():
  global lightrequired
  lightrequired = (lightrequired if isinstance(lightrequired, Number) else 0) + 100
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
  global lightrequired
  lightrequired = (lightrequired if isinstance(lightrequired, Number) else 0) + -100
  pass
btnB.wasPressed(buttonB_wasPressed)


lightrequired = 400
while True:
  label3.setText(str(lightrequired))
  label2.hide()
  label0.setText(str(light_0.analogValue))
  if (light_0.analogValue) <= lightrequired:
    servo_3.write_angle(0)
    label2.show()
    wait(1)
    servo_3.write_angle(90)
    wait(5)
    servo_3.write_angle(0)
  wait_ms(2)

Livestock counter with RFID, ENV II and ToF

Python
Purpose of thermal scanner is to detect high temperature which is part of the symptoms if livestock is sick.

Purpose of livestock count is is to make live count of the total amount of livestock. It make sure it does not go beyond or under the total amount of livestock. Tof and RFID detects motion sensor and RFID Tag and converts it to 1 livestock count and has a time interval for each count.
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
rfid_1 = unit.get(unit.RFID, unit.PAHUB0)
tof_2 = unit.get(unit.TOF, unit.PAHUB2)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA)
env2_0 = unit.get(unit.ENV2, unit.PAHUB1)


maxNo_ofAnimals = None
No_ofAnimals = None



label0 = M5TextBox(239, 86, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(207, 170, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(275, 10, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(240, 112, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 76, "Temperature:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(0, 160, "Sheep Tag:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label6 = M5TextBox(0, 118, "Sheeps Entered:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label7 = M5TextBox(114, 5, "No. of sheeps:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label8 = M5TextBox(238, 210, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label9 = M5TextBox(0, 200, "Distance:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonB_wasPressed():
  global maxNo_ofAnimals, No_ofAnimals
  maxNo_ofAnimals = (maxNo_ofAnimals if isinstance(maxNo_ofAnimals, Number) else 0) + -1
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonA_wasPressed():
  global maxNo_ofAnimals, No_ofAnimals
  maxNo_ofAnimals = (maxNo_ofAnimals if isinstance(maxNo_ofAnimals, Number) else 0) + 1
  pass
btnA.wasPressed(buttonA_wasPressed)


No_ofAnimals = 0
maxNo_ofAnimals = 0
while True:
  rgb.setColorAll(0xffffff)
  label8.setText(str(tof_2.distance))
  label4.setText(str(maxNo_ofAnimals))
  label0.setText(str(env2_0.temperature))
  label0.hide()
  label5.setText(str(No_ofAnimals))
  label1.setText('Please Enter')
  if rfid_1.isCardOn():
    label1.setText(str(rfid_1.readUid()))
    wait(1)
    label1.setText('Please Enter')
    if 300 > (tof_2.distance):
      No_ofAnimals = (No_ofAnimals if isinstance(No_ofAnimals, Number) else 0) + 1
      label0.show()
      label5.setText(str(No_ofAnimals))
      speaker.sing(831, 2)
      wait(3)
      label1.setText('Reset')
  if No_ofAnimals != maxNo_ofAnimals:
    speaker.setVolume(0.1)
    speaker.tone(1800, 200)
    rgb.setColorAll(0xff0000)
    rgb.setColor(3, 0xffffff)
    rgb.setColor(2, 0xff0000)
    rgb.setColor(4, 0xffffff)
    speaker.sing(220, 1)
    wait(1)
  wait_ms(2)

Credits

Hadrian

Hadrian

1 project • 0 followers
ShiftyClouds

ShiftyClouds

0 projects • 0 followers
Jw19

Jw19

0 projects • 0 followers
Thanks to Marcus.

Comments