megan neoTeng Hon LingAloysius SeeMohamed Abrar
Published

Our Smart Livestock Farming

Our project is created to reduce the workload of farmers by having a machine to feed the animals like cows and sheep.

BeginnerShowcase (no instructions)382
Our Smart Livestock Farming

Things used in this project

Story

Read more

Schematics

Animal Sorter

image uploaded in parts a whole code is too long

Feeder + Temperature Scanner + Food Level Detector (Part 1)

Image uploaded in parts as whole code is too long

Feeder + Temperature Scanner + Food Level Detector (Part 2)

Image uploaded in parts as whole code is too long

Feeder + Temperature Scanner + Food Level Detector (Part 3)

Image uploaded in parts as whole code is too long

Feeder + Temperature Scanner + Food Level Detector (Part 4)

Image uploaded in parts as whole code is too long

Code

our codes

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

setScreenColor(0x222222)
servo_1 = unit.get(unit.SERVO, unit.PORTB)
rfid_2 = unit.get(unit.RFID, unit.PORTA)


cowcounter = None
shepcounter = None



sheep = M5TextBox(64, 64, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
cow = M5TextBox(195, 64, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
countersheep = M5TextBox(71, 109, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
countercow = M5TextBox(203, 107, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)




cowcounter = 0
shepcounter = 0
sheep.setText('Sheep')
cow.setText('Cow')
countercow.setText(str(cowcounter))
countersheep.setText(str(shepcounter))
servo_1.write_angle(30)
while True:
  if (rfid_2.readUid()) == '27ee91184':
    servo_1.write_angle(0)
    cowcounter = cowcounter + 1
    countercow.setText(str(cowcounter))
    wait(2)
  if (rfid_2.readUid()) == '227bee11a6':
    servo_1.write_angle(60)
    shepcounter = shepcounter + 1
    countersheep.setText(str(shepcounter))
    wait(2)
  wait_ms(2)

our codes

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

setScreenColor(0x222222)
pahub_1 = unit.get(unit.PAHUB, unit.PORTA)
rfid_1 = unit.get(unit.RFID, unit.PAHUB2)
tof_2 = unit.get(unit.TOF, unit.PAHUB3)
servo_2 = unit.get(unit.SERVO, unit.PORTB)
env2_0 = unit.get(unit.ENV2, unit.PAHUB4)


x = None
weightcow = None
weightsheep = None
amountfood = None



name_cow = M5TextBox(23, 36, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
weightofanimal = M5TextBox(85, 133, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Name_Sheep = M5TextBox(10, 36, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
text = M5TextBox(10, 160, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
animalcowweight = M5TextBox(143, 133, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
amount = M5TextBox(130, 99, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
Temperature = M5TextBox(10, 194, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
animalsheepweight = M5TextBox(146, 133, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
tempinput = M5TextBox(117, 194, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
weight = M5TextBox(174, 99, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)



def buttonB_wasPressed():
  global x, weightcow, weightsheep, amountfood
  x = x + 1
  pass
btnB.wasPressed(buttonB_wasPressed)


tempinput.setText(str(0))
text.setText('Food dispensing at 1kg/s')
Temperature.setText('Temperature:')
weightofanimal.setText('Weight:')
pahub_1.select_only_on(2)
pahub_1.select_only_on(3)
x = 1
weightcow = 0
weightsheep = 0
servo_2.write_angle(0)
while True:
  if (rfid_1.readUid()) == '227bee11a6':
    weightcow = 600
  if (rfid_1.readUid()) == 'ed197856da':
    weightcow = 550
  if (rfid_1.readUid()) == '20382b4073':
    weightsheep = 60
  if (rfid_1.readUid()) == '27ee91184':
    weightsheep = 70
  if x % 2 == 1:
    amountfood = (weightcow / 100) * 4
    animalcowweight.show()
    animalsheepweight.hide()
    animalcowweight.setText(str(weightcow))
    amount.setText(str(amountfood))
    weight.setText('kg')
    name_cow.show()
    Name_Sheep.hide()
    name_cow.setText('Amount of food (cow)')
    if rfid_1.isCardOn():
      tempinput.setText(str(env2_0.temperature))
      while (env2_0.temperature) > 39.2:
        speaker.tone(1800, 200)
        wait(0.5)
      servo_2.write_angle(90)
      wait(amountfood)
      servo_2.write_angle(0)
  else:
    amountfood = (weightsheep / 100) * 3
    animalsheepweight.show()
    animalcowweight.hide()
    animalsheepweight.setText(str(weightsheep))
    amount.setText(str(amountfood))
    weight.setText('kg')
    name_cow.hide()
    Name_Sheep.show()
    Name_Sheep.setText('Amount of food (sheep)')
    if rfid_1.isCardOn():
      tempinput.setText(str(env2_0.temperature))
      while (env2_0.temperature) > 39.9:
        speaker.tone(1800, 200)
        wait(0.5)
      servo_2.write_angle(90)
      wait(amountfood)
      servo_2.write_angle(0)
  if (tof_2.distance) > 75:
    rgb.setColorAll(0xff0000)
  else:
    rgb.setColorAll(0x33ff33)
  wait_ms(2)

Credits

megan neo

megan neo

1 project • 1 follower
Teng Hon Ling

Teng Hon Ling

0 projects • 0 followers
Aloysius See

Aloysius See

0 projects • 0 followers
Mohamed Abrar

Mohamed Abrar

0 projects • 1 follower
Thanks to mojica jomarie .

Comments