Problemen met Multiplexer

Hallo,

Voor school moet ik een project maken met Arduino. Ik gebruik hierbij de analoge 16 ch CD74HC4067 multiplexer samen met een SD shield datalogger.
Ik werk met zeven verschillende sensoren waarvan drie verbonden zijn met arduino zelf en vier verbonden zijn met de multiplexer.

Ik krijg het maar niet te goei! :confused:
Apart werkt elke sensor wel goed, maar ze allemaal tegelijk runnen geeft ongeloofwaardige waardes.

Weet er iemand raad.. of wat ik fout doet? Want ik zie het niet meer :frowning:

Ik ben nieuw hier, dus wist niet goed hoe ik de code moest toevoegen,
dan maar op deze manier:

#include <math.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

RTC_DS1307 RTC;

//Digitale paarten
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//SIG pin
int SIG_pin = 0;

// hartslag

// Variables
int pulsePin = 1; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

// Regards Serial OutPut -- Set This Up to your needs
static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse

const int xBpin = readMux (5); // x-axis of the accelerometer
const int yBpin = readMux (6); // y-axis
const int zBpin = readMux (7); // z-axis (only on 3-axis models)
const int xHpin = readMux (1); // x-axis of the accelerometer
const int yHpin = readMux (2); // y-axis
const int zHpin = readMux (3); // z-axis (only on 3-axis models)

int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};

int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};

//loop through the 4 sig
//for(int i = 0; i < 4; i ++){
//digitalWrite(controlPin_, muxChannel[channel]);_
* //}*
* //read the value at the SIG pin*
* int val = analogRead(SIG_pin);
_
//return the value*_
* return val;*
* }*

void setup()
* {*
* pinMode(s0, OUTPUT); *
* pinMode(s1, OUTPUT); *
* pinMode(s2, OUTPUT); *
* pinMode(s3, OUTPUT); *

* //hartslag*
* pinMode(blinkPin,OUTPUT); *
* pinMode(fadePin,OUTPUT); *
* interruptSetup(); *

* Serial.begin(57600);*
* Wire.begin();*
* RTC.begin();*

* if (! RTC.isrunning()) {*
* Serial.println("RTC is NOT running!");*
* RTC.adjust(DateTime(DATE, TIME));
_
}*_

* Serial.print("Initializing SD card...");*
* pinMode(10, OUTPUT);*
* if (!SD.begin(4)) {*
* Serial.println("initialization failed!");*
* return;*
* }*
* Serial.println("initialization done.");*

* // accelerometer*
* analogReference(EXTERNAL);*

* pinMode(xBpin, INPUT);*
* pinMode(yBpin, INPUT);*
* pinMode(zBpin, INPUT);*
* pinMode(xHpin, INPUT);*
* pinMode(yHpin, INPUT);*
* pinMode(zHpin, INPUT);*
}

