Cherry WoodHai JieedysonMark Jeshurun Mirasol
Published

Project: PEST TERROR

Pest Control System for urban farming

BeginnerFull instructions provided24 hours549
Project: PEST TERROR

Things used in this project

Story

Read more

Schematics

A2 Board

Block Diagram

Flow Chart

Code

Transmitter Code

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

setScreenColor(0x222222)
servo_1 = unit.get(unit.SERVO, unit.PORTB)
tof_1 = unit.get(unit.TOF, unit.PAHUB2)
pahub_1 = unit.get(unit.PAHUB, unit.PORTA)
pbhub_1 = unit.get(unit.PBHUB, unit.PAHUB0)


Data_send = None

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

image3 = M5Img(70, 60, "res/techterror.png", True)
label0 = M5TextBox(98, 16, "Detecting", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
image0 = M5Img(110, 70, "res/Detecting.png", True)
image1 = M5Img(110, 70, "res/Detected.png", True)
image2 = M5Img(96, 56, "res/spraying.png", True)
label1 = M5TextBox(334, -100, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)




espnow.add_peer('78:21:84:93:ae:41', id=1)
servo_1.write_angle(0)
image0.hide()
image1.hide()
image2.hide()
image3.hide()
while True:
  label0.setText('Detecting')
  wait(0.2)
  image0.show()
  if (tof_1.distance) < 100:
    speaker.tone(10000, 500)
    wait_ms(3)
    label0.setText('Detected')
    image0.hide()
    wait(0.2)
    image1.show()
    wait(3)
    label0.setText('TERROR')
    Data_send = tof_1.distance
    espnow.send(id=1, data=str((tof_1.distance)))
    image1.hide()
    wait(0.5)
    image3.show()
    wait(5)
    image3.hide()
  elif (tof_1.distance) > 100 and (tof_1.distance) < 300:
    speaker.tone(10000, 500)
    if (pbhub_1.analogRead(0)) <= 500:
      label0.setText('Detected')
      image0.hide()
      wait(0.2)
      image1.show()
      wait(3)
      label0.setText('TERROR')
      Data_send = tof_1.distance
      espnow.send(id=1, data=str((tof_1.distance)))
      image1.hide()
      wait(0.2)
      image3.show()
      wait(5)
    elif (pbhub_1.analogRead(0)) <= 700:
      label0.setText('Detected')
      image0.hide()
      wait(0.2)
      image1.show()
      wait(3)
      servo_1.write_angle(120)
      wait(0.2)
      servo_1.write_angle(0)
      image1.hide()
      wait(0.2)
      image2.show()
      label0.setText('Spraying')
      wait(4)
      image2.hide()
    else:
      label0.setText('Detected')
      image0.hide()
      wait(0.2)
      image1.show()
      wait(3)
      servo_1.write_angle(180)
      wait(0.2)
      servo_1.write_angle(0)
      image1.hide()
      wait(1)
      image2.show()
      label0.setText('Spraying')
      wait(4)
      image2.hide()
  else:
    label0.setText('Detecting')
  wait_ms(2)

Receiver Code

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

setScreenColor(0x222222)
servo_1 = unit.get(unit.SERVO, unit.PORTB)
pir_0 = unit.get(unit.PIR, unit.PORTA)


mac = None
Data_send = None
distance = None

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

title0 = M5Title(title="Mac Address:", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF)
label0 = M5TextBox(101, 30, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
detected = M5Img(95, 74, "res/nobird.jpg", True)
techterror = M5Img(70, 65, "res/techterror.png", True)
label1 = M5TextBox(101, 8, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
deter = M5Img(95, 74, "res/scare.jpg", True)




def recv_cb(_):
  global mac,Data_send,distance
  mac, _, Data_send = espnow.recv_data(encoder='str')
  distance = int(Data_send)
  label0.setText('TERROR')
  techterror.show()
  wait(0.5)
  servo_1.write_angle((distance / 2))
  wait(3)
  techterror.hide()
  servo_1.write_angle(0)
  wait(0.2)

  pass
espnow.recv_cb(recv_cb)



detected.hide()
techterror.hide()
deter.hide()
while True:
  label0.setText('Detecting')
  wait(0.1)
  label1.setText(str(espnow.get_mac_addr()))
  if (pir_0.state) == 1:
    wait(0.1)
    label0.setText('Detected')
    detected.show()
    wait(3)
    label0.setText('Deterring')
    detected.hide()
    wait(0.1)
    deter.show()
    wait(0.1)
    for count in range(3):
      rgb.setColorAll(0xff0000)
      wait(0.5)
      rgb.setColorAll(0x3366ff)
      speaker.tone(2000, 50)
    deter.hide()
    rgb.setColorAll(0x000000)
  else:
    label0.setText('Detecting')
  wait(0.5)
  wait_ms(2)

Credits

Cherry Wood

Cherry Wood

1 project • 0 followers
Hai Jie

Hai Jie

1 project • 0 followers
edyson

edyson

1 project • 0 followers
Mark Jeshurun Mirasol

Mark Jeshurun Mirasol

1 project • 0 followers

Comments