Ads1015 problem

by valtsu23 on Tue Mar 12, 2013 1:21 pm

This is my firts arduino project.

I'm trying to build datalogger what uses ads1015 a/d converter. Datalogger chip is this:

Now device saves adc result to the microSD card, but the result is always 4095. Even when A1 voltage is 0V the adc result is 4095.

Here is the code:
Code: Select all
  ArduLog V1.0
  Requires Arduino V1.0 and above

  Written by Hobbytronics Ltd (
  This example code is in the public domain.
  Simple Data Logging program for the Hobbytronics ArduLog board. Please feel free to amend and adapt.
  Appends all received serial data to the log file
  Uses pin A1 to start/stop logging
  Configuration is determined by config.txt file which should have the following entries
  BAUD xxx
  FILE filename_prefix
  Green LED lights up to indicate logging has started, extinguishes when logging stopped
  Orange LED indicates data activity


#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <SD.h>

Adafruit_ADS1015 ads1015;
const int CardDetect = A2;     // the card detect pin
const int statusLED = 5;       // Green Status LED on pin 5
const int file_flush = 2;      // Force data write to file after x seconds

File myFile;

// Struct to hold config info from config.txt file
struct {
  unsigned int baud;    // baud rate
  char fileprefix[20];  // filename prefix 
  char filename[20];    // filename to log data
} config;

unsigned long currentTime;
unsigned long cloopTime;

void setup()
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");

  int i;
  pinMode(CardDetect, INPUT);  // Card Detect
  pinMode(statusLED, OUTPUT);  // Status LED
  // Default config settings - override with config file "config.txt" if required
  config.baud = 0;
  strcpy(config.fileprefix, "LOG."); 
  strcpy(config.filename, "LOG.001");
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);
    // CardDetect LOW - a card is inserted
    if (!SD.begin(10)) {
    digitalWrite(statusLED, HIGH);  // Logging started
    Serial.println("No card detected");     
  currentTime = millis();
  cloopTime = currentTime;

void loop()
int16_t adc1;
adc1 = ads1015.readADC_SingleEnded(1);

     delay (100);
   currentTime = millis();
   if(currentTime >= (cloopTime + (file_flush*1000)))
       // Flush data to file after (file_flush) seconds
       cloopTime = currentTime;  // Updates cloopTime

void openlogfile()
    // Search for next log filename
    myFile =, FILE_WRITE);

    // if the file opened okay, output the name
    if (myFile)
      Serial.print("Log file: ");
      // if the file didn't open, print an error:
      Serial.print("Error opening log file: ");

Posts: 2
Joined: Tue Mar 12, 2013 1:09 pm

Re: Ads1015 problem

by adafruit_support_bill on Tue Mar 12, 2013 3:19 pm

Can you post a photo showing your connections? Have you tried the example code from the Adafruit library?

According to the HobbyTronics page, the logger is also an I2C device. Make sure there is no address conflict.
User avatar
Posts: 25380
Joined: Sat Feb 07, 2009 9:11 am

Re: Ads1015 problem

by adafruit_support_mike on Tue Mar 12, 2013 5:29 pm

Just at a quick glance, you have some unnecessary braces in your code:

Code: Select all
void setup()

and there's another one like it at the beginning of the loop() function. It looks like you got the braces around the Adafruit code when you copied it over to your script. I don't think that should cause any problems, but it wouldn't hurt to get rid of the extra braces.

I'll second the suggestion to try running the singleended.pde sketch that came in the examples folder for the ADS1015 library. The results from a piece of code known to work on other devices might give us some hints that will help locate the problem.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm

Re: Ads1015 problem

by valtsu23 on Wed Mar 20, 2013 12:53 pm

Problem is solved. Power source was causing the trouble, I'm not sure why.
Posts: 2
Joined: Tue Mar 12, 2013 1:09 pm