* //code temperatuur*
* double Thermister(int RawADC) *
*{ *
* double Temp;*
* Temp = log(((10240000/RawADC) - 10000));*
_ Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
* Temp = Temp - 273.15; *
* return Temp; *
}
void loop()
{
File myFile = SD.open("Data.txt", FILE_WRITE);
if(myFile)
_
{

* DateTime now = RTC.now();*

* myFile.print(now.day(), DEC);*
* myFile.print('/');*
* myFile.print(now.month(), DEC);*
* myFile.print('/');*
* myFile.print(now.year(), DEC);*
* myFile.print("\t");*
* myFile.print(now.hour(), DEC);*
* myFile.print(':');*
* myFile.print(now.minute(), DEC);*
* myFile.print(':');*
* myFile.print(now.second(), DEC);*
* myFile.print("\t");*
* Serial.print(now.day(), DEC);*
* Serial.print('/');*
* Serial.print(now.month(), DEC);*
* Serial.print('/');*
* Serial.print(now.year(), DEC);*
* Serial.print("\t");*
* Serial.print(now.hour(), DEC);*
* Serial.print(':');*
* Serial.print(now.minute(), DEC);*
* Serial.print(':');*
* Serial.print(now.second(), DEC);*
* Serial.print("\t");*

* {*

* //temperatuur*
* int value; //Create an integer variable*
* double temp; //Variable to hold a temperature value*
* value=readMux(0); //Read the analog port 0 and store the value in val*
* temp=Thermister(value); //Runs the fancy math on the raw analog value*
* //Serial.println(temp); //Print the value to the serial port*
* Serial.print("Temperatuur= " + String (temp) + " graden ");*

* //ademhaling*
* int ademhaling = analogRead (2);*
* myFile.print("Resp:\t" + String (ademhaling) + "\t");*
* Serial.print("Resp:\t" + String (ademhaling) + "\t");*

* //gsr sensor*
* int gsrValue = readMux(4);*
* myFile.print("GSR:\t" + String ( gsrValue) + "\t");*
* Serial.print("GSR:\t" + String ( gsrValue) + "\t");*

* //vibratie*
* int vibratie = analogRead (3);*
* myFile.print("Vbr:\t" + String ( vibratie) + "\t");*
* Serial.print("Vbr:\t" + String ( vibratie) + "\t");*

* //accelerometer hoofd*
* float zeroH_G = 512.0;
_
float scaleH = 106; *_

* const int xHpin = readMux (1);*
* int xH = analogRead(xHpin);*
* myFile.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");*

* const int yHpin = readMux (2);*
* int yH = analogRead(yHpin);*
* myFile.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");*

* const int zHpin = readMux (3);*
* int zH = analogRead(zHpin);*
* myFile.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");*

* //accelerometer been*
* float zeroB_G = 512.0;
_
float scaleB = 106; *_

* const int xBpin = readMux (5);*
* int xB = analogRead(xBpin);*
* myFile.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");*

* const int yBpin = readMux (6);*
* int yB = analogRead(yBpin);*
* myFile.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");*

* const int zBpin = readMux (7);*
* int zB = analogRead(zBpin);*
* myFile.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");*

* //harstlag*

* serialOutput() ; *

* if (QS == true){ *
* digitalWrite(blinkPin,HIGH); // Blink LED, we got a beat. *
* fadeRate = 255; *
* serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. *
* QS = false; // reset the Quantified Self flag for next time *
* }*

* ledFadeToBeat(); // Makes the LED Fade Effect Happen*

* myFile.print("Hartslag:\t" + String (BPM) + "\tBPM\t"); *

* }*
* Serial.println();*
* myFile.println(); *

* delay (100);*
myFile.close();}
}

void ledFadeToBeat(){
* fadeRate -= 15; // set LED fade value*
* fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!*
* analogWrite(fadePin,fadeRate); // fade LED*
* } *

DE_CODE.ino (7.54 KB)

#include <math.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

RTC_DS1307 RTC;

//Digitale paarten
// liever define gebruiken
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//SIG pin
int SIG_pin = 0;

// hartslag

// Variables
int pulsePin = 1; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

// Regards Serial OutPut -- Set This Up to your needs
static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
// dit moet in setup staan want het is een functie.
//en wat staat er in readmux?
const int xBpin = readMux (5); // x-axis of the accelerometer
const int yBpin = readMux (6); // y-axis
const int zBpin = readMux (7); // z-axis (only on 3-axis models)
const int xHpin = readMux (1); // x-axis of the accelerometer
const int yHpin = readMux (2); // y-axis
const int zHpin = readMux (3); // z-axis (only on 3-axis models)

// functies:

int readMux(int channel){
doe al dit init werk voor of in de setup
int controlPin[] = {s0, s1, s2, s3};

int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};

//loop through the 4 sig
//for(int i = 0; i < 4; i ++){ // hier moet staan controlpin of zo ik weet hier niet meer wat je wilt.
//digitalWrite(controlPin_, muxChannel[channel]); muxchannel heeft 2 dimensies_
* //}*
* //read the value at the SIG pin*
* int val = analogRead(SIG_pin);
_
//return the value*_
* return val;*
* }*

