So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By MeMagic
#87150
schufti wrote:no it is not defective, it is so quick!
If the loop is not taking a lot of time, the esp can do about 3-5 loops during the same millisecond.

Thanks for posting.
What would you suggest in this case? How shall I proceed to smooth the behavior of the ESP reacting on the Opto Interrupter's signals?
User avatar
By schufti
#87152 it might be due to the fact that every "edge" when moved in/out the opto gives intermittent states, like bouncing on contacts.
You may "debounce" the opto signal somewhat like

if detected opto active, delay 5ms, if still opto active do "active" action else ignore ....
User avatar
By MeMagic
#87153
schufti wrote:it might be due to the fact that every "edge" when moved in/out the opto gives intermittent states, like bouncing on contacts.
You may "debounce" the opto signal somewhat like

if detected opto active, delay 5ms, if still opto active do "active" action else ignore ....

Right! I've already done this, but by inserting 300-400ms delays. Your proposal is good, but sometime it's not sufficient. The opto can change 3 times it's signal during one ms, like in the output below. So, although the signal is the same as first, overall signal counter is increased. I'd better just delay 400ms.
Code: Select allOpto interrupter not covered. Time: 17653
Opto interrupter covered. Time: 20302
Opto interrupter not covered. Time: 20302
Opto interrupter covered. Time: 20302
Opto interrupter not covered. Time: 22919


May be it would be better to enhance smoothness by using some capacitors in the circuit?

But the BIG issue still stays on! The output is more or less OK if I run the ESP and the opto only, without motor. When I connect the motor also, the opto signal will switch multiple times without being flagged at all! This is literally what happens - the motor is being rotating forward and backward as it should following the code, but it won't take into account is the opto covered or not, and timings are random. It looks like the electronic part is doing this. Like some electronic noise in the circuit.