Micropython tutorial of TPYBoard DIY metal detector example demo

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Jackli
Posts: 80
Joined: Thu Apr 29, 2021 9:11 am

Micropython tutorial of TPYBoard DIY metal detector example demo

Post by Jackli » Fri Jul 16, 2021 7:49 am

Recently I want to use the cell phone to collect metal detector data to port the project to the serial screen implementation, before the first simple example to do a simple metal detection.

Required components
  • One TPYBoard board
    One LJ12A3-4-Z/BX metal proximity switch
    One breadboard
    One light-emitting diode
    One data cable
    A number of DuPont wires
LJ12A3-4-Z/BX Proximity switch working principle

Proximity switch has the characteristics of both travel switch and microswitch but also has sensing performance, and reliable action, stable performance, fast frequency response, long application life, strong anti-interference ability, etc., and has the characteristics of waterproof and shockproof, corrosion resistance, etc.

The output signal of the proximity switch is the output digital signal, that is when there is no metal near, output 1 when there is metal, output 0. Through the front probe to detect whether there is metal, and then the detected number will be passed to the TPYBoard, and then the TPYBoard makes the corresponding judgment, widely used in machine tools, metallurgy, chemical industry, aerospace, light textile, and printing industries; in daily life, it can be used in hotels, restaurants, garages, automatic doors, automatic heaters are used on; insecurity and anti-theft, such as data archives, accounting, finance, museums, vaults, and other important places, are usually equipped with a variety of proximity switches consisting of anti-theft devices.

We just need the positive (gray wire) to connect to the VIN pin of the TPYBoard, the negative (blue wire) to connect to the GND pin of the TPYBoard, and the black wire (output signal) to connect to the IO pin of the TPYBoard, the Y1 pin used here. Once connected, the red light that comes with the proximity switch itself will light up when a metal is near, and go off when it is away from the metal.

Image

Hardware wiring method

After we connect the proximity switch line above, the TPYboard development board can collect the digital signal passed by the metal switch through the Y1 pin, we can use this signal to let the development board control the automatic door opener, alarm, etc. Here is just a simple and easy-to-understand application to light up our red LED light-emitting diode.

Image

code sharing

Code: Select all

# main.py -- put your code here!
import pyb
from machine import Pin

y1 = Pin('Y1', Pin.IN)
x1 = Pin('X1', Pin.OUT_PP)

while 1:
    #When there is no metal
    if y1.value() == 1 :
        print(y1.value())
        x1.value(0)
    #When there is metal
    else:
        print(y1.value())
        x1.value(1)

Post Reply