Tilt detection using MEMS sensor using Raspberry Pi

Call for Price

Tilt detection using MEMS sensor using Raspberry Pi

SKU: Tilt detection using MEMS sensor using Raspberry Pi Category:

Description

ABSTRACT

Raspberry Pi is mini PC which is programmed using Python programming. MEMS sensor is also known as tilt sensing sensor, which is used to detect the tilt in 3 Dimensions, such as X,Y and Z directions. By using tilt you can built the applications such as fall detection, balancing robot etc. Sensor which having 3 Dimensional axes, each dimension is connected to the each channels of MCP3008 to convert analog values to the digital. So that it can be used for several applications based on the needed tilt level in any dimensions. ADC IC which is interfaced with the Raspberry Pi using GPIO pins for CS,MISO,MOSI and CLOCK. IN this Raspberry Pi system, If any of the tilt dimensions crosses its threshold, buzzer gets triggered to exhaust noise as alarm.

 

HARDWARE REQUIRED

  • Raspberry Pi
  • SD card
  • Power supply
  • VGA to HDMI converter (Optional)
  • MCP3008 (ADC IC)
  • MEMS sensor

 

SOFTWARE REQUIRED

  • Raspbian Stretch OS      
  • SD card Formatter
  • Win32DiskImager (or) Etcher

PYTHON LIBRARIES USED

  • RPi.GPIO as GPIO (To access the GPIO Pins of Raspberry Pi)
  • Time library (For Time delay)

CODE

import time

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
    if ((adcnum > 7) or (adcnum < 0)):
        return -1
    GPIO.output(cspin, True)

    GPIO.output(clockpin, False)  # start clock low
    GPIO.output(cspin, False)  # bring CS low

    commandout = adcnum
    commandout |= 0x18  # start bit + single-ended bit
    commandout <<= 3  # we only need to send 5 bits here
    for i in range(5):
        if (commandout & 0x80):
            GPIO.output(mosipin, True)
        else:
            GPIO.output(mosipin, False)
        commandout <<= 1
        GPIO.output(clockpin, True)
        GPIO.output(clockpin, False)

    adcout = 0
    # read in one empty bit, one null bit and 10 ADC bits
    for i in range(12):
        GPIO.output(clockpin, True)
        GPIO.output(clockpin, False)
        adcout <<= 1
        if (GPIO.input(misopin)):
            adcout |= 0x1

    GPIO.output(cspin, True)

    adcout >>= 1  # first bit is 'null' so drop it
    return adcout


# change these as desired - they're the pins connected from the
# SPI port on the ADC to the Cobbler
SPICLK = 18
SPIMISO = 23
SPIMOSI = 24
SPICS = 25
Buzzer=21
# set up the SPI interface pins
GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)
GPIO.setup(Buzzer, GPIO.OUT)


while True:
    # read the analog pin
    MEMS_X = readadc(0, SPICLK, SPIMOSI, SPIMISO, SPICS)
    MEMS_Y = readadc(1, SPICLK, SPIMOSI, SPIMISO, SPICS)
    MEMS_Z = readadc(2, SPICLK, SPIMOSI, SPIMISO, SPICS)
    print("MEMS_X value:", MEMS_X)
    print("MEMS_Y value:", MEMS_Y)
    print("MEMS_Z value", MEMS_Z)
    if((MEMS_X<500)or(MEMS_Y<500)or(MEMS_Z<500)):
        GPIO.output(Buzzer, True)
        time.sleep(1)
        GPIO.output(Buzzer, False)
    else:
        GPIO.output(Buzzer, False)


Additional information

Weight 0.000000 kg

Reviews

There are no reviews yet.

Be the first to review “Tilt detection using MEMS sensor using Raspberry Pi”

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.