Hello guys.
I am new at Arduino. Recently I buy Arduino UNO R3, and temperature, acceleration sensor from Lilypad (sparkfun). For temperature I get best reading with analogReference(INTERNAL), but when using this line I cant measure my acceleration. Kinda dont understand really this analogReference. Can someone explain me a bit ? Also help me get this acceleration working with this analogReference included ?
#include <math.h>
//Temperature sensor
unsigned int total; // max 64 readings
float tempC; // final temp
//Acceleration sensor
const int xpin = A1;
const int ypin = A2;
const int zpin = A3;
void setup() {
analogReference(INTERNAL); // enable the internal ~1.1volt bandgap reference
Serial.begin(9600);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void loop() {
// Temperature
total = 0; // reset value
for (int x = 0; x < 10; x++) { // read 10x
total = total + analogRead(A0); // add each value to a total
delay(50);
}
Serial.print("Analog reading : ");
Serial.println(total/10);
tempC = ((total * 0.0001025) - 0.5) * 100;
//float v = total * 4.9 / 1024;
//tempC = (v - 0.5) * 100;
Serial.print("Temperatura : ");
Serial.println(tempC -2, 1); // po dokumentaciji in nasih meritvah je -2 potreben
// End of Temperature
// Acceleration
int x = analogRead(xpin);
delay(1);
int y = analogRead(ypin);
delay(1);
int z = analogRead(zpin);
delay(1);
float zero_G = 512;
float scale = 102.3;
Serial.println();
Serial.print("x : ");
Serial.println(((float)x - zero_G)/scale);
Serial.print("y : ");
Serial.println(((float)y - zero_G)/scale);
Serial.print("z : ");
Serial.println(((float)z - zero_G)/scale);
// End of Acceleration
delay(1000); // some delay to slow readings
}