Now im trying to measure the time.
starting when the value is above 5 and stopping when value is below 5.
Then i would like to print in the monitor how long this duration was.
When again light hits the diode and the value goes again above 5 it should start measure again and print again but as long the diode doesnt get hit by light again it shouldnt make a new measurement
so i wrote this code but i couldnt get it to work, is there someone who can help me please ?
int sensorPin = A3;
int sensorValue = 0;
boolean timingFlag;
unsigned long timeOff;
unsigned long timingMillis;
If You use the Autoformat function, Ctrl T, in the IDE, You will see errors like this.
Also, please use code tags when posting code, upper left symbol in this window
Thank you all for the answers, both codes work now.
Your codes is much more elegant @johnwasser.
I put the timing in the other code also in micros for the precision and put the baud up as well.
Is there a way to get the micro seconds printed as millis with comma ?
i would like to get big numbers printed 1000,700 instead of 1000700
and if possible get small numbers printed 0,490 instead of 490
Your wrote dont use analog inputs, why ? @johnwasser
Im trying to measure times down to 490 micros so 0,49 millis.
When i got this precise running, I would like to use two photodiodes and measure the time between first diode getting light and second diode getting light as well as the time between first diode doesnt get light any more and second diode doesnt get light any more plus the times each diode is lit.
benni95:
i would like to get big numbers printed 1000,700 instead of 1000700 and if possible get small numbers printed 0,490 instead of 490
unsigned long elapsedMicroseconds = stopTime - startTime;
// Convert to float, divide by 1000, and print with 3 decimal places
Serial.println(elspasedMicroseconds / 1000.0, 3);
benni95:
Your wrote dont use analog inputs, why ? @johnwasser
I said to not use pinMode() on analog input pins. The pinMode() function should only be used on pins you are using for digitalRead() or digitalWrite().
Analog reading is slow. If you want to time very short intervals, use an analog comparator to do the thresholding and turn your analog signal into a digital signal. Then you can measure down to a fraction of a microsecond using the Input Capture feature of Timer1. For multiple signals, you would need some external switching hardware or an Arduino with more Input Capture pins than the one on an UNO/Nano.
I gathered the diode from a broken camera its a silicon blue cell and the repair manual says it has a response time from 10^-6 sec.
right now i got one leg from the diode connected to a3 and the other to ground, i put a germanium diode as a resistor between a3 and ground this way the reading keeps zero when there is no light on the diode.
which parts do i need for analog comparator and how do i hook it up with the diode?
So its not possible to have one diode on d pin 1 and the other on d pin2 and start timing when pin 1 change and stop when pin 2 change ?
goal is to measure the time a curtain of a camera needs to travel 35mm so i want to put two diodes 35mm apart
You have been really helpful already !