Photoelectric sensor E3JK-R4M1 with ESP 32 Wroom 32D

@jim-p there's no any adjustment point on sensor body, how I'll do that?

@jim-p I want sensor to detect object and send signal to LCD to count it. and when there's no object, sensor should not detect and LCD should not count.
But in my scenario, the red indicator beeps when no object and LCD counts, and as soon as object comes, red indicator disappears and LCD stops counting.
@jim-p what should I do now?

@6v6gt yes, my sensor is exactly same as shown in attached picture

@6v6gt Ok Let me test it first.

You've understood that a led needs a current limiting resistor (say 300R to 1k ) if you are powering it with 5 volts DC .

What, incidentally, is the source of the 5v DC that you have been applying to the sensor? I'm beginning to suspect that a plausible explanation for the symptoms you have described (continuous counting when the relay is in a specific state) is a failure to understand that the GND connection in the diagram in post #4 must (also) be connected to the GND of the ESP32.

EDIT
That is, I'd guess that since the counter code looks OK (although the results may be inverted) and the module relay could not cause the unwanted "counts", at least not at the frequency you have reported, then the cause is probably a floating ESP32 pin. This may not have been visible in the sketch in post #22 because of the 200ms delay. Also, since you appear to have made a voltage divider by chaining a number of resistors in series, a break somewhere in that chain could also lead to floating ESP32 pin.

Are you using the gray or black wire?
Show a diagram of how you have things connected.

@6v6gt I have tested it.
When hand/object comes infront of sensor, LED stays ON, and when there's nothing, sensor and LED both blink with frequency of mili seconds and sometimes 1 second delay, both not properly stay OFF.

@6v6gt I'm powering it from the ESP32's 5V pin.

see post #49

Gray or Black?

Using grey Wire

Run the sketch from post #22.
What happens?

Dear All,
It is counting now with respect to required condition.
The position of sensor was horizontal, which was creating problem, I placed sensor vertically and now it's OK.
Now I want this real time counting on PC through serial communication (WiFi connectivity), what to do for this.

1 Like

I'm not an expert in that area.

Below every post is a "Solution" icon click on the one that you think helped the most not your own , this will mark your post as solved.

Look at the top of the Arduino forum and click on ARDUINO.CC then CLOUD here you can build "Things" to work on WiFi.

Open a new topic and ask there for help.

Do you want the data collected by the sensor to be visible only in the internal network somehow (say through web browsers etc.) or do you want the data to be visible on the entire internet ?

You've talked about real time but, in reality, how up to date must the data be when viewed from external systems ? That is, how much latency can be tolerated.

Can you explain a bit about how the data, which looks something like the count of objects on a production line, is going to be processed and especially why that processing can't be done on the same device that is doing the counting. That is the ESP32.

1 Like

Internal network only (like within my factory/office)

@6v6gt I require immediate, real-time transmission of count data that matches exactly what's displaying on my LCD screen. When a box/carton passes through the sensor and increments the counter, I need that same count reflected instantly in the monitoring system.

Additionally, I need the system to:

  1. Maintain an hourly record of boxes counted
  2. Show the current counting rate as boxes pass through
  3. Store historical data of previous counts for reference

For example, if 100 boxes passed through between 9:00-10:00 AM, I should be able to see this historical count while also monitoring the current count happening at 11:00 AM.

The latency should be minimal (milliseconds) to ensure accurate tracking of fast-moving products on my production line. Any significant delay between the physical count and the data transmission could lead to discrepancies in my production records.

Dear @jim-p Thank you so much for all help you've provided me from the beginning until now. I truly appreciate your support!


I want to attach this single 4 pin push button to reset the counting on LCD. How will I do its 4 pin connection with ESP 32 wroom 32D

Anyone please guide me

Surely you can use digitalRead() in the loop() to detect if a button is being pressed. If the button is being pressed then set the value of the variable count to 0. There is no need for debouncing of the button or any other complexities. You need only two connections to the button but you must choose two diagonally opposite pins.

If you plan to go any further with this project I suggest you learn how to program and use the Arduino and some basic electronics.

Spend some time at these websites
https://docs.arduino.cc/learn/
https://www.allaboutcircuits.com/textbook/

Otherwise it make take another 5 days for you to make the pushbutton work.

jim, push button connection is not difficult thing for me at all,
I want help in serial communication to system, that I mentioned below:
I require immediate, real-time transmission of count data that matches exactly what's displaying on my LCD screen. When a box/carton passes through the sensor and increments the counter, I need that same count reflected instantly in the monitoring system.

Additionally, I need the system to:

  1. Maintain an hourly record of boxes counted
  2. Show the current counting rate as boxes pass through
  3. Store historical data of previous counts for reference

For example, if 100 boxes passed through between 9:00-10:00 AM, I should be able to see this historical count while also monitoring the current count happening at 11:00 AM.

The latency should be minimal (milliseconds) to ensure accurate tracking of fast-moving products on my production line. Any significant delay between the physical count and the data transmission could lead to discrepancies in my production records.