Check if input signal is high for a given time interval - Page 1
Forum section: electronics / beginners

author: fenicento
author_rank: Newbie
timestamp: January 11, 2015, 03:17:57 pm
content: Hi all,I'm an Arduino user and not to skilled in electronics (not at all actually). I'm trying to build a lamp that switches on and off if adigital proximity sensordetects and object for more than one second. I'm actually using anAdafruit Trinket, but I'd really like to use integrated circuits thant don't need to be programmed, since the application is really easy.In order to toggle the on/off I guess I can use a T-type flip flop, but I really don't know how to check if the signal of the sensor stays high for one second. In short, I need an integrated chip or a circuit that reproduces this behaviour:QuoteAny ideas?

author: German_EE
author_rank: Super Contributor
timestamp: January 11, 2015, 07:01:44 pm
content: Take a 74HC132 chip, it's four two input NAND gates but they have Schmitt trigger inputs so slow inputs can be used. One input is directly from your sensor, the second input has a series resistor and a capacitor down to 0V. So, the sensor output goes high, input one goes high and input two slowly ramps up to 5V over 1 second, after which the output of the NAND goes low.

author: fenicento
author_rank: Newbie
timestamp: January 12, 2015, 06:08:44 pm
content: That sounds just fine, thanks.I just read that the sensor signal is normally HIGH, and becomes LOW when something is in the way. So I guess I have to turn thing around and use a NOR gate. In this case I'd have the first input coming directly from the output of the sensor, and the second one connected in series with R and C. Is it right? Do you know where I can find a formula to correctly estimate the right R and C in order to obtain a desired time T?

author: katzohki
author_rank: Frequent Contributor
timestamp: January 12, 2015, 06:21:35 pm
content: Or you could get a simple clock going and count how many clock pulses something is high / low.

author: fenicento
author_rank: Newbie
timestamp: January 13, 2015, 12:18:03 am
content: as I said, I'm a newbie and making circuits without a MCU is really difficult for me. Can you count the clock cycles in which a signal is high or low just using integrated circuits?

author: Rick Law
author_rank: Super Contributor
timestamp: January 13, 2015, 12:29:49 am
content: Quote from: fenicento on January 13, 2015, 12:18:03 amTry the millisec() function. Save the milliseconds it first turn on, and now you can subtract that off to get how long it has been on:...unsigned long lastTurnOn=0;unsigned long turnOnTime=0;int itIsOn=0;...if (decidedIfOn()==yes) {if (itIsOn==0) {lastTurnOn=millisec();itIsOn=1;}//turnOnTime = millisec()-lastTurnOn; // how many milli seconds ago did it turn on} else {itIsOn=0L;}Give that a try... & good luck...

author: dannyf
author_rank: Super Contributor
timestamp: January 13, 2015, 02:20:46 am
content: QuoteTough to reconcile the two,Anyway, a 555 would do that, as well as some logic gates. But a mcu is probably the most versatile of them all.But without knowing which path you want to go down, it is hard to help you.

author: dannyf
author_rank: Super Contributor
timestamp: January 13, 2015, 02:24:21 am
content: Code:turnOnTime = millisec()-lastTurnOn; // how many milli seconds ago did it turn onThe logic can be made simpler: you just need to reset the counter if nothing is detected.Something like this:Code:if nothing_detected start_time=milliesec(); //reset start time is nothing is detectedif (milliesec() - start_time > desired_duration) do_something();

author: katzohki
author_rank: Frequent Contributor
timestamp: January 13, 2015, 03:52:52 pm
content: Quote from: fenicento on January 13, 2015, 12:18:03 amYes. Let's say you want to check if your signal is high (just use an inverter if you want to check low). Take your signal and AND it with a clock signal (you can use a crystal or clock IC). Feed that into a counter. AND the outputs of the counter together and when they are all = 1 the output will be 1. You will have to experiment with maybe multiple counters to get it to the timing you want.https://www.fairchildsemi.com/datasheets/74/74VHC393.pdfEdit: On the subject of doing this with an MCU, you could do this with an absolute minimum if you learn to program directly without all the extras that the adafruit board gives you. I reckon that a 6 pin MCU (e.g. ATTiny or PIC10F), decoupling cap, couple resistors, transistor, a relay and your sensor could accomplish the entire project.