Datalogging using Arduino

I need to sample 50 Hz stepped down utility voltage. can I use Arduino data logger for this purpose?

"It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second." The Arduino reads 0-5volts.

That means the sampling rate for an Arduino is 10 kHz. So the 50 Hz signal can be sampled using the Arduino. isn't it?

But, will Arduino support for negative voltages?

Yes the Arduino can easily handle 50hz

But, will Arduino support for negative voltages?

No. But you can offset an AC signal to 2.5v.


I just used the following code. But it didn’t do the job. The sampling is not in satisfactory level.

#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup() {
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only

Serial.print(“Initializing SD card…”);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
Serial.println(“card initialized.”);

void loop() {
// make a string for assembling the data to log:
String dataString = “”;
int sensor = analogRead(0);
//sensor = map(sensor,0,1024,0,255);
dataString += String(sensor);

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile =“datalog.txt”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
// print to the serial port too:
// if the file isn’t open, pop up an error:
else {
Serial.println(“error opening datalog.txt”);

The sampling is not in satisfactory level.

What does that mean?

Please get into the habit of using code tags when posting code.


Errr . . .?

I couldn't get the exact data from data logger. The sampled power line data should be sinusoidal. But it is not the case when i get the data from datalogger. I suspect the sampling rate is very low.

So, increase the sampling rate. What is your sampling rate now?


the baud rate set here is 4GHz.

but still its not working

No surprise, I guess

the baud rate set here is 4GHz.

Yes, we'll maybe come back to that later, but what is your sampling rate?

The sampling rate is set by the code


isn't it?

Start here

so how to change the sampling rate?

By making the loop shorter?
What is the sampling rate? You still haven’t answered that question.

I need around 10kHz sampling rate.

OK, I'm going to ask one more time.

What is your sampling rate?

It's 10 kHz.

I need around 10kHz sampling rate.

ARDPrash: It's 10 kHz.

Great. Problem solved.

Problem not solved