void setup()
{
* pinMode(s0, OUTPUT);*
* pinMode(s1, OUTPUT);*
* pinMode(s2, OUTPUT);*
* pinMode(s3, OUTPUT);*

* //hartslag*
* pinMode(blinkPin,OUTPUT); *
* pinMode(fadePin,OUTPUT); *
* interruptSetup(); *

* Serial.begin(57600);*
* Wire.begin();*
* RTC.begin();*

* if (! RTC.isrunning()) {*
* Serial.println("RTC is NOT running!");*
* RTC.adjust(DateTime(DATE, TIME));
_
}*_

* Serial.print("Initializing SD card...");*
* pinMode(10, OUTPUT);*
* if (!SD.begin(4)) {*
* Serial.println("initialization failed!");*
* return;*
* }*
* Serial.println("initialization done.");*

* // accelerometer*
* analogReference(EXTERNAL);*

* pinMode(xBpin, INPUT);*
* pinMode(yBpin, INPUT);*
* pinMode(zBpin, INPUT);*
* pinMode(xHpin, INPUT);*
* pinMode(yHpin, INPUT);*
* pinMode(zHpin, INPUT);*
}
* // zet functies bij elkaar*
* //code temperatuur*
* double Thermister(int RawADC)*
{
* double Temp;*
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
*Temp = Temp - 273.15; *
return Temp;
}
void loop()
hou het eerst eens simpel dus niet opslaan, ik denk dat je multiplexer niet goed gaat.
{
File myFile = SD.open("Data.txt", FILE_WRITE);
if(myFile)
{
* DateTime now = RTC.now();*

* myFile.print(now.day(), DEC);*
* myFile.print('/');*
* myFile.print(now.month(), DEC);*
* myFile.print('/');*
* myFile.print(now.year(), DEC);*
* myFile.print("\t");*
* myFile.print(now.hour(), DEC);*
* myFile.print(':');*
* myFile.print(now.minute(), DEC);*
* myFile.print(':');*
* myFile.print(now.second(), DEC);*
* myFile.print("\t");*
* Serial.print(now.day(), DEC);*
* Serial.print('/');*
* Serial.print(now.month(), DEC);*
* Serial.print('/');*
* Serial.print(now.year(), DEC);*
* Serial.print("\t");*
* Serial.print(now.hour(), DEC);*
* Serial.print(':');*
* Serial.print(now.minute(), DEC);*
* Serial.print(':');*
* Serial.print(now.second(), DEC);*
* Serial.print("\t");*

* {*

* //temperatuur*
* int value; //Create an integer variable*
* double temp; //Variable to hold a temperature value*
* value=readMux(0); //Read the analog port 0 and store the value in val*
* temp=Thermister(value); //Runs the fancy math on the raw analog value*
* //Serial.println(temp); //Print the value to the serial port*
* Serial.print("Temperatuur= " + String (temp) + " graden ");*

* //ademhaling*
* int ademhaling = analogRead (2);*
* myFile.print("Resp:\t" + String (ademhaling) + "\t");*
* Serial.print("Resp:\t" + String (ademhaling) + "\t");*

* //gsr sensor*
* int gsrValue = readMux(4);*
* myFile.print("GSR:\t" + String ( gsrValue) + "\t");*
* Serial.print("GSR:\t" + String ( gsrValue) + "\t");*

* //vibratie*
* int vibratie = analogRead (3);*
* myFile.print("Vbr:\t" + String ( vibratie) + "\t");*
* Serial.print("Vbr:\t" + String ( vibratie) + "\t");*

* //accelerometer hoofd*
* float zeroH_G = 512.0;
_
float scaleH = 106;*_

* const int xHpin = readMux (1);*
* int xH = analogRead(xHpin);*
* myFile.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");*

* const int yHpin = readMux (2);*
* int yH = analogRead(yHpin);*
* myFile.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");*

* const int zHpin = readMux (3);*
* int zH = analogRead(zHpin);*
* myFile.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");*

* //accelerometer been*
* float zeroB_G = 512.0;
_
float scaleB = 106;*_

* const int xBpin = readMux (5);*
* int xB = analogRead(xBpin);*
* myFile.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");*

* const int yBpin = readMux (6);*
* int yB = analogRead(yBpin);*
* myFile.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");*

* const int zBpin = readMux (7);*
* int zB = analogRead(zBpin);*
* myFile.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");*

* //harstlag*

* serialOutput() ; *

* if (QS == true){ *
* digitalWrite(blinkPin,HIGH); // Blink LED, we got a beat.*
* fadeRate = 255; *
* serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. *
* QS = false; // reset the Quantified Self flag for next time *
* }*

* ledFadeToBeat(); // Makes the LED Fade Effect Happen*

* myFile.print("Hartslag:\t" + String (BPM) + "\tBPM\t");*

* }*
Serial.println();
myFile.println();

* delay (100);*
myFile.close();}
}

