0% found this document useful (0 votes)
49 views12 pages

Lab Reports Inst and Control Lab

This lab document describes using an accelerometer sensor module and a gyroscope sensor module. It provides objectives, theoretical background, and working principles of each sensor. It also includes wiring diagrams, code examples, and potential applications such as detecting movement, measuring orientation and angular velocity, and incorporating sensors into devices like mobile phones, games, and industrial machinery. The lab tasks involve interfacing the sensor modules with a microcontroller and reading output data to understand their functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views12 pages

Lab Reports Inst and Control Lab

This lab document describes using an accelerometer sensor module and a gyroscope sensor module. It provides objectives, theoretical background, and working principles of each sensor. It also includes wiring diagrams, code examples, and potential applications such as detecting movement, measuring orientation and angular velocity, and incorporating sensors into devices like mobile phones, games, and industrial machinery. The lab tasks involve interfacing the sensor modules with a microcontroller and reading output data to understand their functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lab: Use of Accelerometer sensor module

Objectives:

 To understand how to use accelerometer sensor module.


 To understand what a accelerometer sensor module is and it’s working principle.
 To understand the applications of the accelerometer sensor module.

Theoretical Background:

The accelerometer measures the acceleration along one direction. An accelerometer is an


integrated, built-in module or circuit that accurately detects and measures the acceleration and
motion of the application it is attached too. The type of measurement they measure is the rate of
velocity change in an object and commonly measure in G-forces (g) or in meters per second
squared (m/s2).

Working principle:

An accelerometer is a device that measures the vibration, or acceleration of motion of a structure.


The force caused by vibration or a change in motion (acceleration) causes the mass to "squeeze"
the piezoelectric material which produces an electrical charge that is proportional to the force
exerted upon it.

What are Accelerometer Sensors used for?


• Gaming systems
• Mobile devices
• Disk drive protection
• Image stabilization
• Sports and health devices
• Industrial applications
• Commercial applications

Connections:
VCC -> 3.3 V / 5 V (better)
GND -> GND
SCL -> A5
SDA -> A4
XDA ->
XCL ->
ADO ->
INT ->
The analogic pins are not set on INPUT because it's their default setting. The values read by
the analogic pins will be sent to the serial port.
Open the Serial Monitor, move the sensor and try to see how the values change.

Code:
#include<Wire.h>
const int MPU=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU,12,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
GyX=Wire.read()<<8|Wire.read();
GyY=Wire.read()<<8|Wire.read();
GyZ=Wire.read()<<8|Wire.read();

Serial.print("Accelerometer: ");
Serial.print("X = "); Serial.print(AcX);
Serial.print(" | Y = "); Serial.print(AcY);
Serial.print(" | Z = "); Serial.println(AcZ);

Serial.print("Gyroscope: ");
Serial.print("X = "); Serial.print(GyX);
Serial.print(" | Y = "); Serial.print(GyY);
Serial.print(" | Z = "); Serial.println(GyZ);
Serial.println(" ");
delay(333);
}
Circuit diagram:

Lab task:
Lab: Interfacing a gyroscope sensor GY-521 module (MPU-6050
breakout board) with a controller

Objective:

 To understand how to interface a gyroscope sensor with a controller.


 To understand what a gyroscope sensor and what it’s working principle.
 To understand the applications of the gyroscope sensor.

Theoretical Background:

Gyroscope sensor is a device that can measure and maintain the orientation and angular
velocity of an object. These are more advanced than accelerometers. These can measure the tilt
and lateral orientation of the object whereas accelerometer can only measure the linear motion.
Gyroscope sensors are also called as Angular Rate Sensor or Angular Velocity Sensors. These
sensors are installed in the applications where the orientation of the object is difficult to sense by
humans.

Measured in degrees per second, angular velocity is the change in the rotational angle of the
object per unit of time.

The GY-521 module is a breakout board for the MPU-6050 MEMS (Microelectromechanical
systems) that features a 3-axis gyroscope, a 3-axis accelerometer, a digital motion processor
(DMP), and a temperature sensor. The digital motion processor can be used to process complex
algorithms directly on the board. Usually, the DMP processes algorithms that turn the raw values
from the sensors into stable position data.

Gyroscope Sensor Working Principle:

The Coriolis force or the Coriolis effect is used in the measurement of angular momentum. A
gyroscope sensor works on the principle of conservation of angular momentum. It works by
preserving the angular momentum.

List of materials:
Arduino Uno
Jumper wires
Breadboard
GY-521 module
Wiring scheme:
The GY-521 breakout has eight pins:

 VCC (The breakout board has a voltage regulator. Therefore, you can connect the board
to 3.3V and 5V sources.)
 GND
 SCL (Serial Clock Line of the I2C protocol.)
 SDA (Serial Data Line of the I2C protocol.)
 XDA (Auxiliary data => I2C master serial data for connecting the module to external
sensors.)
 XCL (Auxiliary clock => I2C master serial clock for connecting the module to external
sensors.)
 AD0 (If this pin is LOW, the I2C address of the board will be 0x68. Otherwise, if the pin
is HIGH, the address will be 0x69.)
 INT (Interrupt digital output)

Wiring layout:

