8. Gesture Sensor
#include <SparkFun_APDS9960.h>
#include <Wire.h>
#define APDS9960_INT 23 // Needs to be an interrupt pin
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void setup(){
pinMode(APDS9960_INT, INPUT);
Serial.begin(115200);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - GestureTest"));
Serial.println(F("--------------------------------"));
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}
if ( apds.enableGestureSensor(true) ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
if (apds.setGestureGain(GGAIN_2X))
{
Serial.println("Gesture Gain Set");
}
else
{
Serial.println(F("Something went wrong during gesture sensor init!"));
}
}
void loop() {
pinMode(2,OUTPUT);
pinMode(13,OUTPUT);
pinMode(32,OUTPUT);
if( isr_flag == 1 ) {
detachInterrupt(0);
handleGesture();
isr_flag = 0;
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
}
}
void interruptRoutine() {
isr_flag = 1;
}
void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
digitalWrite(2,HIGH);
break;
case DIR_DOWN:
Serial.println("DOWN");
digitalWrite(2,HIGH);
break;
case DIR_LEFT:
Serial.println("LEFT");
digitalWrite(2,HIGH);
break;
case DIR_RIGHT:
Serial.println("RIGHT");
digitalWrite(13,HIGH);
break;
case DIR_NEAR:
Serial.println("NEAR");
digitalWrite(13,HIGH);
break;
case DIR_FAR:
Serial.println("FAR");
digitalWrite(13,HIGH);
break;
default:
Serial.println("NONE");
}
}
}
OUTPUT: How to check ?
1. Go to sketch
2. Next is include libraries --->manage libraries----> search for (APDS9960) ------> select(SPARKFUN APDS9960 RGB AND GESTURE SENSOR)see if is installed or not .
3.If not installed, install with all libraries.
4. If it is installed with all libraries then ---> in the include libraries Search for
SPARKFUN APDS9960 select it and upload to the arduino board.
9. Environment Monitoring Module(BMP280)
#include<Wire.h>
#include<Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
#define SEALEVELPRESSURE_HPA (1013.25)
float tempC,tempF,atPressure,altitude,humidity;
void setup() {
Serial.begin(115200);
Serial.println(F("BMP280 test"));
if(!bmp.begin(BMP280_ADDRESS_ALT,BMP280_CHIPID)){
Serial.println(F("Could not find a valid BMP280 sensor,check wiring or""try a different address!"));
while(1)delay(10);
}
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
}
void loop() {
printValues();
delay(2000);
}
void printValues(){
Serial.print("Temperature= ");
tempC = bmp.readTemperature();
//Serial.print(bme.readTemerature());
Serial.print(tempC);
Serial.println("deg C");
Serial.print("Temperature= ");
Serial.print(1.8*tempC+32);
Serial.println("deg F");
Serial.print("Pressure=");
atPressure=bmp.readPressure()/100.0F;
Serial.print(atPressure);
Serial.println("hPa");
Serial.print("Altitude= ");
altitude=bmp.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print(altitude);
Serial.print("m");
Serial.println();
}
10. Heart Rate Monitoring Module (MAX30102)
11.MULTI-AXIS ACCELEROMETER
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
MPU6050 mpu;
float baseline[3];
float features[3];
float motion_threshold = 0.7;
void setup(){
Wire.begin();
Serial.begin(115200);
mpu.initialize();
calibrate();
}
void loop(){
float ax,ay,az;
mpu_read(&ax,&ay,&az);
ax=ax-baseline[0];
ay=ay-baseline[1];
az=az-baseline[2];
mpu_record();
delay(2000);
}
void mpu_read(float*ax,float*ay,float*az) {
int16_t _ax,_ay,_az,_gx,_gy,_gz;
mpu.getMotion6(&_ax,&_ay,&_az,&_gx,&_gy,&_gz);
*ax=_ax/16384.0;
*ay=_ay/16384.0;
*az=_az/16384.0;
}
void calibrate(){
float ax,ay,az;
for(int i=0;i<10;i++){
mpu_read(&ax,&ay,&az);
delay(100);
}
baseline[0]=ax;
baseline[1]=ay;
baseline[2]=az;
}
void mpu_record(){
float ax,ay,az;
float aax,aay,aaz;
String position;
mpu_read(&ax,&ay,&az);
ax=ax-baseline[0];
ay=ay-baseline[1];
az=az-baseline[2];
features[0]=ax;
features[1]=ay;
features[2]=az;
Serial.print(features[0]);
Serial.print("");
Serial.print(features[1]);
Serial.print("");
Serial.println(features[2]);
aax=fabs(ax);
aay=fabs(ay);
aaz=fabs(az);
Serial.print(aax);
Serial.print("");
Serial.print(aay);
Serial.print("");
Serial.println(aaz);
position="Upright";
if(aax>motion_threshold)
{
if(ax>0)
position="Left";
else
position="Right";
}
if(aay>motion_threshold)
{
if(ay>0)
position="Backward";
else
position="Forward";
}
Serial.println(position);
}
12.MAGNETIC SWITCH INTERFACE
#define magSW 16void setup() {
pinMode(magSW,INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
int sw_status;
sw_status=digitalRead(magSW);
if(sw_status)
Serial.println("Window open");
else
Serial.println("Window closed");
delay(1000);
}
13.OLED DISPLAY INTERFACE
#include<Wire.h>
#include"SSD1306.h"
SSD1306 display(0x3c,21,22);
String myString;
int count;
void setup() {
OLEDInit();
}
void loop() {
OLEDUpdate();
count++;
if(count==10) count=0;
delay(1000);
}
void OLEDInit(){
display.init();
display.setFont(RomanIMT_Plain_24);
}
void OLEDUpdate(){
display.clear();
myString="Hello"+String(count);
display.drawString(0,0,myString);
display.display();
}