Hey guys.. I originally posted this over on the Arduino forums, but since it is in C, I figured I should spread around my chances of finding an answer.
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.
Here is a sketch of what I am talking about. Hopefully you can make out my handwriting.
I can see from the serial monitor that the sensors are detecting movement at the same time, but only one light will change at a time.
Here is the code.
I just don't understand why this part is not working.
Thanks in advance for any help you guys can provide.
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.
Here is a sketch of what I am talking about. Hopefully you can make out my handwriting.
I can see from the serial monitor that the sensors are detecting movement at the same time, but only one light will change at a time.
Here is the code.
Rich (BB code):
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)))
{
changeValue(3);
}
else if((analogRead(s01) > 250) && (analogRead(s03)))
{
changeValue(5);
}
else if((analogRead(s02) > 250) && (analogRead(s03)))
{
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);
}
Rich (BB code):
else if((analogRead(s01) > 250) && (analogRead(s02)))
{
changeValue(3);
}
else if((analogRead(s01) > 250) && (analogRead(s03)))
{
changeValue(5);
}
else if((analogRead(s02) > 250) && (analogRead(s03)))
{
changeValue(6);
}
Attachments
-
153.7 KB Views: 32