void ledFadeToBeat(){
* fadeRate -= 15; // set LED fade value*
* fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!*
* analogWrite(fadePin,fadeRate); // fade LED*
* }*

Ik heb er even alles is uit gehaald, buiten 2 sensoren. De thermister werkt goed, maar hang ik er de piezo bij aan veranderd enkel de themister.

Wat bedoel je met dat mijn multiplexer niet goed staat? bedoel je mijn bedrading?
Met readMux bedoel ik aan welke poort hij aangesloten is op de multiplexer.

#include <math.h>

 
  //Digitale poorten
 #define s0  8
 #define s1  9
 #define s2  10
 #define s3  11

//SIG pin
 int SIG_pin = 0;
   
  
void setup()

 {
  Serial.begin(57600);
  
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 

  }
  
   //multiplexer
  int readMux(int channel){
//doe al dit init werk voor  of in de setup 
 int controlPin[] = {s0, s1, s2, s3};

 int muxChannel[16][4]={
   {0,0,0,0}, //channel 0
   {1,0,0,0}, //channel 1
   {0,1,0,0}, //channel 2
   {1,1,0,0}, //channel 3
   {0,0,1,0}, //channel 4
   {1,0,1,0}, //channel 5
   {0,1,1,0}, //channel 6
   {1,1,1,0}, //channel 7
   {0,0,0,1}, //channel 8
   {1,0,0,1}, //channel 9
   {0,1,0,1}, //channel 10
   {1,1,0,1}, //channel 11
   {0,0,1,1}, //channel 12
   {1,0,1,1}, //channel 13
   {0,1,1,1}, //channel 14
   {1,1,1,1}  //channel 15
 };

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
  }
  
   //code temperatuur
  double Thermister(int RawADC) 
{ 
   double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;              
 return Temp; 
}
  

  
void loop ()
  {
      //temperatuur (Thermister)
  int value;                //Create an integer variable
  double temp;            //Variable to hold a temperature value
  value=readMux(0);      //Read the analog port 0 and store the value in val
  temp=Thermister(value);   //Runs the fancy math on the raw analog value
  Serial.print("Temp= \t " + String (temp) + " \t c\t ");
    
      //ademhaling (Piezo)
  int ademhaling = readMux(1);
  Serial.print("Resp:\t" + String (ademhaling) + "\t");
  
  
  Serial.println();
  delay (100);
}

je gebruikt de variabele channel niet in readmux

Whoop, Het werkt! ;D 8)

Dan laat je programma maar eens zien!!!
en heb je er netjes commentaar ingezet, en een schema ofwel maak er een netjes presentabel geheel van.
en ik wil het best nakijken hoor,

Ik heb niet echt de code moeten aanpassen..
Mijn cruciale fout was, dat ik vergat rekening te houden welke pinnen de shields gebruikte :blush: l
De multiplexer heb ik van plaats veranderd é voila..
Ah en het probleem met de thermister was dat er een conflict was met analogReference(EXTERNAL) , dus die heb ik bij aan de 3.3v gehangen.

//library temperatuur
#include <math.h>

//library datalogger
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

//library sd shield
#include <SPI.h>
#include <SD.h>

//Mux digitale pins
int s0 = 6;        //digitale controle pin 6
int s1 = 7;        //digitale controle pin 7
int s2 = 8;        //digitale controle pin 8
int s3 = 9;        //digitale controle pin 9

//Mux analoge output
int SIG_pin = A0;  

//hartslag - Variabelen
int pulsePin = 1;                                
volatile int BPM;                 
volatile int Signal;               
volatile int IBI = 600;             
volatile boolean Pulse = false;      
volatile boolean QS = false;        
static boolean serialVisual = true;


void setup(){
  Serial.begin(9600);
  
//nodig voor accelerometers en thermister, aangesloten op 3.3V
  analogReference(EXTERNAL);
  
//hartslag Setup
  interruptSetup(); 

//digitale output 
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  
   
//datalogger
    Wire.begin();
    RTC.begin();
 
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
//SD kaart
   Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}


//code temperatuur
 double Thermister(int RawADC) { 
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;              
  return Temp;
}

void loop()

