Arduino with multiple sensors

Hi everybody, I am very new to Arduino world, and I am currently working on a school project that requires your help.

My project is about logging some data, using some sensors and GPS. Everything will be attached on a bicycle and logged on a SD card.
Following are the sensors and parts I have purchased-

  • 3-axis accelerometer (ADXL 335, 3.3 VDC)
  • Ultrasonic Distance Measurement (Maxsonar-EZ1, 5VDC)
  • Two IR sensors for distance measurement (Sharp, 5VDC)
  • Hall effect sensors for cadence of pedals
  • EM-406A GPS
  • Arduino UNO R3
  • GPS logger shield from Adafruit
  • Protoshield

Requirement of the project is to log data with high frequency from all the sensors, so this is how it should look.

A line for GPS (@ t = 0 sec)
20 lines of all the other sensors (so 20 * 6 analog inputs = 120 entries, 6 entries in one line, 20 lines in total)
A line of GPS (@ t = 2 sec)
... so on

So far I have only got the GPS part working, and the program I have (edited a program I found online, I am not the creator) can successfully log a sentence every second. The thing I don;t know is how to interface the rest of the sensors so that the program is efficient, fast and logs everything. I need some pointers from you guyz, as I have no idea at all, how to even begin this for the rest of the sensors.

My code for GPS is here -

/* EXAMPLE

$PSRF103,<msg>,<mode>,<rate>,<cksumEnable>*CKSUM<CR><LF>

<msg> 00=GGA,01=GLL,02=GSA,03=GSV,04=RMC,05=VTG
<mode> 00=SetRate,01=Query
<rate> Output every <rate>seconds, off=00,max=255
<cksumEnable> 00=disable Checksum,01=Enable checksum for specified message
Note: checksum is required

Example 1: Query the GGA message with checksum enabled
$PSRF103,00,01,00,01*25

Example 2: Enable VTG message for a 1Hz constant output with checksum enabled
$PSRF103,05,00,01,01*20

Example 3: Disable VTG message
$PSRF103,05,00,00,01*21

*/

#define SERIAL_SET   "$PSRF100,01,4800,08,01,00*0E\r\n"

#define GGA_ON   "$PSRF103,00,00,01,01*25\r\n"// GGA-Global Positioning System Fixed Data, message 103,00
#define GGA_OFF  "$PSRF103,00,00,00,01*24\r\n"

#define GLL_ON   "$PSRF103,01,00,01,01*26\r\n"// GLL-Geographic Position-Latitude/Longitude, message 103,01
#define GLL_OFF  "$PSRF103,01,00,00,01*27\r\n"

#define GSA_ON   "$PSRF103,02,00,01,01*27\r\n"// GSA-GNSS DOP and Active Satellites, message 103,02
#define GSA_OFF  "$PSRF103,02,00,00,01*26\r\n"

#define GSV_ON   "$PSRF103,03,00,01,01*26\r\n"// GSV-GNSS Satellites in View, message 103,03
#define GSV_OFF  "$PSRF103,03,00,00,01*27\r\n"

#define RMC_ON   "$PSRF103,04,00,01,01*21\r\n"// RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define RMC_OFF  "$PSRF103,04,00,00,01*20\r\n"

#define VTG_ON   "$PSRF103,05,00,01,01*20\r\n"// VTG-Course Over Ground and Ground Speed, message 103,05
#define VTG_OFF  "$PSRF103,05,00,00,01*21\r\n"

#define DDM_ON   "$PSRF105,01*3E\r\n"// Switch Development Data Messages On/Off, message 105
#define DDM_OFF  "$PSRF105,00*3F\r\n"

#define WAAS_ON    "$PSRF151,01*3F\r\n"// useful in US, but slower fix
#define WAAS_OFF   "$PSRF151,00*3E\r\n"

#include <SD.h>
#include <SoftwareSerial.h>

// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
 SoftwareSerial gpsSerial =  SoftwareSerial(2, 3);

// Set the pins used 
#define powerPin 4     //provides input power for GPS from digital pin 4
#define chipSelect 10  

#define BUFFSIZE 90
char buffer[BUFFSIZE]; //makes a string named 'buffer' with the length equal to buffsize
uint8_t bufferidx = 0;  // unsigned integer bufferidx - this is a counter used for the 'buffer' string
uint8_t i;    // counter i
File logfile; //file to store data, logfile is NOT the name of the file


