Hello everyone!
I’m new to the forums and hope to place my question in the right subforum. I’ve worked with Arduino before but this is my first project with serial communication. It’s also just a test run, the device shall be standalone with a SD card one day…
My code and board are really simple as of now (only few comments, i deleted all my german comments to avoid confusion):
int sensorPin0 = A0;
int sensorPin1 = A1; //
int sensorPin2 = A2; //
int sensorPin3 = A3; //
int west = 0;
int nord = 0;
int sued = 0;
int ost = 0;
void setup() {
Serial.begin(9600); //initiate serial communication with baud rate 9600
Serial.println("West \t Nord \t Sued \t Ost");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
west = analogRead(sensorPin0);
nord = analogRead(sensorPin1);
sued = analogRead(sensorPin2);
ost = analogRead(sensorPin3);
Serial.print(west);
Serial.print(" \t ");
Serial.print(nord);
Serial.print(" \t ");
Serial.print(sued);
Serial.print(" \t ");
Serial.println(ost);
}
It’s just four light resistors in different directions. I want to read their sensor data and send them to the PC via USB. I use an Arduino Uno / Pretzel Board and the current Arduino version from this site.
Thing is: It worked yesterday for 6 hours with a 10 second delay(i stopped it manually) and then it worked from 11pm yesterday till 10:30am this morning with a 15 second delay, i didn’t stop it here though.
I used CoolTerm for logging the data with a timestamp. After that i could only get it to work for about 20 minutes tops with varying delays during today. I’m down to only using the serial monitor because i only need one 24 hour cycle of data for now but even that doesn’t work. My last try was a 60 second delay (which would be sufficient) but it only showed 18 lines of data before stopping. The only thing that changed might be my PC use while running the arduino, but its data is so insignificant (75kb in 6 hours), i just cant believe it could be an issue.
Thanks for reading this!
Any ideas?
Edit:
I now use a millis-Timer like this:
int sensorPin0 = A0; // LDR richtung West, Input zwischen 0 und 1023, gelbes Kabel
int sensorPin1 = A1; // LDR richtung Nord, orange
int sensorPin2 = A2; // LDR richtung Sued, rot
int sensorPin3 = A3; // LDR richtung Ost, braun
int west = 0; //Messwertstart auf Null setzen
int nord = 0;
int sued = 0;
int ost = 0;
long Timer = 0;
long interval=60000;
void setup() {
Serial.begin(9600); //initiate serial communication with baud rate 9600
Serial.println("Time \t West \t Nord \t Sued \t Ost"); //Variablen mit Sensorwerten an den Rechner übertragen
}
void loop() { // put your main code here, to run repeatedly:
unsigned long current = millis();
if (current - Timer >interval){
Timer = current - 1;
west = analogRead(sensorPin0); // sensorwerte in Variablen hinterlegen
nord = analogRead(sensorPin1);
sued = analogRead(sensorPin2);
ost = analogRead(sensorPin3);
Serial.print(Timer);
Serial.print(" \t ");
Serial.print(west);
Serial.print(" \t ");
Serial.print(nord);
Serial.print(" \t ");
Serial.print(sued);
Serial.print(" \t ");
Serial.println(ost);
}
}
I tried a watchdog but the 8 second response interval is too small for my 60 seconds of nothing - or would the watchdog be ok with millis?
I’ll let it run for a while now, i don’t know for how long it will last though, so i’d appreciate ideas on my mistake before either way!
Thanks~