{
//data wordt geprint op de sd kaart
File myFile = SD.open("Data.txt", FILE_WRITE); 
if(myFile)

{
// de tijd en datum 
   DateTime now = RTC.now();
    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    Serial.print("\t");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print("\t");
    myFile.print(now.day(), DEC);
    myFile.print('/');
    myFile.print(now.month(), DEC);
    myFile.print('/');
    myFile.print(now.year(), DEC);
    myFile.print("\t");
    myFile.print(now.hour(), DEC);
    myFile.print(':');
    myFile.print(now.minute(), DEC);
    myFile.print(':');
    myFile.print(now.second(), DEC);
    myFile.print("\t");
  
//temperatuur            
  int waarde=readMux(0);     
  double temp=Thermister(waarde);   
  Serial.print("Temp=\t " + String (temp) + " \t c \t");
  myFile.print("Temp=\t " + String (temp) + " \t c \t");
  
//ademhaling
  int ademhaling = analogRead (2);
  Serial.print("Resp:\t" + String (ademhaling) + "\t");
  myFile.print("Resp:\t" + String (ademhaling) + "\t");
  
//vibratie
  int vibratie = analogRead (3);
  Serial.print("Vbr:\t" + String ( vibratie) + "\t");
  myFile.print("Vbr:\t" + String ( vibratie) + "\t");
  
//gsr sensor
  int gsrValue = readMux(4);
  Serial.print("GSR:\t" + String ( gsrValue) + "\t");
  myFile.print("GSR:\t" + String ( gsrValue) + "\t");
  
  
//accelerometer hoofd
  float zeroH_G_x = 508;
  float zeroH_G_y = 504.2;
  float zeroH_G_z = 526;

  float scaleH_x = 102;
  float scaleH_y = 101.2;
  float scaleH_z = 102; 
  
  int xH = readMux(1); 
  Serial.print("aXH:\t" + String (((float)xH - zeroH_G_x)/scaleH_x) + "\tg\t");
  myFile.print("aXH:\t" + String (((float)xH - zeroH_G_x)/scaleH_x) + "\tg\t");
  
  int yH = readMux(2); 
  Serial.print("aYH:\t" + String (((float)yH - zeroH_G_y)/scaleH_y) + "\tg\t");
  myFile.print("aYH:\t" + String (((float)yH - zeroH_G_y)/scaleH_y) + "\tg\t");
  
  int zH = readMux(3); 
  Serial.print("aZH:\t" + String (((float)zH - zeroH_G_z)/scaleH_z) + "\tg\t");
  myFile.print("aZH:\t" + String (((float)zH - zeroH_G_z)/scaleH_z) + "\tg\t"); 
  

//accelerometer been
  float zeroB_G_x = 505;
  float zeroB_G_y = 504;
  float zeroB_G_z = 514.5;

  float scaleB_x = 105;
  float scaleB_y = 104;
  float scaleB_z = 101.5;  
  
  
  int xB = readMux(5);  
  Serial.print("aXB:\t" + String (((float)xB - zeroB_G_x)/scaleB_x) + "\tg\t");
  myFile.print("aXB:\t" + String (((float)xB - zeroB_G_x)/scaleB_x) + "\tg\t");
  
  int yB = readMux(6);  
  Serial.print("aYB:\t" + String (((float)yB - zeroB_G_y)/scaleB_y) + "\tg\t");
  myFile.print("aYB:\t" + String (((float)yB - zeroB_G_y)/scaleB_y) + "\tg\t");
 
  int zB = readMux(7);  
  Serial.print("aZB:\t" + String (((float)zB - zeroB_G_z)/scaleB_z) + "\tg\t");
  myFile.print("aZB:\t" + String (((float)zB- zeroB_G_z)/scaleB_z) + "\tg\t");
  
  
//hartslag
   serialOutput() ;       
    
  if (QS == true){     
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
  }
  Serial.print("Harstlag:\t" + String (BPM) + "\tSPM\t");
  myFile.print("Hartslag:\t" + String (BPM) + "\tSPM\t");   
  
  Serial.println();
  myFile.println();
  delay (500);
  
  myFile.close();}
 }



//multiplexer
int readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};
  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };
 
//loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);   
  }
  
//read the value at the SIG pin
  int val = analogRead(SIG_pin);

//return the value
  return val;
}