Demo entry 5859379

Temp & 10DOF Sensor Test

   

Submitted by Zishun Yu on Jul 22, 2016 at 16:55
Language: C++. Code size: 2.2 kB.

#include <Adafruit_BMP085.h>

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_BMP085.h>

Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
Adafruit_BMP085 bmp;

void setup() {
Serial.begin(9600);
 //gyro
   gyro.enableAutoRange(true);
  
  /* Initialise the sensor */
  if(!gyro.begin())
  {
    /* There was a problem detecting the L3GD20 ... check your connections */
    Serial.println("Ooops, no L3GD20 detected ... Check your wiring!");
    while(1);
  }

  Serial.begin(9600);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
}

void loop() {
  sensors_event_t event; 
  gyro.getEvent(&event);
  Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print("  ");
    
//BMP
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");  
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

    
//MCP9700AE Temp Sensors
int sensorPin[4];
  sensorPin[0] = 12;
  sensorPin[1] = 13;
  sensorPin[2] = 14;
  sensorPin[3] = 15;
  float vol = 5.0;
//  float voltage[4];
//  float temperatureC[4];
  float voltage[4];
  float temperatureC[4];
  String s = "";
  for (int i = 0; i<4; i++){
    float reading = analogRead(sensorPin[i]);
    delay(10);
    // converting that reading to voltage, for 3.3v arduino use 3.3 
    voltage[i] = reading*vol;
    voltage[i] /= 1024.0;
    //converting from 10 mv per degree wit 500 mV offset
    //to degrees ((volatge - 500mV) times 100)
    temperatureC[i]=(voltage[i]-0.5)*100;

    Serial.print("Temp ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(temperatureC[i]);
  }
      delay(1000);
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).