Hello everybody,
I would like to create a stopwatch using my Arduino Uno.
The program is very simple, the chronometer will have to start only when a photoresistor will detect a light source. The program will have to record how long this light will remain on and at the end report the result via the serial monitor (only at the end). Also, to see if the code works correctly, I would like a LED to remain ON when the stopwatch is actually recording the passage of time.
This is the code I tried to write by my own.
int UVOUT = A0; //Output from the sensor
int x = 400;
int pinLed = 2;
unsigned long time;
void setup() {
Serial.begin(9600);
pinMode(UVOUT, INPUT);
pinMode(pinLed, OUTPUT);
Serial.println("UV Stopwatch");
}
void loop() {
int uvLevel = analogRead(UVOUT);
if (uvLevel > x){
digitalWrite(pinLed, HIGH);
Serial.println("UV Detection - Started");
time = millis();
}
Serial.print("Total Time: ");
Serial.println(time);
}
If anyone could give me some advice or help me with the drafting of the code it would be much appreciated !
Thx in advance,
Giacomo.