Hi guys, this is going to be my first post and hopefully I can explain this where everyone can understand my noobiness :).
So, I am building a pretty big circuit that has 40 leds and 20 IR sensors. I have been prototyping using just 3 sensors with 6 leds. Right now, I can get the circuit to act how it is supposed to when an object passes in front of one of the sensors. When an object is detected, the Arduino talks to a shift register and sets the pin high this is associated the sensor. Each sensor is associated with 2 leds, one controlled by a standard inverter connected to a BJT that switches one of the leds. When nothing is in front of the sensor, the inverter causes the white led to illuminate, and when something is present, the shift register causes the inverter to go high (causing the BJT to switch) and the register switches another BJT to illuminate the other led. Before I confuse you much more, here is a drawing of what I am doing.
My problem is I can get this circuit to work if I trip only one sensor at a time. But, it should be able to handle multiple sensors at the same time.
Here is my code. Please don't laugh.......
int sV01 = 0; //Sensor 1 Analog Value
int sV02 = 0; //Sensor 2 Analog Value
int sV03 = 0; //Sensor 3 Analog Value
int bitToSet;
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
//Pin for Sensor01
const int s01 = 1;
//Pin for Sensor02
const int s02 = 2;
//Pin for Sensor03
const int s03 = 3;
//Pin for Master Resest (Active Low)
const int mRPin = 10;
int sValue;
void setup()
{
Serial.begin(9600); //Begin serial communcation );
//Set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(mRPin, OUTPUT);
Serial.begin(9600);
Serial.println("reset");
}
void loop()
{
digitalWrite(mRPin, HIGH);
for(int i = 0; i < 3; i++)
{
Serial.print("__");
Serial.print(analogRead(i)); //Write the value of the photoresistor to the serial monitor.
Serial.print("__");
}
Serial.println("\r");
if(analogRead(s01) > 250)
{
changeValue(1);
}
else if(analogRead(s02) > 250)
{
changeValue(2);
}
else if(analogRead(s03) > 250)
{
changeValue(4);
}
else if((analogRead(s01) > 250) && (analogRead(s02) > 250))
{
changeValue(3);
}
else if((analogRead(s01) > 250) && (analogRead(s03) > 250))
{
changeValue(5);
}
else if((analogRead(s02) > 250) && (analogRead(s03) > 250))
{
changeValue(6);
}
else
{
changeValue(0);
}
//digitalWrite(mRPin, LOW);
}
// This method sends bits to the shift register:
void changeValue(int nTd) {
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, nTd);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
Any help is much appreciated, and if anyone has suggestions for not only the code, but the circuit itself, I would love to hear them.