Noob Photogate help

I am a complete NOOB. I am trying to make an affordable infrared Photogate timer to use when I teach high school physics classes. I have followed some instructions online and built a functioning system. However, I am also trying to learn new skills and would very much like to do this using XOD. I am using a TSOP 32838 IR receiver and an appropriate IR LED. I have simple patch that triggers a standard LED when something passes between the IR LED and the IR Sensor. The problem is that the whole thing doesn’t seem sensitive/responsive enough to be useful. When I built the previous version it was very responsive and accurate. Right now what I am trying to achieve is that when the ir beam is broken the LED goes off and when the beam is reestablished the the LED come back on. Eventually I will work in a timer and some math and an LCD but I want to learn one step at a time. Any help would be much appreciated. I am sure this is something super simple. image

Not sure what you are using for TSOP 32838 or how it works, but I assume TSOP-SIG is true if light is detects; otherwise false (or the inverse of that). In your code above, the flip-flop will only toggle when TSOP-SIG changes to true. This is probably NOT what you want. I think what you want is to delete the flip-flop node & just tie TSOP-SIG directly to RedLED-LUM. If the Red LED is on when you want it off & off when you want it on, then you can add a ‘not’ node between TSOP & RedLED (replacing the flip-flop node in your current code).

Another “fix” that would probably work is to put a pulse-on-change node between TSOP & flip-flop, but this is a bad idea. It is too easy for the flip-flop to get out-of-sync with the TSOP output if you are just toggling the flip-flop (i.e. does TSOP see light when program starts and flip-flop is set to false [there is no guarantee that IR will be turned on before flip-flop is initialized]? If SIG change is too fast, there is a chance that flip-flop will only see one pulse. There are probably other cases where flip-flop could get out-of-sync with state you want). There are times when using flip-flop-TGL is appropriate, but care should be taken when using it since you cannot force it to the correct state without using SET or RST. In this case, I think you just want output of TSOP, so there is no reason to use the flip-flop.

Thank you for your fast reply. I have been working through the XOD tutorials but not everything is “sticking with me” the first time around. I am basically trying to recreate the tutorial found linked below with XOD: https://jrowing.com/arduino-light-gates . I tried your suggestion and I am not getting the results I expected. I was hoping to get the led to go off when the beam is broken and be on when the beam is intact. All I get are some random flutters in the led when I pass my finger through the beam

It would help to know how your TSOP node is coded. Even if there are no coding errors, It is possible that passing your finger through the beam allows enough ambient light from the room to hit the sensor and trigger it.

I am using the following node: xod/gpio/digital-read is there a better one for me to try?

That would be the correct node if you were using a straight photo sensor. The TSOP 32838 is actually an IR receiver that expects to receive coded messages over a carrier signal. I don’t think it is going to work the way you want to use it.

There are IR Sensor Modules that you can get, but they usually mount the transmitter next to the receiver and expect to bounce the light off the object you want to detect. I don’t know if you can make that work for you. Most of these sensors have a POT that allows you to set threshold, then the sensor returns a digital value like your code is expecting. You might be able to find a sensor that is separate from the transmitter to use in your current setup. I guess you could use the joined transmitter/receiver and just not use the transmitter…

You can just use a photodiode, but it would be a little more complicated. You would have to set it up as a voltage divider and use an analog pin. The input pin would be connected to both the photodiode and a resistor (1M Ohm would probably work). The photodiode and resistor then connect to V+ and GND. If you connect photodiode to V+, the voltage will go up when light is detected. If you connect photodiode to GND, the voltage will go down when light is detected. Resistor needs to connect to the opposite of what the photodiode connects to. You will need to experiment to see what value the analog-read returns to determine what threshold you want to set. If you connect photodiode to V+, you might end up with something like this:

image
You will need to experiment with your setup to see if 0.75 is an appropriate value to check for. Using the watch node would allow you to see what values are returned under different conditions to help you determine what value you should compare to in the ‘greater’ node (you need to run in debug mode to see values in watch node). If you connect the resistor to GND and the voltage never goes down, you might need a smaller resistor. If voltage never goes up, you might need a larger resistor.

I had a feeling that something like you describe would end up being the case based on the original project I am trying to replicate. I bought my original hardware for the scenario I linked to earlier. In that case the IRremote library was used and the frequency required for the sensor was defined in the sketch. I could not see how to replicate what was in the original sketch with XOD but I didn’t know if that was a limitation of xod, my hardware or most likely my knowledge. In any case I anticipated not being able to use the hardware I have so I did order some photodiodes a few days ago and will give that a try when they show up later today or tomorrow. Again, let me thank you for your help. I really like XOD and am enjoying the personal learning journey I am on and all the help has been awesome.

I haven’t tried the photodiode yet but I was curious about the TSOP 32838 receiver I have and how I might be able to make a patch work with it. Since it is meant to work with an ir source at 38 Khz I was thinking I could try cycling the LED at that frequency. This is what my patch looks like:
image

It doesn’t work of course. Am I barking up the wrong tree with this approach or am I just doing something silly with the programming? I don’t need this sensor to work if I can get the photodiode working but I would like to make this work for the learning value if I can. Thanks

The TSOP sensor is expecting to get signals with a base frequency of 38Khz. I think the output from the sensor is the signals (codes) it received. It is not an on/off sensor. It’s a “here’s the code I received” sensor.

Hi, I succesfuly did the same thing some wheeks ago because I tok want to put xod and arduinos in the secondary physics classrooms.
The best way to do it, hardware point of view, is to use an IR led and a “flame sensor” (look for ky-028), with the following advantages: it’s cheap, you can set up sensitivity to avoid daylight influence and it can give you a digital or analog reading.

Have a look here but please ignore the russian english and the lack of common sense while doing this (did’t have any kind of script or even a plan :)) )

Light gate video

A flame sensor is basically a photo diode tuned to IR, so it is less likely to be affected by indoor lighting but direct sunlight would still be a problem. If you get a flame sensor module, it might have additional hardware to convert the analog sensor output to digital for you.

I absolutely know the TSOP32838 sensor I started with will work. I built a photogate using that sensor and code that I copied and pasted from the internet into the Arduino IDE. It worked perfectly but I wanted to add some other functionality to the project like an lcd and menu to toggle between velocity, acceleration, and time. I don’t have the coding skills to make it happen in the IDE but I think I could do it with xod. I am pretty good at copying other peoples work :slight_smile: but not so good at making things from scratch (just not enough knowledge…yet). Anyway, as a proof of concept, I know what I had worked I just don’t know if it can be achieved with xod. If it can’t, that’s fine, I can always use what I had usig the IDE. My intuition is that I need to find a way to make the IR LED flash at the right frequency or duty cycle but I could be way off. Anyway, I have also tried the photodiode approach that gweimer suggested and it works well enough but I need to play around with the resistance in the voltage divider to get better results. I truly appreciate everyone weighing in on this. I may not achieve my secondary goal of making a photogate but I am achieving my primary goal of learning.

I just realized in my last post I was erroneously referring to my sensor as a TSOP 32838 instead of the actual TSOP 38238.

This particular flame sensor have both digital and analog outputs.
It has a comparator on board so you can easily set up sensitivity i relation to surrounding environment factors like direct sunlight.

Had a quick look and that module will output low when it sees a 38Khz signal from the IR led and high when it doesnt. You’ll want to omit the flip flop and drive the led at 38Khz.
Haven’t tested it but looks like this library might be suitable for generating the output for the IR led
hussainfawzi/fast-pwm

If you have access to a signal generator (I’m guessing the school probably has one) you could initially run the IR led off that to eliminate one variable while you’re testing your code. It’s much easier to get one part working at a time.

Hope this helps.

Thanks revenador. I will try that. Although I don’t have easy access to a signal generator. I think what I will do is drive the LED off of another Arduino Nano with the code I was using in the Arduino IDE since I know it works correctly. In essence, I will be using the original project as a signal generator for the LED. Then I will see what is happening with the sensor plugged into another nano connected through xod. I can also switch the roles and drive the LED from xod and have the sensor running the working program from the Arduino IDE. I think I should be able to make some conclusions by taking this approach.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.