Please let me know if you experience any problems with this
code. Be sure to check back for more Arduino code.
Schematic:
Code:
/*
Oliver Holden
Created 28/10/2014
Components:
* Arduino UNO
* LDR
* 10K resistor
- Gets an analogue value of Light from an LDR
Prints the data to the Serial Monitor
Data is sent to an Excel spreadsheet through data
acquisition software, PLX-DAQ, Download http://www.parallax.com/downloads/plx-daq
Schematic for this project is on
http://electrical-teen.blogspot.co.uk/
*/
int LDRPin= A2; // LDR Reading Pin
int LDRReading = analogRead(LDRPin); // Reading analogue value from LDR
int x = 0; // For PLX-DAQ
int row = 0; // For PLX-DAQ
void setup()
{
Serial.begin(9600); // Opening serial connection at 9600bps
Serial.println("Light"); //Printing Serial Monitor header
Serial.println("LABEL, Time, LDR"); // Setting headers of colums in PLX-DAQ spreadsheet
Serial.println("\n-----------------");
}
void loop() {
Serial.println(LDRReading); // Printing data to Serial Monitor
row++; // For PLX-DAQ
x++; // For PLX-DAQ
delay(1000); // Printing data once a second
}
Why "Serial.println("\n-----------------");"??
ReplyDeleteIt's there to separate the headings from the data so it prints like this:
ReplyDeleteLDR
-----------
Value
I think that's why.
This code is not working for me. I think that in Serial.println (in loop) is not all correct.
ReplyDeleteThis code works better for me:
int ROW = 0;
int LABEL = 1;
int val = 0;
void setup(){
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,val,ROW");
}
void loop(){
val = analogRead(A0);
ROW++;
Serial.print("DATA,TIME,");
Serial.print(val);
Serial.print(",");
Serial.println(ROW);
if (ROW > 100) // just to limitate data
{
ROW = 0;
Serial.println("ROW,SET,2");
}
delay(200);
}
Thanks for letting me know while since I have used it, Im not to sure why it wouldn't work though as I tested all of my code before I posted them have you got it working with that your code?
ReplyDelete