void setup() {
  Serial.begin(9600);
  pinMode(powerPin, OUTPUT); //set powerpin is output, it will supply power to GPS, can be changed to permanent 5V connection with other sensors
  digitalWrite(powerPin, LOW); //do NOT supply power to GPS yet
  pinMode(10, OUTPUT); // make sure that the default chip select pin is set to output, even if you don't use it, this is important for SD loggers, CS pin for adafruit loggers is 10
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
  return;
  }
  
  //find name of new logfile
  strcpy(buffer, "GPSLOG00.TXT");
  for (i = 0; i < 100; i++) {
    buffer[6] = '0' + i/10;
    buffer[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(buffer)) {
      break;
    }
  }
  logfile = SD.open(buffer, FILE_WRITE);
  
  gpsSerial.begin(4800); // connect to the GPS at the desired rate, 4800 selected for this GPS, do not change
  
  gpsSerial.print(SERIAL_SET);
  delay(250);
  
  gpsSerial.print(RMC_ON);// Generate RMC data  RMC-Recommended Minimum Specific GNSS Data, message 103,04
  delay(250);
  gpsSerial.print(DDM_OFF);// Don't generate Development Data Messages On/Off, message 105
  delay(250);
  gpsSerial.print(GGA_OFF);// Don't generate GGA data  GGA-Global Positioning System Fixed Data, message 103,00
  delay(250);
  gpsSerial.print(GLL_OFF);// Don't generate GLL data  GLL-Geographic Position-Latitude/Longitude, message 103,01
  delay(250);
  gpsSerial.print(GSA_OFF);// Don't generate GSA data  GSA-GNSS DOP and Active Satellites, message 103,02
  delay(250);
  gpsSerial.print(GSV_OFF);// Don't generate GSV data  GSV-GNSS Satellites in View, message 103,03
  delay(250);
  gpsSerial.print(VTG_OFF);// Don't generate VTG data  VTG-Course Over Ground and Ground Speed, message 103,05
  delay(250);
  gpsSerial.print(WAAS_OFF);// Don't use WAAS - is useful for US only, and enabling gives slower fix
 }

void loop() {
  char c; //define character c
  
  // read one 'line'
  if (gpsSerial.available()) { //if GPS serial data is available
    c = gpsSerial.read();           //store the data in char c

    if (bufferidx == 0) {    //check if bufferidx is 0, while the first letter in char c is not '

I hope you guys can help me. Eagerly waiting for your reply.

Thanks and Cheers, store a new line in char c.
                            // All the GPS strings start with $, so it is required to check that we have an NMEA sentence
      while (c != '


I hope you guys can help me. Eagerly waiting for your reply.

Thanks and Cheers)
        c = gpsSerial.read(); // wait till we get a $
    }
    buffer[bufferidx] = c; //stores value of char c in buffer at location bufferidx

    if (c == '\n') {
      buffer[bufferidx+1] = 0; // terminate it - null character terminates a string

      if (buffer[bufferidx-4] != '*') {
        // no checksum?
        bufferidx = 0;
        return;
      }
      
      // find out if we got a fix
      char *p = buffer;    //declare pointer p of char type, and assign address of the first letter of the buffer string to it
      p = strchr(p, ',')+1;
      p = strchr(p, ',')+1;       // skip to 3rd item - strchr locates first occurence of ',' in the string

      if (p[0] == 'V') {  // 'V' means data is void (no fix), 'A' means fix is acheived and GPS is active
        bufferidx = 0;
        return;
      }
      
      // start logging good data!
      Serial.print(buffer);
     
      bufferidx++; //Need to write bufferidx + 1 bytes to getCR/LF

      logfile.write((uint8_t *) buffer, bufferidx);
      logfile.flush();
      
      bufferidx = 0;
      return;
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) { //if bufferidx becomes longer than buffsize 
       //Serial.print('!');
       bufferidx = 0;
    }
  }
}

I hope you guys can help me. Eagerly waiting for your reply.

Thanks and Cheers

Seems like you are off to a decent start.
I would get one sensor at a time working first.
Once you have figured out how each sensor works, then try combing it into one program, one thing at a time.

Another problem I have is my accelerometer operates on 3.3 VDC while the other sensors are running on 5VDC. To use the AREF, I don't wanna change it in the loop part of the program before and after reading the accelerometer data because I read that after changing AREF a few readings are not accurate and I cannot wait for after each time changing the AREF. Can I use the same (DEFAULT) AREF for the entire program and than convert the values of accelerometer afterwards? Is this kind of data reliable? If yes than how can I convert it?