How to Measuring Acceleration with an MCP3008 Module in Raspberry Pi

You want to connect an Acceleration with MCP3008 in  Raspberry Pi. Today I show you how to Measuring Acceleration with an MCP3008 Module step by step complete process. we are using Accelerometer ADXL335 for this project.


≡ What is Accelerometer


By measuring the sum of acceleration due to gravity, an accelerometer can figure out the point it is tilted at with regard to the earth. By detecting the sum of energetic acceleration, the accelerometer can discover out how quick and in what course the gadget is moving.

In Accelerometer ADXL335 :

The ADXL335 is a small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs. The product measures acceleration with a minimum full-scale range of ±3 g. It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration. The user selects the bandwidth of the accelerometer using the CX, CY, and CZ capacitors at the XOUT, YOUT, and ZOUT pins. Bandwidths can be selected to suit the application, with a range of 0.5 Hz to 1600 Hz for the X and Y axes, and a range of 0.5 Hz to 550 Hz for the Z-axis.

Source and More about see Datasheet Accelerometer ADXL335


≡ Why we need MCP3008:


The Raspberry Pi computer does not have a way to read analog inputs. It’s a digital-only computer. Compare this to the Arduino, AVR or PIC microcontrollers that regularly have 6 or more analog inputs! Analog inputs are handy because many sensors are analog outputs, so we require a way to form the Pi analog-friendly.

We’ll do that by wiring up an MCP3008 chip to it. The MCP3008 acts like a “bridge” between digital and analog. It has 8 analog inputs and the Pi can query it utilizing 4 digital pins. That produces it a perfect addition to the Pi for joining basic sensors like photocells, FSRs or potentiometers, thermistors, etc.! Let’s check the datasheet of the MCP3008 chip.

MCP3008


 ≡ Components Required :


1.Raspberry pi

2.Breadboard

3. Connecting wire

6. Resistors

7.MCP3008

8. Accelerometer ADXL335

This book will help you to gain more knowledge of Raspberry pi  Software and Hardware Problems and Solutions

Raspberry Pi Cookbook


≡ Circuit diagram Acceleration MCP3008 Raspberry Pi:


shows the arrangement for this, using a breadboard. It uses three channels of the ADC to measure the X, Y, and Z acceleration forces

Using a triple-axis accelerometer Using a triple-axis accelerometer

You will need to set up SPI on your Raspberry Pi, so if you have not already done so, follow Setting Up SPI on your Raspberry pi


≡ Code Acceleration MCP3008 Raspberry Pi:


Open an editor (nano or IDLE) and paste in the following code.

import spidev, time

spi = spidev.SpiDev()
spi.open(0,0)

def analog_read(channel):
    r = spi.xfer2([1, (8 + channel) << 4, 0])
    adc_out = ((r[1]&3) << 8) + r[2]
    return adc_out

while True:
    x = analog_read(0)
    y = analog_read(1)
    z = analog_read(2)
    print("X=%d\tY=%d\tZ=%d" % (x, y, z))
    time.sleep(1)

The program simply reads the three forces and prints them out:
X=508 Y=503 Z=626

If you want to know more about raspberry pi then click on the link below

RASPBERRY PI TUTORIALS FOR BEGINNERS

No comments

Theme images by Dizzo. Powered by Blogger.