user34538: I am working on a project that is supposed to record the time difference between two photoresistors that are 4in apart. The photoresistors are sensing the passing of water or other liquids on a chute/ramp. 
The liquids range from water to milkshakes so the time difference shouldn't be more than 2 or 3 seconds at most (I would think). I'm okay with the accuracy being off by a a few tenths of a second.
I am using Photo cell (CdS photoresistor) for my project.
I have looked online and haven't seen a similar project. I want to be able to display the time difference on a lcd. 
I have my lcd up and running but I'm not sure how to code the time difference. My photoresistors are connected to A0 and A1 and I am using digital pins 7-12 for the lcd. If anyone has any advice that would be very appreciated!
I'm sure I missed something so ask any clarifying questions

user30005: The most accurate approach is via In out capture on your timer.
Alternatively you can use an interrupt to start and stop the timer.
The worst approach is to poll 
However, phtoresistors are slow and generally inconsistent. This can lead to errors in reading. S phototransistor or diode works better.
Edit: it is crazy to try to read the signal in analog. Instead design the circuitry so that it breaches the digital low or high thresholds so you can use digitalRead instead.
You can simply use millis or micros to time stamp the events and calculate the difference.
If you want more precise timing measurements, Google ticks implementation.
edit 2:
here is what I tried:
if (dtime_running==0) {             //event 1 has not arrived
    if (EVENT_ON(EVENT1_PIN)) {     //event 1 has arrived
        dtime = time_now();         //time stamp the event
        dtime_available = 0;        //data not yet available
        dtime_running = 1;          //time measurement running
    }
} else {                            //event 1 has arrived and now wait for event 2
    if (EVENT_ON(EVENT2_PIN)) {     //and event 2 has arrived
        dtime = time_now() - dtime; //calculate the timing difference
        dtime_available = 1;        //data now available
        dtime_running = 0;          //stop taking measurement
    } 
}

On two pulses that are 500ms apart, here is the measurement:

Notice that in the box on the upper right, dtime has a value of 500, just as we expected.
the risk with this approach is that if the loop has other tasks, jitters to the measurement will show up. but for slow events, or long time measurements, it may not matter that much.

user7508: You are asking about

the time difference between two photoresistors

This, to start with, makes little sense. Photoresistors are analog
devices. Their resistance, and thus the voltage you measure, is a
continuously varying quantity. The first thing you have to do is to turn
them into logic (i.e. either “off” or “on”) devices. The simplest
approach is to compare your analog reading to a threshold:

if the reading is above the threshold, you will say LDR is in the
HIGH state
if it is below the threshold, the LDR is in the LOW state.

There is a problem with this simple approach though: when the reading is
close to the threshold, the ambient noise can make many spurious
transitions between LOW and HIGH. The simplest solution is to have
not one, but two thresholds. This is called “hysteresis” and is
something you definitely should have whenever you are using thresholds
against analog readings. This can be coded as follows:
const int THRESHOLD_LOW  = 400;  // dummy value
const int THRESHOLD_HIGH = 600;  // dummy value

int HystereticRead(uint8_t pin, int previousState)
{
    int reading = analogRead(pin);
    if (previousState == LOW && reading >= THRESHOLD_HIGH) {
        return HIGH;
    } else if (previousState == HIGH && reading < THRESHOLD_LOW) {
        return LOW;
    } else {
        return previousState;
    }
}

Obviously, the thresholds you will use will not be these dummy values:
you will determine them from experiment.
Next thing is to record transitions. You do not want to look for a
particular state of the LDR, but for the moment it moves from one state
(say LOW) to the other. This is done by comparing the new state you
read to the previous one, as in:
static int state0;  // state of the LDR 0
int new_state = HystereticRead(A0, state0);
if (state0 == LOW && new_state == HIGH) {
    // LDR 0 went from LOW to HIGH.
}
state0 = new_state;  // save for next time

Last thing, and really the simplest, is to record times. You just have
to call millis() to get a timestamp, and compute a difference between
timestamps to get a duration in milliseconds. Here is how you could
write it:
void loop()
{
    static int state0, state1;  // states of the LDRs
    static uint32_t time0;      // last time LDR 0 went HIGH

    // Check for LDR 0 going HIGH.
    int new_state = HystereticRead(A0, state0);
    if (state0 == LOW && new_state == HIGH) {
        time0 = millis();
    }
    state0 = new_state;

    // Check for LDR 1 going HIGH.
    new_state = HystereticRead(A1, state1);
    if (state1 == LOW && new_state == HIGH) {
        uint32_t time1 = millis();
        Serial.print(time1 - time0);
        Serial.println(" ms");
    }
    state1 = new_state;
}


34538: <p>I am working on a project that is supposed to record the time difference between two photoresistors that are 4in apart. The photoresistors are sensing the passing of water or other liquids on a chute/ramp. </p>

<p>The liquids range from water to milkshakes so the time difference shouldn't be more than 2 or 3 seconds at most (I would think). I'm okay with the accuracy being off by a a few tenths of a second.</p>

<p>I am using Photo cell (CdS photoresistor) for my project.</p>

<p>I have looked online and haven't seen a similar project. I want to be able to display the time difference on a lcd. </p>

<p>I have my lcd up and running but I'm not sure how to code the time difference. My photoresistors are connected to A0 and A1 and I am using digital pins 7-12 for the lcd. If anyone has any advice that would be very appreciated!</p>

<p>I'm sure I missed something so ask any clarifying questions</p>
 30005: <p>The most accurate approach is via In out capture on your timer.</p>

<p>Alternatively you can use an interrupt to start and stop the timer.</p>

<p>The worst approach is to poll </p>

<p>However, phtoresistors are slow and generally inconsistent. This can lead to errors in reading. S phototransistor or diode works better.</p>

<p>Edit: it is crazy to try to read the signal in analog. Instead design the circuitry so that it breaches the digital low or high thresholds so you can use digitalRead instead.</p>

<p>You can simply use millis or micros to time stamp the events and calculate the difference.</p>

<p>If you want more precise timing measurements, Google ticks implementation.</p>

<p>edit 2:</p>

<p>here is what I tried:</p>

<pre><code>if (dtime_running==0) {             //event 1 has not arrived
    if (EVENT_ON(EVENT1_PIN)) {     //event 1 has arrived
        dtime = time_now();         //time stamp the event
        dtime_available = 0;        //data not yet available
        dtime_running = 1;          //time measurement running
    }
} else {                            //event 1 has arrived and now wait for event 2
    if (EVENT_ON(EVENT2_PIN)) {     //and event 2 has arrived
        dtime = time_now() - dtime; //calculate the timing difference
        dtime_available = 1;        //data now available
        dtime_running = 0;          //stop taking measurement
    } 
}
</code></pre>

<p>On two pulses that are 500ms apart, here is the measurement:
<a href="https://i.stack.imgur.com/r0Qt8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r0Qt8.png" alt="enter image description here"></a></p>

<p>Notice that in the box on the upper right, dtime has a value of 500, just as we expected.</p>

<p>the risk with this approach is that if the loop has other tasks, jitters to the measurement will show up. but for slow events, or long time measurements, it may not matter that much.</p>
 7508: <p>You are asking about</p>

<blockquote>
  <p>the time difference between two photoresistors</p>
</blockquote>

<p>This, to start with, makes little sense. Photoresistors are analog
devices. Their resistance, and thus the voltage you measure, is a
continuously varying quantity. The first thing you have to do is to turn
them into logic (i.e. either “off” or “on”) devices. The simplest
approach is to compare your analog reading to a threshold:</p>

<ul>
<li>if the reading is above the threshold, you will say LDR is in the
<code>HIGH</code> state</li>
<li>if it is below the threshold, the LDR is in the <code>LOW</code> state.</li>
</ul>

<p>There is a problem with this simple approach though: when the reading is
close to the threshold, the ambient noise can make many spurious
transitions between <code>LOW</code> and <code>HIGH</code>. The simplest solution is to have
not one, but <em>two</em> thresholds. This is called “<a href="https://en.wikipedia.org/wiki/Hysteresis" rel="nofollow noreferrer">hysteresis</a>” and is
something you definitely should have whenever you are using thresholds
against analog readings. This can be coded as follows:</p>



<pre class="lang-cpp prettyprint-override"><code>const int THRESHOLD_LOW  = 400;  // dummy value
const int THRESHOLD_HIGH = 600;  // dummy value

int HystereticRead(uint8_t pin, int previousState)
{
    int reading = analogRead(pin);
    if (previousState == LOW &amp;&amp; reading &gt;= THRESHOLD_HIGH) {
        return HIGH;
    } else if (previousState == HIGH &amp;&amp; reading &lt; THRESHOLD_LOW) {
        return LOW;
    } else {
        return previousState;
    }
}
</code></pre>

<p>Obviously, the thresholds you will use will not be these dummy values:
you will determine them from experiment.</p>

<p>Next thing is to record transitions. You do not want to look for a
particular state of the LDR, but for the moment it moves from one state
(say <code>LOW</code>) to the other. This is done by comparing the new state you
read to the previous one, as in:</p>

<pre class="lang-cpp prettyprint-override"><code>static int state0;  // state of the LDR 0
int new_state = HystereticRead(A0, state0);
if (state0 == LOW &amp;&amp; new_state == HIGH) {
    // LDR 0 went from LOW to HIGH.
}
state0 = new_state;  // save for next time
</code></pre>

<p>Last thing, and really the simplest, is to record times. You just have
to call <code>millis()</code> to get a timestamp, and compute a difference between
timestamps to get a duration in milliseconds. Here is how you could
write it:</p>

<pre class="lang-cpp prettyprint-override"><code>void loop()
{
    static int state0, state1;  // states of the LDRs
    static uint32_t time0;      // last time LDR 0 went HIGH

    // Check for LDR 0 going HIGH.
    int new_state = HystereticRead(A0, state0);
    if (state0 == LOW &amp;&amp; new_state == HIGH) {
        time0 = millis();
    }
    state0 = new_state;

    // Check for LDR 1 going HIGH.
    new_state = HystereticRead(A1, state1);
    if (state1 == LOW &amp;&amp; new_state == HIGH) {
        uint32_t time1 = millis();
        Serial.print(time1 - time0);
        Serial.println(" ms");
    }
    state1 = new_state;
}
</code></pre>
