SM24 Geophone With Raspberry Pi Pico W

by bennyliu in Circuits > Sensors

1348 Views, 2 Favorites, 0 Comments

SM24 Geophone With Raspberry Pi Pico W

geophone_wiring_pico.jpg

Written By:

Benny Liu and Yourui Shao


Geophones are a type of vibration sensor that can sense the movement in the ground and convert it into voltage, which is then examined for anomalies. The sensor has been used by scientists to examine the seismic activity under the earth, and even used by Apollo 16 to gain more knowledge of the disturbances under the moon's surface. But, geophones can also be used in everyday scenarios. For example, they can be used in fall detection, sensing the vibration caused by a fall, or monitoring water pumps.


A Raspberry Pi Pico is used to control the sensor because it is cost efficient. In the cases such as monitoring water pumps or sensing falls, it is required to have many geophones in different locations for efficient and accurate data. Hence, a Raspberry Pi Pico is useful since it is affordable and is also ideal for controlling electronics.

Supplies

  1. Raspberry Pi Pico W
  2. SM24 Geophone
  3. Micro HDMI cable
  4. 6 Cables
  5. Analog to Digital Converter
  6. PCB

Wiring

image (1).png

Above is a schematic of the wiring needed for the sensor.

Code

A driver is needed to establish a connection between the analog-to-digital converter (ADC) and the Raspberry Pico. We will be using the Driver for the ADS1015/ADS1115 Analogue-Digital Converter, and incorporating the given sample code:

from machine import I2C, Pin, Timer

import ads1x15 # importing the driver library
from array import array

# Sample code:
addr = 0x48 # 72 in hexadecimal
gain = 5
_BUFFERSIZE = const(512)

data = array("h", (0 for _ in range(_BUFFERSIZE)))
timestamp = array("L", (0 for _ in range(_BUFFERSIZE)))
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
# for the Pycom branch, use:
# i2c = I2C()
ads = ads1x15.ADS1115(i2c, addr, gain)
ads.set_conv(7, 0, 1) # start the first conversion


Next, we use the WLAN class from the network library to establish the Pico's connection to the wifi network so that we can get the vibration value through the HTTP server:


import network
import time
from time import sleep_ms, ticks_ms, ticks_us

ssid = 'WIFI_USER'
password = 'WIFI_PWD'

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

# 192.168.1.48 and 192.168.1.1 are sample IP and gateway
wlan.ifconfig(('192.168.1.48', '255.255.255.0', '192.168.1.1', '8.8.8.8'))

# Waiting for a connection for a  maximum of 10 seconds.
max_wait = 10
while max_wait > 0:

# wlan.status() returns constants, which store integer values
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print('waiting for connection...')
    time.sleep(1)

if wlan.status() != 3:
    raise RuntimeError('network connection failed')
else:
    print('connected')
    status = wlan.ifconfig()
    print( 'ip = ' + status[0] )


Next, we will create a socket in order to send the value to 192.168.1.48:


import socket

addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]

s = socket.socket()
s.bind(addr)
s.listen(1)


Next, the Pico will listen for connections, which are any HTTP requests with its IP address, http://192.168.1.48/. Once http://192.168.1.48/ is accessed, it will notify that a connection is made. The HTTP request provides a JSON giving the vibration value collected through ads1x15 in the key “value.”


print('listening on', addr)

# Listen for connections
while True:
    try:
        cl, addr = s.accept()
        print('client connected from', addr) # Notifies connection
        request = cl.recv(1024)
        request = str(request)
        try:
            request = request.split()[1]
        except IndexError:
            pass
        
        value = ads.read_rev()
        
        str_value = '{"value": "' + str(value) + '"}'
        
        cl.send('HTTP/1.0 200 OK\r\nContent-type: text/json\r\nContent-Length: ' + str(len(str_value)+2) + '\r\n\r\n')
        cl.send(str_value + '\r\n')
        print('Done value', value)
        cl.close()

    except OSError as e:
        cl.close()
        print('connection closed')


View whole code at Github: https://github.com/iuruoy-shao/vibration-sensor

Collecting Data

vibration_plot_ex.png

The image above is an example of the data collected by the geophone. The numbers on the y-axis of the graph represents a vibration score that we have set ourselves, determining how large the vibration was. The geophone continuously sends back data of the vibrations recorded on the ground, and the large spike in the graph was the vibrations recorded when a person fell. As you can see, anomalies are easily detected by geophones in this scenario, accurately detecting the fall of a human.