Bed_Data

Bed Behavior Research

Arduino code for Bed_data

30.03.2010 (12:03 am) – Filed under: Arduino ::

int sensorValue[80]; // an array to store the sensor values

// the address pins will go in order from the first one:
#define firstAddressPin 8

#define ThermistorPIN 0 // Analog Pin 0
double temp;

//////////////////////////////temperature alg

#include
//Schematic:
// [Ground] —- [10k-Resister] ——-|——- [Thermistor] —- [+5v]
// |
// Analog Pin 0

double Thermistor(int RawADC) {
// Inputs ADC Value from Thermistor and outputs Temperature in Celsius
// requires: include
// Utilizes the Steinhart-Hart Thermistor Equation:
// Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}
// where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
long Resistance;
double Temp; // Dual-Purpose variable to save space.
Resistance=((10240000/RawADC) – 10000); // Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024/ADC)
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // “Temp” means “Temporary” on this line.
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp)); // Now it means both “Temporary” and “Temperature”
Temp = Temp – 273.15; // Convert Kelvin to Celsius // Now it only means “Temperature”

// Uncomment this line for the function to return Fahrenheit instead.
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit
return Temp; // Return the Temperature
}

double printDouble(double val, byte precision) {
// prints val with number of decimal places determine by precision
// precision is a number from 0 to 6 indicating the desired decimal places
// example: printDouble(3.1415, 2); // prints 3.14 (two decimal places)

if( precision > 0) {

unsigned long frac, mult = 1;
byte padding = precision -1;
while(precision–) mult *=10;
if(val >= 0) frac = (val – int(val)) * mult;
else frac = (int(val) – val) * mult;
unsigned long frac1 = frac;
while(frac1 /= 10) padding–;

if(frac > 0.5){
val = val+1;
}
else{
val = val;
}

Serial.print((int) val);
}
}

////////////////end of temp

int analogInput = 0;
int sensorNum = 0;

void setup() {
Serial.begin(115200);
// set the output pins:
for (int pinNumber = firstAddressPin; pinNumber < firstAddressPin + 4; pinNumber++) {
pinMode(pinNumber, OUTPUT);
}
}

void loop() {

// iterate once for every multiplexer (called muxes for short):
for (int mux = 0; mux < 5; mux++) {

for (int channelNum = 0; channelNum < 16; channelNum ++) {
// determine the four address pin values from the channelNum:
setChannel(channelNum);

// read the analog input and store it in the value array:
sensorValue[channelNum] = analogRead(analogInput+mux);

if(analogInput+mux == 4&& channelNum == 14){
//////temp

temp=sensorValue[channelNum];

temp = Thermistor(temp); // read ADC and convert it to Celsius
//Serial.print(", Celsius: "); printDouble(temp,3); // display Celsius

temp = (temp * 9.0)/ 5.0 + 32.0; // converts to Fahrenheit

// Serial.print("Fahrenheit: ");
printDouble(temp,3); // display Fahrenheit
Serial.print(",");

}
else{
// print the values as a single tab-separated line:
Serial.print(sensorValue[channelNum], DEC);
Serial.print(",");
}
}
}
// print a carriage return at the end of each read of the mux:
Serial.println();

}

void setChannel(int whichChannel) {
for (int bitPosition = 0; bitPosition < 4; bitPosition++) {
// shift value x bits to the right, and mask all but bit 0:
int bitValue = (whichChannel >> bitPosition) & 1;
// set the address pins:
int pinNumber = firstAddressPin + bitPosition;
digitalWrite(pinNumber, bitValue);
}
}

Bed_Data

28.02.2010 (11:27 pm) – Filed under: instructions ::

Concept: Create a bedAPI to control log sleep, and have a smart house system that can adjust ambiance sleep settings.

Content: FSR matrix, camera tracking, light, temperature, and noise sensors to log bed data.

Context: Your room.

Initial thoughts: We wanted to create an under mattress sensor system to detect weight shifts during sleep without the use of a camera.

Figure 1. Diagram of installation

Figure 2. Diagram of system flow.

If you want to build your own Bed_Data, you have to follow these are the hardware that you need:

FSR matrix (DIY) (72)

Camera (1)

Photocell (1)

Thermistor (1)

Microphone (1)

Arduino (1)

Terminals (12)

CD4067 (6)

Resistors (72)

Wires

We used force sensors matrix(6*12) to detect pressure on the bed. We are looking for places on the bed that you apply your force on. We are trying to understand how your bed sees you while you are sleeping.

Figure 3. Wires, force sensors and the bed

Figure 4. Force sensors

Figure 5. Terminals, sensors, wires, Arduino, multiplexers

We used terminals (with 8 inputs) to connect each line of sensor. Then on the other side, we used ribbon cables to connect terminals to multiplexer breadboard. Then we connected the sensor wires to CD4067 as our multiplexers. There is a good documentation by Tom Igoe.

Figure 6. Photocell and thermistor

We add temperature and photocell to understand what is going on in the environment. These sensors are giving us temperature and amount of light in the room. We connected all of these sensors to multiplexers and multiplexers to Arduino. Then we used Arduino code from Tom Igoe’s multiplexer example . We used 115200 boudrate for our serial communication.

Then we collect all the values in processing. We also add a webcam from the ceiling and used processing to get images. We mapped force sensor values on image to show force on different parts of the bed. Values from the force sensors are changing the transparency values of the rectangles (which represents force sensors).

We also used the microphone from the camera to get the noise level of the environment. We displayed temperature, lights values and time on the right side of the image.

Processing sketch kept taking snapshots from the processing application each 20 seconds. Then made a stop motion video of these images.

Figure 7. Bed_Data interface.

Feel free to contact us: info@beddata.com

How to multiplx

28.02.2010 (3:42 pm) – Filed under: Microcontroller ::

Here is a link to the tutorial we used. Arduino + 6 multiplexers to receive data from the FSR matrix. Multiplexers expand analog inputs by 16, and by daisy chaining more multiplexers…well you do the math.

How to FSR’s

20.12.2009 (11:24 pm) – Filed under: FSRs ::

See how we built the force resistance sensors (FSRs) by clicking the image link below.

Bed_Data video

20.12.2009 (1:47 pm) – Filed under: Visualization ::

Here are the first sleep logging visualizations we did: