Hacking the FC03 IR Sensor

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Hacking the FC03 IR Sensor

#1 Post by moelski » 06 Dec 2016, 20:13

Hi @all,

today I setup a small project. I need a counter for my gas meter in the basement and I used a IR Sensor to detect this little silver plate on the last number of my meter.
Works like a charme and ESPEasy was setup quickly with a pulse counter.

But then things got strange ... The gas meter stops at the last number 6. That´s where the silver plate is placed for counting.
So the IR sensor stays high in the Output. And then ESPEasy starts counting every second (that´s the debouncing time I set). :shock:

I have no explanation for this because the interrupt routine is setup for using FALLING edges.
So has anyone an idea whay it counts as long as the pin is high? To be honest ... I´m a little bit confused ... :roll:

My setup is R141 and the IR sensor is on GPIO 13 which is D7. The sensor I am using is this one:
https://www.walmart.com/ip/Indicator-Li ... /148488118

Any ideas ?

Note:
The Problem here is not related to the Pulsecounter nor ESPEasy. It´s more an electronic problem.
The most of the answer is electronic / sensor related ...
Last edited by moelski on 09 Dec 2016, 06:06, edited 2 times in total.
regards
Dominik

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#2 Post by Shardan » 07 Dec 2016, 13:51

Hello moelski,

to narrow down that behaviour i would try a simple idea first:

disconnect the output from the sensor and set the GPIO pin to high hardwired.
Just connect the pin to 3,3V with a resistor 3,3KOhm....10 KOhm.
Leave the sensor power connected, just disconnect the data wire.

This shows if the errorneous pulse comes from the sensor itself or if it is generated somewhere in the ESP-Chip.

If it comes from the sensor i suspice the comparator chip shows a reaction to voltage problems.
Try to adjust it to a lower sensivity if possible.
If the pulses result from "ripples" on the voltage, even an addiional little capacitor (220nF... 1µf)
at the voltage divider may help (see pic). A 100µF or bigger on the sensor between 3,3V and GND may help too.
Fc03-Capacitor.jpg
Fc03-Capacitor.jpg (23.51 KiB) Viewed 4813 times
If it is definitely the sensor and nothing works, give the analog output a try. Some people reported that this
works better as the digital output sometimes.

If anything fails you will need an oscilloscope to see what's going on.

Regards
Shardan
Regards
Shardan

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#3 Post by Shardan » 07 Dec 2016, 15:16

Me again ;)

just another idea i got this moment:
The comparator works in a linear mode. It does not switch exactly between "High" and "Low", there is a linear range between.

Add the 220 nF capacitor as a clean reference voltage is always a good idea.
Then add a resistor of 47KOhm between A0 and D0 pins.
This might make the circuit very unsensitive. If sensivity is too low, try 100K, 220K and 470K.
Or use a 47K connected in series with a 500K trim, more comfortable.

This adds a hysteresis to the comparator, it makes it "switch" between high and low at defined thresholds
and eliminates the linear behaviour.
With a 47K it should have thresholds at 1,4V (output goes low) and 1,6V (output goes high).
But i can't calculate these values exactly as the resistance of the optosensor isn't defined.

Regards
Shardan
Regards
Shardan

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#4 Post by moelski » 07 Dec 2016, 19:21

Hi !

That´s exact the problem. I have the circuit on my desk and if I use a piece of metal I can see that there is a small range where the output is not HIGH and not LOW.
The Output LED is dimmed ... And that is exactly the range where I have the problems with multiple counts ...

Will try your suggestions.
regards
Dominik

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#5 Post by moelski » 07 Dec 2016, 19:37

And you got the wrong picture. I am using this here:
Attachments
FC-33a.jpg
FC-33a.jpg (127.89 KiB) Viewed 4784 times
regards
Dominik

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#6 Post by moelski » 07 Dec 2016, 19:46

Just placed 100k between D0 and A0 and it seems promising 8-)
No more linear behaviour ... I will test it at my gas meter. :)
regards
Dominik

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#7 Post by Shardan » 07 Dec 2016, 20:46

hello,

well, it's basically the same circuit, just your one has a trim resistor - which is partly useless as it can be driven fully against Vcc and GND.
The comparator will never do anything from these positions down to about 15..20% of the turn.

Anyways.. I have to say these breakoutboards have not the best circuit design. i would have given that additional capacitor
and two more resistors making it into a precisely working tool. Not much of cost at all.

Regards
Shardan
Regards
Shardan

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#8 Post by moelski » 08 Dec 2016, 09:09

Hi Shardan,

Today I had the same issue again :cry:
i would have given that additional capacitor and two more resistors making it into a precisely working tool. Not much of cost at all.
So you mean replacing the trim by two resistors and place a cap at the resistor which has the ground connection, correct?

What will be usage values for the resistors? 10k/10k like in the first schematic you posted?

I must say that I´m not the best in analog electronics ... :roll:

