Differential Light Sensing: The 4-Channel Nav System
This project is a deep dive into Analog Sensor Integration, specifically focusing on a 4-channel light-sensing array to drive a differential steering robot. By placing photoresistors (LDRs) in a cross formation (Front-Left, Front-Right, Back-Left, Back-Right), the Arduino can determine not just if light is present, but the exact direction of the source, allowing the robot to "seek" or "flee" from light autonomously.
Overcoming the Multi-Channel Analog Hurdle
The primary challenge in this build is a common issue for Arduino beginners: Input Crosstalk and Variable Scope.
- The RCtime Method: Instead of simple
analogRead(), this project implements the RCtime technique. This involves charging a capacitor (1uF) through a pin, then measuring how long it takes to discharge through the photoresistor. This method provides much higher resolution in low-light conditions than a standard voltage divider. - Debugging Re-definitions: As noted in the project history, copying code blocks for multiple sensors often leads to the
redefinition of 'long int RCtime(int)'error. To fix this, the function must be declared once at the top, and called with different pin integers as arguments (e.g.,RCtime(tlPin)andRCtime(trPin)). - Electrical Isolation: When reading multiple analog channels rapidly, the Arduino's internal ADC Multiplexer can carry some residual voltage from the previous reading. The project explains how to add "dummy reads" or small delays between channel swaps to ensure the Left sensor doesn't influence the Right sensor's data.
Bridging the Gap to Locomotion
Once the 4-channel data is stabilized, the next step is Motor Mapping:
- Direct Proportionality: The Arduino compares the Left and Right readings. If
Left > Right, the code increases the PWM speed of the Right motor to turn the robot toward the light. - L293D Integration: To drive the physical motors, the logic is output to a motor driver shield. This allows the low-power sensor data to control the high-power bi-directional path of the chassis.
- Sensor Shielding: For maximum directional accuracy, the LDRs are often mounted inside small "blind" tubes (like heat shrink or straws). This narrows their field of view, making the 4-channel array much more sensitive to the light's exact vectors.
This project serves as an excellent Semester Project because it forces the student to handle both software architecture (functions/variables) and electrical troubleshooting simultaneously.
I have used the RCtime page from arduino.cc to get a single channel photoresistor to work and have a decent analog output. The cap is 1002nF and the resistor is 1kohm.
I got the code for A0 to work. The problem is when I added the second channel. I copied the code and built the second channel exactly the same.
My problem is adding the second channel. When I get the code without errors, the second photo resistor changes the value for both sides.
After I get this figured out and working electrically I will need to change the code to operate motors.
I know I am asking a lot over a forum but is there a site or video that I can look at and figure this out?
(Current error codes)
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Uno"
C:\\*: In function 'long int RCtime(int)':
C:\\*:17:8: warning: unused variable 'result' [-Wunused-variable]
long result = 0;
^
C:\\*:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
C:\\*: At global scope:
Semester_project_code:25:1: error: expected unqualified-id before '{' token
{
^
C:\\*: In function 'long int RCtime(int)':
Semester_project_code:30:6: error: redefinition of 'long int RCtime(int)'
long RCtime(int(trPin))
^
C:\\*:15:6: note: 'long int RCtime(int)' previously defined here
long RCtime(int tlPin)
^
Semester_project_code:39:1: error: expected primary-expression before '}' token
}
^
C:\\*:32:8: warning: unused variable 'result' [-Wunused-variable]
long result = 0;
^
C:\\*:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
exit status 1
expected unqualified-id before '{' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.