Lab Reports Inst and Control Lab
Lab Reports Inst and Control Lab
Objectives:
Theoretical Background:
Working principle:
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:
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.
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.
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:
#include "Wire.h" // This library allows you to communicate with I2C devices.
// "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)
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.
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:
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:
2.PIR Sensor
3.breadboard
4.led(any colour)
5.buzzer
Connections:
+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
}
}
Vcc
GND
Output pin in the middle.