Codul pentru a inregistra pe SDcard parametri de functionare VAWT (curent, tensiune , putere, energie) folosind aceeasi configuratie Arduido+Shield Ethernet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
#include <SD.h> #include <Wire.h> const int chipSelect = 4; File dataFile; float sample1=0; float sample2=0; float voltage=0.0; float actualval; float amps=0.0; float totamps=0.0; float avgamps=0.0; float amphr=0.0; float watt=0.0; float energy=0.0; float val11=0; float val2=0; float i1 = 0; float i = 0; void setup() { Serial.begin(9600); while (!Serial) { ; } Serial.print("Initializing SD card..."); pinMode(SS, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: while (1) ; } Serial.println("card initialized."); dataFile = SD.open("energy.txt", FILE_WRITE); if (! dataFile) { Serial.println("error opening energy.txt"); while (1) ; } } void loop() { long milisec = millis(); long time=milisec/1000; for(int i=0;i<150;i++) { sample1+=analogRead(A1); sample2+=analogRead(A2); delay(2); } sample1=sample1/150; sample2=sample2/150; float temp; val11=sample1; temp=val11/4.092; val2=(temp/10); i1 = sample2; i = ((.0049 * i1) - 2.5)/.066; voltage=val2; amps =i; totamps=totamps+amps; avgamps=totamps/time; amphr=(avgamps*time); watt =voltage*amps; energy=(watt*time)/3600; //////////////////////////////////////////////////////// String dataString = ""; int parameter[4]={ voltage,amps,watt,energy }; for (int i = 0; i < 4; i++) { int sensor = parameter[i]; dataString += String(sensor); if (i < 4) { dataString += ","; } } dataFile.println(dataString); Serial.println(dataString); dataFile.flush(); delay(500); } |