I am new to this Forum and to Arduino. I don't know too much about programming, so I need some help on this for a product design project.
So I have 2LDRS, 2lasers, 2LEDs. The 2 lasers are ON and constantly pointed towards the 2 LDRS.
I wave my hand between the lasers and LDRs to interupt the light.
If I wave from left to right, first activating LDR1, then LDR2, LED1 should turn on.
If I wave from right to left, first activating LDR2, then LDR1, LED2 should turn on.
Basically, if used as a sensor and placed by a doorway, it should detect if a person is entering (by flashing LED1) or if a person is leaving (by flashing LED2)
The important thing to notice is WHEN each LDR is turned off. If LDR1 is turned off before LDR2, then the motion was in one direction. Otherwise, the motion was the other way. You need to record WHEN (using millis()) each LDR was turned off. When both have been turned off, the relative times will tell you the direction.
Now, the tricky part is what happens if two people pass through the doorway together, one going in and one going out? What happens if someone starts to enter (breaks both beams), but then backs out?
Basically, if used as a sensor and placed by a doorway, it should detect if a person is entering (by flashing LED1) or if a person is leaving (by flashing LED2)
This will not actually be implemented in doorways, so I will not have a problem with multiple objects interferring
Well the doorway analogy was easier to understand. I actually want to sense the direction of waving hands to control an object. Where might I find information on programming the code for this?
I am new to this Forum and to Arduino. I don't know too much about programming, so I need some help on this for a product design project.
The best place for you to start is the tutorial section - http://www.arduino.cc/en/Tutorial/HomePage - to get familiar with the Arduino and how it is programmed. It will cost you one eveneing to a week to go through the examples but then you wil have 90% of the knowledge needed.
wrt the project I recommend to take paper and pencil and write down how you would do it (imagine your eyes as LDR 1 and LDR2). there are 4 state changes
LDR1 ON => OFF
LDR1 OFF => ON
LDR2 ON => OFF
LDR2 OFF => ON
you need to detect these 4 changes and at that moment you need to check the other LDR and then you should have all information to determine the direction.
To help your project forward here you have ~75% of the code, the interesting part is left open, but the comments are in place. The part you need can be found in the tutorial section (with a little mod)
#define LDR1PIN A0
#define LDR2PIN A1
#define LEFTLED 4
#define RIGHLED 5
int direction = 0 ; // 0 = undiceded, -1 = left +1 = right
int LDR1state = 0; // 0 = dark, 1 = light
int LDR2state = 0; // idem
int LDR1NewState = 0;
int LDR2NewState = 0;
void setup()
{
Serial.begin(115200);
Serial.println("Direction Detector");
// SET LED MODES
// READ INITIAL LDR STATE
}
void loop()
{
// READ NEW LDR1 STATE
// READ NEW LPR2 STATE
// COMPARE NEW STATES WITH PREVIOUS STATES AND DETERMINE DIRECTION
// LIGHT THE RIGHT LED
digitalWrite(LEFTLED, direction == -1); // -1 was defined as left
digitalWrite(RIGHTLED, direction == 1); // 1 was defined as right
}