I have some code that ChatGPT wrote for me to control a servo with a potentiometer and a push button, this worked perfectly.
I then wanted to replace the push button with a IR break beam, ChatGPT converted it for me ( the main difference was some variable names and type were changed)
But it just doesn’t work, I have some text printing in the serial monitor and it said the beam was breaking when there was nothing in the gap.
So I found some basic code to test the components taken from here - Detecting an IR Beam Break with the Arduino IR Library that lights up pin 13 LED when there is IR received at the receiver and turns off when the beam is broken. Even this didn’t work, the LED lights initially then goes off.
I’ve checked the IR Tx with my camera its ok.
The IR Rx is working because it works with the remote control that came with my kit.
If I disconnect the IR TX and press a button the remote control the pin 13 LED flashes, if the IR TX is connected and I press a button the LED doesn’t flash.
Any help or hints as to what I am doing wrong is much appreciated
Is it as simple as to just buy a break beam kit? The only reason I didn’t is because I could only find them online not locally and I didn’t meet the minimum order value
That check is worth nothing if you use an IR receiver. Such a receiver has a built-in filter that only detects IR pulses at about 38 kHz. Why that? As you found out already, constant (ambient...) light is not detected by the IR receiver, only the modulated light created by IRsend.mark().
I have no idea
Perhaps IRsend.mark() has a built-in timeout?
What happens if you break the beam, then release it again?
Most probably the light from the LED overrides the light of the distant remote control. The remote sends bursts, i.e. a few pulses for "mark" followed by a pause for "space", and so on. The payload is the time of the various marks and spaces.
I've just been searching and reading and it looks like this is the issue, the IR break beam packs use continuous IR so I think thats what I need.
No idea why that modulated code didnt work but that was only a test anyway
Questioners know what their hardware and software looks like but the volunteers here do not; you need to fully explain what’s not working, and how it is supposed to work.
Please read all the posting guidelines before asking your questions; follow these guidelines in your post.
Hardware
As always, show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
Give WEB links to your major components.
Software
In the Arduino IDE, use CtrlT or CMDT to format your code, then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach your copied sketch.
When you follow the posting guidelines, volunteers can be more effective.
I know the answer, it is relative simple but let us see if ChatGPT does. It started this let it finished it. If they solve it the ChatGPT will learn. I have found many people designing with ChatGPT do not know what they are doing and cannot distinguish the good from the bad.