Maybe I could use a z-diode instead of the resistore which is connected to ground?
Just refresh my comparator skills here : http://www.electronics-tutorials.ws/opa ... rator.html 8-)
regards
Dominik

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#9 Post by Shardan » 08 Dec 2016, 15:47

Hello,

there is a slight difference between the schematic I found on the web and the one you showed:
The inputs of the comparator are swapped. As you said the signal is "high" if the sensor gets a
white spot it's your schematic that is correct in this case. "High" says the "Out" LED is off!

(I really should get such a breakout board for testing myself......)

If that is correct (LED off if white Spot detected) the 100KOhm resistor should be placed between DO and the wiper of the trim resistor.
The 220nF capacitor can't be placed then as it would slow down the comparator instead of speeding up.

A Zener diode won't work well here even basically the idea is right. The lowest ZD I could find by
quick researching my sellers has 2,7 Volts so the difference to Vcc is extremely low while the given voltage
is too high, it should be around 1,5...1,7 volts for 3,3V Vcc i think.

a more cleaned up design might look like this. Be warned, values are made by rule of thumb
and untested!
Schmitt-Trigger.jpg
Schmitt-Trigger.jpg (72.39 KiB) Viewed 4740 times
I'm wondering if I should do a redesign as i might need such a sensor sooner or later.
IR-reflection sensors are ordered already but it will take time until they arrive from China.
Getting some PCB prototypes after testing on a breadboard will take some weeks too.
So including xmas and new year holidays this won't happen before February or later.

I'm tempted to integrate an ESP directly on the PCB and take the sensor off-board for easier placement.
What do you think?
Regards
Shardan

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#10 Post by moelski » 08 Dec 2016, 20:44

Hi !

Did not work well for me in MultiSim ...
I did some tests and this could work fine ... See pictures.

But I have to figure out what voltage output comes from the IR-reflection sensor.
Will measure that and put it into the simulation ...
Attachments
Schematic.PNG
Schematic.PNG (34.14 KiB) Viewed 4723 times
Oszi.PNG
Oszi.PNG (33.79 KiB) Viewed 4723 times
regards
Dominik

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#11 Post by moelski » 08 Dec 2016, 20:57

Also works in very noisy environment ...
Attachments
Oszi2.PNG
Oszi2.PNG (27.31 KiB) Viewed 3550 times
regards
Dominik

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Pulse Counter Problem - Multiple counts if Pin stays high

#12 Post by Shardan » 08 Dec 2016, 21:18

Can't say much as i don't have the hardware atm,
no LM393 neither a IR sensor.

I suggest to check the high and low voltage from the sensor, best done in place at your counter with real values.
Then change the voltage divider R3/R4 to a resulting voltage in the mid between the high and low levels.

Maybe R2 is too low then, from the diagram the thresholds seem to be near VCC / GND.
The bigger you make R2, the lower gets the difference between the thresholds.
I should mention that a smaller difference makes the circuit more sensitive to noise,
so some optimizing will be necessary.
And even here i would put a capacitor in parallel to R3 to keep the reference voltage clean.


Seems to work nicely in noisy environment as shown from the diagrams.
Maybe give it a try.

Regards
Shardan
Regards
Shardan

User avatar
moelski
Normal user
Posts: 126
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Hacking the FC03 IR Sensor

#13 Post by moelski » 11 Dec 2016, 20:12

Hi !

Well I made a lot of simulations at Saturday and gave my best to get this sensor up and running. But at the end I failed :shock:
The Schmitt Trigger did not work as expected and it took to much time to get usable results. So I decided to give another approach a try - Arduino Nano.
It is much easier to read the sensor value and the schmitt Trigger functionality was easy to implement in software ... And it´s configurable in Software 8-)

It took me only 2 hours to get the stuff up and running. And using some python on a raspberry the data was easily transmitted via MQTT to my FHEM installation.

If anyone is interested in my code and / or my setup just leave me a note here.

Sorry that this is not a success story for ESPEasy :roll: But at the end I have a controlling unit in my basement (Raspberry Pi 2) which also reads the Watts from my power meter and in the next days my water consumption. ;)
Attachments
The results in FHEM ...
The results in FHEM ...
Power and Gas capture.PNG (62.41 KiB) Viewed 3526 times
regards
Dominik

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Hacking the FC03 IR Sensor

#14 Post by Shardan » 11 Dec 2016, 20:28

Hello,

congrats.
I supposed that this might happen.
As mentioned above the circuit is made as cheap as possible and has some flaws.
Re-making the whole circuit might be easier then cleaning all the flaws out.

When the parts arrive here and I have some spare time I'll do hardware testing
on a breadboard to get an IR sensor working. As I'm interested in such a sensor it
might end up in a complete sensor with an ESP-01 included on the PCB.

But that will take it's time definitely.

Regards
Shardan
Regards
Shardan

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 23 guests