Pages: [1]   Go Down
Author Topic: Flip-Flop from analog input?  (Read 638 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I just got my arduino a week ago, and I'm having trouble with this.

Basically I want to create a laser tripwire (using a laser diode, and a Photoresistor),
and if the laser breaks, I want the state of a boolean to change, but when the laser comes back on, I want nothing to happen

Can anyone give me some example code for this flip flop effect?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33448
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You want to trigger stuff just on the falling (breaking) edge of the signal from the photo resistor?

If so do an analogue reading and compare it to some threshold to get a digital value. Remember the state of the switch when you last looked at it and compare it to what it is this time.
Only do your stuff if it is broken now and wasn't last time.
As the last thing in the loop transfer the current value to the remembered value.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To save anyone wasting their time answering the same question in the sensors section, I've deleted it.

Do NOT cross post.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To save anyone wasting their time answering the same question in the sensors section, I've deleted it.

Do NOT cross post.


Im really sorry, i won't do it again.


You want to trigger stuff just on the falling (breaking) edge of the signal from the photo resistor?

If so do an analogue reading and compare it to some threshold to get a digital value. Remember the state of the switch when you last looked at it and compare it to what it is this time.
Only do your stuff if it is broken now and wasn't last time.
As the last thing in the loop transfer the current value to the remembered value.

Can you give some example code on how to do this?
Logged

Offline Offline
Edison Member
*
Karma: 5
Posts: 1730
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could part of it with hardware, and save yourself on the analog reads,
instead of a photoresistor(kinda slow) use an led with a comparator
have a potentiometer to adjust the trip level and the output will be a digital high or low, that will be much faster
in your code just have it once it goes low do something and set a flag to not do anything else
like
Code:
If(digitalRead(3)==1 && tripped ==0){
//do something
tripped=1;
}
//or replace digitalread with this for your setup

If(analogRead(A1) > 500 && tripped ==0){//etc and have the 500 number be watever is above abient but below the light

Now the need for speed would only be necessary if watever is tripping it is small and/or moving to fast for the photocell to respond, a quick google says anywhere between 2ms and 50ms response time
Logged

Pages: [1]   Go Up
Jump to: