Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <SD.h>
- #define GND A0
- #define VCC A5
- const int chipSelect = 10;
- void setup() {
- pinMode(GND, OUTPUT);
- pinMode(VCC, OUTPUT);
- digitalWrite(GND, LOW);
- digitalWrite(VCC, HIGH);
- Serial.begin(9600);
- 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");
- while (1);
- }
- Serial.println("card initialized.");
- }
- void loop() {
- // make a string for assembling the data to log:
- String dataString = "";
- // read three sensors and append to the string:
- for (int analogPin = 1; analogPin < 5; analogPin++) {
- int sensor = analogRead(analogPin);
- dataString += String(sensor);
- if (analogPin < 4) {
- dataString += ",";
- }
- }
- // 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 = SD.open("datalog2.csv", FILE_WRITE);
- // if the file is available, write to it:
- if (dataFile) {
- dataFile.println(dataString);
- dataFile.close();
- // print serial port:
- Serial.println(dataString);
- }else {
- Serial.println("error opening datalog.txt");
- }
- }
Add Comment
Please, Sign In to add comment