We use only of the first four pins: VCC, GND, SDA, and SCL.

 First, we connect the module’s VCC to the Arduino’s 5V pin.


 Then, the module’s GND is connected to one of the Arduino’s GND pins.
 Next, we have to set up the I2C connection between the module and the Arduino.
 An Arduino Uno, just connect SCL to SCL and SDA to SDA.

If an Arduino Uno without SCL and SDL pins, then connect the Arduino’s A4 pin to the
module’s SDA pin. Next, connect the Arduino’s A5 pin to the module’s SCL pin.
Code:

// (c) Michael Schoeffler 2017, http://www.mschoeffler.de

#include "Wire.h" // This library allows you to communicate with I2C devices.

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050.


MPU 6050. If AD0 pin is set to HIGH, the
I2C address will be 0x69.

int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw


data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data

char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings


will have the same length
h in the debug monitor.
sprintf(tmp_str, "%6d", i);
return tmp_str;
}
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521
board)
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
}
void loop() {
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-
6050 Register Map and Descriptions Revision 4.2, p.40]
Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As
a result, the connection is kept active.
Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers

// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B
(ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D
(ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H)
and 0x40 (ACCEL_ZOUT_L)
temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and
0x42 (TEMP_OUT_L)
gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44
(GYRO_XOUT_L)
gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46
(GYRO_YOUT_L)
gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48
(GYRO_ZOUT_L)

// print out data


Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
// the following equation was taken from the documentation [MPU-6000/MPU-6050 Register
Map and Description, p.30]
Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
Serial.println();
// delay
delay(1000);
}

Lab task: Write down at least 3 applications of gyroscope sensor

1) Sensing Angular Velocity:

It can be used to sense the rate of change of angular motion in moving bodies. This can be used
for detecting athletic movement.

2) Sensing Angles:

The angles can also be detected using the gyroscope sensor. This application is used in car
navigations and game controllers.

3) Sensing Control Mechanism:

We can also use a gyroscopic sensor to detect vibration due to various external factors. We can
use this application for camera-shake control and vehicle control.
Lab: Use of passive infra-red sensor

Objectives:

 To understand what a passive infra-red sensor and it’s working principle.


 To understand how to use passive infra-red sensor.
 To understand the applications of passive infra-red sensor.

Theoretical Background:

A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light
radiating from objects in its field of view. They are most often used in PIR-based motion
detectors. PIR sensors are commonly used in security alarms and automatic lighting applications.
PIR sensors detect general movement, but do not give information on who or what moved. For
that purpose, an imaging IR sensor is required.
PIR sensors are commonly called simply "PIR", or sometimes "PID", for "passive infrared
detector". The term passive refers to the fact that PIR devices do not radiate energy for detection
purposes. They work entirely by detecting infrared radiation (radiant heat) emitted by or
reflected from objects.
The output of PIR motion detection sensor can be connected directly to one of the Arduino
(or any microcontroller) digital pins. If any motion is detected by the sensor, this pin value
will be set to “1”. The two potentiometers on the board allow you to adjust the sensitivity
and delay time after detecting a movement.
PIR sensor working principle:
Passive Infra Red sensors can detect movement of objects that radiate IR light (like human
bodies). Therefore, using these sensors to detect human movement or occupancy in security
systems is very common. Initial setup and calibration of these sensors takes about 10 to 60
seconds.
The part needed:

1.Arduino uno or clone

2.PIR Sensor

3.breadboard

4.led(any colour)

5.buzzer
Connections:

ARDUINO UNO PIR SENSOR

+5V---------------------------------------+5V(VCC)

GND--------------------------------------GND

5 PIN-------------------------------------OUT

Circuit diagram:
Code:
/*
PIR HCSR501
modified on 5 Feb 2019
by Saeed Hosseini @ ElectroPeak
https://electropeak.com/learn/guides/
*/
int ledPin = 13; // LED
int pirPin = 2; // PIR Out pin
int pirStat = 0; // PIR status
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop(){
pirStat = digitalRead(pirPin);
if (pirStat == HIGH) { // if motion detected
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.println("Hey I got you!!!");
}
else {
digitalWrite(ledPin, LOW); // turn LED OFF if we have no motion
}
}

Connection of PIR output to any digital pin.


There is a jumper behind this module. If you move the jumper to L position, the sensor will
‘toggle’ (change state) whenever motion is detected. This is unlikely to be of much use in a
practical applications. This mode is called non-triggering or Single Triggering mode.
Moving the jumper to the H position will result in the more usual sensor logic. The sensor
will turn on when motion is detected and turn off a while after the last motion is detected.
This sensor will reset the timer (which would otherwise turn the output off) each time motion
is detected; this would be applicable, for example, for room occupancy lighting control
where you don’t want the lights to blink off while the unit resets. This is called Retriggering
mode. (or repeatable trigger mode).
There are also two potentiometers behind this module. By changing the SENSITIVITY
potentiometer, you can reduce or increase the sensitivity of the sensor (clockwise increase),
and also by changing TIME potentiometer the output delay after movement detection will be
changed.
Lab task: Label the pins on the sensor module

The PIR sensor has three pins

 Vcc
 GND
 Output pin in the middle.

You might also like