Final Project¶
This week I worked on defining my final project idea and started to getting used to the documentation process.
In our final project we will use many sensors and we will connect it to our microcontroller with i2c protocol
Sensors that we used¶
1-APDS9960
2-mpu-6050 6-Dof
3-SHT40
APDS9960:¶
The Broadcom APDS-9960 is a digital RGB, ambient light, proximity and gesture sensor device in a single 8-pin package. The device has an I2C compatible interface providing red, green, blue, clear (RGBC), proximity and gesture sensing with IR LED. The RGB and ambient light sensing feature detects light intensity under various lighting conditions and through various attentuation materials including darkened glass. In addition, the integrated UV-IR blocking filter enables accurate ambient light and correlated color temperature sensing. The proximity and gesture feature is factory-trimmed and calibrated to 100mm proximity detection distance without requiring customer calibrations. Gesture detection utilizes four directional photodiodes, integrated with visible blocking filter, to accurately sense simple UP-DOWN-RIGHT-LEFT gestures or more complex gestures. The addition of micro-optics lenses within the module provides high efficient transmission and reception of infrared energy. An internal state machine allows the device to be put into a low power state between RGBC, proximity and gesture measurements providing very low power consumption.
Features:¶
RGBC Light Sensor, Proximity and Gesture Detector with IR LED in an Optical Module
1-Miniature Package Size: L3.94 x W2.36 x H1.35 mm
2-I2C Interface Compatible with Dedicated Interrupt Pin
3-High Sensitivity Enabling Operation Behind Darkened Glass
4-RGBC Light Sensing with Integrated UV-IR Block Filter
5-Geometrically Arranged RGBC Photodiodes Providing Uniform Angular Response
6-Calibrated to 100mm Detection Distance Eliminating Customer End Product Calibration
7-Four Separate Photodiodes Sensitive to Different Directions
8-Proximity and Gesture Sensing with Integrated Visible Block Filter
9-Patented Shield Design Minimizing Proximity Cross Talk
10-Integrated Optical Lens Collimating IR LED Beam and Improving Photodiode Sensitivity.
11-Low Power Consumption: 1.0 µA typical in Sleep Mode
Applications¶
1-Display Backlight Control
2-Correlated Color Temperature Sensing
3-Cell Phone Touch-screen Disable
4-Digital Camera Touch-screen Disable
5-Mechanical Switch Replacement
6-Gesture Detection
THE PROGRAMING CODE¶
// File: ambientLight.ino
//
// Read the clear channel of the on-board APDS 9960 light sensor
// and print the reading to the Serial object for display in the
// Serial Monitor or Serial Plotter
//
// Derived from the color_sensor.ino sketch in the Examples library
// by Adafruit. See http://www.adafruit.com/products/3595
#include "Adafruit_APDS9960.h" // Use the Adafruit Library for APDS9960
Adafruit_APDS9960 apds; // Create a global object called apds
// ----------------------------------------------------------------------------
void setup() {
Serial.begin(115200); // Open Serial object for messages and data
delay(3000); // Wait for USB connection
setupAPDSambientLight(); // Configure APDS9960 to read ambient light
}
// ----------------------------------------------------------------------------
void loop() {
int level; // Value of clear channel from APDS 9960
level = readAmbientLight(); // Get the ambient light level
Serial.println(level);
delay(50);
}
// ----------------------------------------------------------------------------
// Configure the APDS9960 sensor to read ambient light levels, not gestures.
//
void setupAPDSambientLight() {
// -- Check to see that the sensor is connected
if ( !apds.begin() ) {
Serial.println("Failed to initialize device! Please check your wiring.");
}
else {
Serial.println("Device initialized!");
}
apds.enableColor(true); // Enable color sensing
}
// ----------------------------------------------------------------------------
// Read the light sensors on the APDS 9960. Return the level of the clear
// channel as an indicator of the ambient light level. Note that the Adafruit
// APDS9960 Library does not have a method for reading only the clear channel.
// In the interest of simplicity, we use the available methods in the library
// and incurr the small extra overhead of reading the R, G, B and clear channels
// when we only need the value from the clear channel
//
int readAmbientLight() {
uint16_t r, g, b, c; // Variables to store color data returned by APDS
while( !apds.colorDataReady() ) { // Wait for color data to be ready
delay(5);
}
apds.getColorData(&r, &g, &b, &c); // Retrieve the color data
return(c); // Only the clear channel matters for this application
}
How we will use it :¶
We will use it to provide the light intensity as the LDR sensor that we used on input&output assignment
mpu-6050 6-Dof:¶
MPU-6050 Six-Axis (Gyro + Accelerometer) MEMS MotionTracking™ Devices The MPU-6050™ parts are the world’s first MotionTracking devices designed for the low power, low cost, and high-performance requirements of smartphones, tablets and wearable sensors. The MPU-6050 incorporates InvenSense’s MotionFusion™ and run-time calibration firmware that enables manufacturers to eliminate the costly and complex selection, qualification, and system level integration of discrete devices in motion-enabled products, guaranteeing that sensor fusion algorithms and calibration procedures deliver optimal performance for consumers. The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together with an onboard Digital Motion Processor™ (DMP™), which processes complex 6-axis MotionFusion algorithms. The device can access external magnetometers or other sensors through an auxiliary master I²C bus, allowing the devices to gather a full set of sensor data without intervention from the system processor. The devices are offered in a 4 mm x 4 mm x 0.9 mm QFN package.
The InvenSense MotionApps™ Platform that comes with the MPU-6050 abstracts motion-based complexities, offloads sensor management from the operating system, and provides a structured set of APIs for application development. For precision tracking of both fast and slow motions, the parts feature a user-programmable gyro full-scale range of ±250, ±500, ±1000, and ±2000 °/sec (dps), and a user-programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g. Additional features include an embedded temperature sensor and an on-chip oscillator with ±1% variation over the operating temperature range.
Features:¶
1-Digital-output of 6-axis MotionFusion data. 9-axis fused data from Motion Processing Library
2-Tri-Axis angular rate sensor (gyro) with a sensitivity up to 131 LSBs/dps and a full-scale range of ±250, ±500, ±1000, and ±2000dps
3-Tri-Axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g
4-Reduced settling effects and sensor drift by elimination of board-level cross-axis alignment errors between accelerometers and gyroscopes
5-Digital Motion Processing™ (DMP™) engine offloads complex MotionFusion, sensor timing synchronization and gesture detection
6-MotionApps™ Platform support for Android, Linux, and Windows
7-Embedded algorithms for run-time bias and compass calibration in library. No user intervention required
8-Digital-output temperature sensor
9-Digital input on FSYNC pin to support video Electronic Image Stabilization and GPS
10-Programmable interrupt supports gesture recognition, panning, zooming, scrolling, and shake detection
11-VDD Supply voltage range of 2.375V–3.46V; VLOGIC (MPU-6050) at 1.8V±5% or VDD
12-Gyro operating current: 3.6mA (full power, gyro at all rates)
13-Gyro + Accel operating current: 3.8mA (full power, gyro at all rates, accel at 1kHz sample rate)
14-Accel low power mode operating currents: 10µA at 1Hz, 20µA at 5Hz, 70µA at 20Hz, 140µA at 40Hz
15-Full Chip Idle Mode Supply Current: 5µA
16-400kHz Fast Mode I²C or up to 20MHz SPI (MPU-6000 only) serial host interfaces
17-User self test
18-10,000g shock tolerant
19-Smallest and thinnest package for portable devices (4x4x0.9mm QFN)
20-RoHS and Green compliant
Applications:¶
1-This module is used in Blurfree technology for video or still image stabilization.
2-For recognizing in-air gestures this module is used.
3-In the security and authentication systems, MPU6050 is used for gesture recognition.
4-For “no-touch” UI application control and navigation MPU6050 is used.
5-In motion command technology for gesture short-cuts, this module is used.
6-This module has also found application in motion enabled gaming and application frameworks.
7-In InstantGesture -IG, MPU6050 is used for gesture recognition.
8-Due to its small size, this module is used in handsets and portable gaming equipment.
9-Motion-based game controllers also have this module.
10-3D remote controllers, 3D mice also use this module.
11-Wearables used for health, fitness and sports also containMPU6050.
12-This module can also be found in many toys.
13-For IMU measurements MPU6050 is used.
14-In drones and quadcopters, MPU6050 is used for position control.
15-This module has also found application in self-balancing robots.
16-MPU6050 is highly preferred for robotic arm control.
17-Humanoid robots also use this module for tilt, rotation, orientation detection.
THE PROGRAMMING CODE¶
// Basic demo for accelerometer readings from Adafruit MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
How we will use it :¶
We will use it to track the motion same that we used on input&output assignment
SHT40:¶
The SHT4X is the 4th generation digital temperature and humidity sensor from Sensirion. In line with Sensirion’s industry-proven humidity and temperature sensors, the SHT40 offers consistent high accuracy within measuring range. The SHT40 sensor covers a humidity measurement range of 0 to 100%RH and a temperature detection range of -40°C to 125°C with a typical accuracy of ±1.8%RH and ±0.2℃. The internal variable power heater enables the device to work properly under extreme operating conditions like condensing environment. The board supply voltage of 3.3V to 5V and an current consumption below 0.15mA in low power mode make the SHT40 perfectly suitable for mobile or wireless battery-driven applications. It is suitable for urban environment monitoring, intelligent buildings, industrial automation, smart home and other Internet of Things applications.
Specifications:¶
1-Operating Voltage: 3.3V-5V
2-Operating Current: 0.45mA
3-Communication Interface: I2C
4-Response Time: 8s (tau63%)
5-Humidity Measurement Range: 0~100%RH
6-Humidity Measurement Accuracy: ±1.8%
7-Temperature Measurement Range: -40~+125℃ (-40 to +275℉)
8-Temperature Measurement Accuracy: ±0.2℃
9-Dimension: 14x17mm/0.55x0.67”
10-Mounting Hole Size: M2 (2mm)
11-Mounting Hole Pitch: 10mm
Features:¶
1- High Accuracy
2-Low Power Consumption
3- Small Size
4-Fast Response
Applications:¶
1-Intelligent Buidings and Furniture
2-Weather Station
3-Warehouses
4-Animals and Plants Culture
5-Animal Incubator
6-Germinating Box for plant see
THE PROGRAMMING CODE¶
This is an example for the SHT4x Humidity & Temp Sensor
Designed specifically to work with the SHT4x sensor from Adafruit
----> https://www.adafruit.com/products/4885
These sensors use I2C to communicate, 2 pins are required to
interface
****************************************************/
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
void setup() {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit SHT4x test");
if (! sht4.begin()) {
Serial.println("Couldn't find SHT4x");
while (1) delay(1);
}
Serial.println("Found SHT4x sensor");
Serial.print("Serial number 0x");
Serial.println(sht4.readSerial(), HEX);
// You can have 3 different precisions, higher precision takes longer
sht4.setPrecision(SHT4X_HIGH_PRECISION);
switch (sht4.getPrecision()) {
case SHT4X_HIGH_PRECISION:
Serial.println("High precision");
break;
case SHT4X_MED_PRECISION:
Serial.println("Med precision");
break;
case SHT4X_LOW_PRECISION:
Serial.println("Low precision");
break;
}
// You can have 6 different heater settings
// higher heat and longer times uses more power
// and reads will take longer too!
sht4.setHeater(SHT4X_NO_HEATER);
switch (sht4.getHeater()) {
case SHT4X_NO_HEATER:
Serial.println("No heater");
break;
case SHT4X_HIGH_HEATER_1S:
Serial.println("High heat for 1 second");
break;
case SHT4X_HIGH_HEATER_100MS:
Serial.println("High heat for 0.1 second");
break;
case SHT4X_MED_HEATER_1S:
Serial.println("Medium heat for 1 second");
break;
case SHT4X_MED_HEATER_100MS:
Serial.println("Medium heat for 0.1 second");
break;
case SHT4X_LOW_HEATER_1S:
Serial.println("Low heat for 1 second");
break;
case SHT4X_LOW_HEATER_100MS:
Serial.println("Low heat for 0.1 second");
break;
}
}
void loop() {
sensors_event_t humidity, temp;
uint32_t timestamp = millis();
sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
timestamp = millis() - timestamp;
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
Serial.print("Read duration (ms): ");
Serial.println(timestamp);
delay(1000);
}
How we will use it :¶
We will use it to provide the temperature and humidity as we used the humidity and temperature sensor on input&output assignment