Blog 4 is takes all the lessons learned from the 1st 3 blogs, assembles the prototype of the photo-eye detection system, providing engineering test and calibration validation while operating from the Arduino.
Please reference for background blogs:
The WRONGCO Hamper Helper – blog 3 – photo "electric eye" detection calibration, and down a COB LED rabbit hole
The WRONGCO Hamper Helper–blog 2-Intro to Optical sensors from a Dummy
The WRONGCO Hamper Helper - experiment 1 dirty clothes pile height detection - not so good
The Arduino test program:
- Reads each phototransistor to sample the voltage drop at ambient light intensity
- Individually turns on each COB LED “transmitter assembly”
- Reads the corresponding phototransistor “receiver” value when COB LED is on
- The cycling is slow enough to allow for manual confirmation of the phototransistor voltages with a DVM
// ---------------------------------------------------------------------------
//
// This is a test program for the Hamper Helper "Electric Eye"
// which detects and alerts if clothes are piled above the top of the hamper.
// This program fires the COB light source & reads the voltage drop across the
// phototransistor mounted directly across from it.
// Low light conditions, the phototransistor is high impedance, reading a voltage drop of approximately 5V.
// If the phototransistor sees the COB LED light, the phototransistor conducts more, with a lower voltage drop.
// The measured voltage drop of the phototransistor hit with the COB LED beam is about 4V.
// The code will set a "beam seen" flag if the beam is detected. If the beam isnt seen when the COB LED is lit,
// it assumed clothes are blocking the light beam.
// This simple code tests the beam COB LED transmitter and phototransistor detector.
// ---------------------------------------------------------------------------
int LongitudePhotoEyeValue;
int LatitudePhotoEyeValue;
int LongitudeSeeBeam;
int LatitudeSeeBeam;
float LatitudePhotoEyeVolts;
float LongitudePhotoEyeVolts;
void setup() {
pinMode(A2, INPUT); // Latitude phototransistor voltage drop 5V = no light (1023), 4V sees beam (900)
pinMode(A3, INPUT); // Longitude phototransistor voltage drop 5V = no light, (1023), 4V sees beam (900)
pinMode(2, OUTPUT); // Driver for Latitude PhotoElectric Eye COBLED
pinMode(3, OUTPUT); //Driver for Longitude PhotoElectric Eye COBLED
//pinMode(5, OUTPUT); // turn on Hamper Full BUZZER
//pinMode(6, OUTPUT); // turn on Hamper Full Flashing LED assembly
//pinMode(7, OUTPUT); // Power atomizer
//pinMode(8, OUTPUT); // start atomizer
delay(1000);//a little power up time for Buck PSs to settle
Serial.begin(9600);
//Arduino's PWM frequency at about 500Hz, analogWrite(255) requests a 100% duty cycle (always on),
//and analogWrite(127) is a 50% duty cycle (on half the time) for example.
}
void loop()
{
delay(5000); // how often to cycle test to give time to manually verify readings.
// check Latitude direction for eye Beam
digitalWrite(2, HIGH); // Latitude turn on COB LED
delay(500);
LatitudePhotoEyeValue=analogRead(A2);
LatitudePhotoEyeVolts=(LatitudePhotoEyeValue)*5.0/1023.0;
delay(50);
if (LatitudePhotoEyeValue<920)
{ LatitudeSeeBeam = HIGH;}
else { LatitudeSeeBeam = LOW;}
digitalWrite(2, LOW); // Latitude turn off COB LED
Serial.print( "LatiitudePhotoEyeValueLIT=");
Serial.println( LatitudePhotoEyeValue);
Serial.print( "LatiitudePhotoEyeVoltsWhenLIT=");
Serial.println( LatitudePhotoEyeVolts, DEC);
Serial.println(" ");
delay(1000); // give time for DVM to display reading
digitalWrite(2, LOW); // Latitude turn off COB LED
// check Longitude direction for eye Beam
//digitalWrite(2, HIGH); // Latitude turn on COB LED
delay(500);
LatitudePhotoEyeValue=analogRead(A2);
delay(50);
//if (LatitudePhotoEyeValue<920)
// { LatitudeSeeBeam = HIGH;}
// else { LatitudeSeeBeam = LOW;}
//digitalWrite(2, LOW); // Latitude turn off COB LED
Serial.print( "LatiitudePhotoEyeValue_AMB=");
Serial.println( LatitudePhotoEyeValue);
Serial.println(" ");
// check Longitude direction for eye Beam
digitalWrite(3, HIGH); // Longitude turn on COB LED
delay(500);
LongitudePhotoEyeValue=analogRead(A3);
LongitudePhotoEyeVolts=(LongitudePhotoEyeValue)*5.0/1023.0;
delay(50);
if (LongitudePhotoEyeValue<920)
{ LongitudeSeeBeam = HIGH;}
else { LongitudeSeeBeam = LOW;}
Serial.print( "LongitudePhotoEyeValue=");
Serial.println( LongitudePhotoEyeValue);
Serial.print( "LongitudePhotoEyeVolts=");
Serial.println( LongitudePhotoEyeVolts, DEC);
Serial.println(" ");
delay(1000); // give time for DVM to display reading
digitalWrite(3, LOW); // Longitude turn off COB LED
//test ambient value
LongitudePhotoEyeValue=analogRead(A3);
delay(50);
Serial.print( "LongitudePhotoEyeValue_AMBIENT=");
Serial.println( LongitudePhotoEyeValue);
Serial.println(" ");
}
Top Comments