Grounding Advice Needed for Arduino and Sensor Circuit

Hello!

I'm working on a project involving an Arduino and a photoelectric sensor, and I'm seeking advice on the best grounding practices to avoid ground loops and interference. I apologize in advance for not having a schematic to share, but I'll do my best to describe the setup clearly.

Circuit Components:

  1. Arduino (powered via USB)
  2. Photoelectric sensor (powered by a separate 12V power supply)
  3. Voltage divider near the Arduino (10k and 5.1k resistors)

Circuit Layout:

  • The photoelectric sensor has positive, negative, and signal cables.
  • The signal cable carries 12V and runs through a 6-meter cable to the voltage divider near the Arduino.
  • The voltage divider connects to an Arduino pin and the Arduino's ground.

Grounding Question:
I'm unsure about the best way to connect the grounds in this setup. I'm considering two options:

Option 1:

  • Run the Arduino's ground through a 6-meter cable.
  • At the sensor end, connect:
    • Arduino ground
    • Negative from the 12V power supply
    • Negative from the sensor

Option 2:

  • Run a separate 6-meter cable for the sensor and power supply grounds respectively.
  • Connect both to the Arduino's ground at the Arduino end.

My main question is: Is there a significant difference between these two approaches in terms of performance or noise reduction? Option 2 requires more cable management, but I'm wondering if it offers any benefits that would make it worthwhile.

I'd greatly appreciate any insights or recommendations from those with experience in similar setups. Thank you in advance for your help!

A bit confused. You say the sensor has positive, negative, and signal but then go on to say the signal is in fact 12V.
It sounds like all you need is to run the arduino G and SIGNAL (5V) to the sensor Signal and negative/ground/common.

Well, the sensor has a positive that should go to the positive on my 12V power supply, and a negative that should go to the negative. It also has a signal wire that reads gives 12V when the sensor is blocked.

To read this 12V signal on the Arduino I run it up a 6 meter cable and through a voltage divider to get 5V on the pin. But I need common ground.

So the question is if there is any difference between running just a ground cable from the Arduino ground down to the point where the negative from the sensor and negative from the power supply meet vs. running two cables (one from the power supply and one from the sensor) to meet at a single point up at the Arduino 6 meters away.

That is, having one ground connection up at the Arduino for all elements vs. running the cable from the Arduino and having the connection down there.

I have read about grounding loops and problems where you have multiple grounding points etc. I am actually redesigning a circuit that has been acting up and splitting a higher 24v circuit I need to open and close away from the lower voltage Arduino circuit that controls it. I was using a MOSFET but will be changing to a relay to avoid common ground issues.

But it just got me thinking that having different grounding points so far apart with different power sources could be a problem? That the grounding points could be at slightly different potentials?

I don't know too much about this but I am trying to learn :blush:

Yes, but it's unlikely to be a very relevant difference for your purpose.

Depending on the kind of communication protocol(s) and/or signal(s) that have to travel along these long lines, you may run into trouble with that kind of length. E.g. running I2C over 6m wires is possible, but tends to be very (very!) prone to (big) problems.

Apology accepted, but nonetheless: make a schematic. It's a much more effective way of communicating what you're doing than writing a novel, and in the end it saves everybody a lot of time.

Post a link to the sensor's datasheet or tell us it's brand name and exact part number. Where did you buy the sensor?
Which Arduino are you using?

Thanks everyone!

The sensor is this one https://www.alibaba.com/product-detail/GTRIC-photoelectric-sensor-M18-cylindrical-LS18_1601167457846.html

I have tried my best to make schematics here, but I have to admit it's not something I have done before. I tried 4 free programs to make one before giving up and just using Adobe XD. So I have just copied symbols from the internet and used lines and text.

Avoiding crossing wires was really hard for me because of all the components, so I made a gap where they cross but are not connected. Maybe I should give some sort of backstory here as to why I am trying to change my circuit in the first place.

Long story short: My garage door used to close automatically when I drove away, but it stopped working after I replaced a sensor. I'm using an Arduino setup with a MOSFET to trigger the garage door opener. It triggers when current starts flowing between the positive and the negative terminal marked "START". There is a 24V potential here. I have added two switches to show how I have connected a physical switch and a Meross garage door opener. Both work as they should.

The original circuit worked despite possibly being incorrectly designed.

I'm still learning about circuits and may have some misunderstandings. My main goal now is to design a circuit that works in theory before implementing it. The Arduino logic and code are working fine - it's the electrical aspect that's stumping me.

So here's the schematic for the circuit that worked perfectly:

Some notes on this is that I have been using ChatGPT and Claude.ai to learn, in addition to doing research myself and testing stuff. The problem with these chatbots is that they are so confident even though they are wrong, and they lack the reasoning skills to understand a lot of this. I need to catch that they are wrong to be able to get the correct answer, and oftentimes I don't.

This is the sole reason for the 100k ohm resistor between source and Arduino ground. ChatGPT said it should be there. Later on I have learned that there should be as little resistance as possible here, and that I absolutely need a common ground between the source, the Arduino and the negative from the 24V garage door opener.

Nevertheless, the circuit worked absolutely fine until one of the ultrasonic sensors started acting up. I have one for detecting the presence of each car, and one on each side of the door to detect blockage. One of the sensors for the door was detecting blockage all the time, so I swapped both out for a photoelectric sensor with a retroreflector.

While doing that I also found that the MOSFET had about 250 ohm resistance between gate and source, so that was bust. I therefore replaced that too.

After hooking up the new sensor the wiring looked like this:

The only problem was that it didn't work. The control logic worked fine, and PIN 7 got triggered when it was supposed to, but the door just either would do nothing or it would start and immediately stop.

Now here's the weird part. After triggering the door like this with the MOSFET, the physical switch and the Meross opener would not be able to open the door. Nothing would happen. The same was true for pressing "TEST" on the garage door motor itself. I needed to power cycle the motor for the physical button to work again. It would work until triggering the MOSFET, then it would stop working.

I did some measurements and found that before triggering the MOSFET I have about 22 - 24V potential between the source and drain, and also between the positive and negative on the terminals on the garage door motor and on the switch.

After triggering the MOSFET this voltage would go haywire and read 3, 12, 22, 18, 15, 23 etc. just switching back and forth. This would stop after power cycling.

This led me down the rabbit hole of ground loops and stuff like that. I thought maybe that I had an earth ground on the garage door motor connected to the negative terminal internally, and that my grounding scheme for the Arduino and connected sensors perhaps was at a slightly different potential.

That led to the question in my original post, but it's really getting this whole system to work that is my goal. With the first smaller goal being designing a circuit that should work in theory. I am thinking of swapping the MOSFET for a relay module with an optocoupler to isolate the 24V from the 5V of the Arduino.

I have to add: I did try to add another cable between Arduino ground and directly to source/the negative wire from the garage door terminal, but that made no difference.

I also don't get any continuity between the negative terminal and the garage door frame or the earth ground on the outlet, so I guess it's some kind of internal reference there?

I appreciate any feedback on how to improve this post or make the schematics clearer. As a novice in this field, I've found it challenging to locate forums or experts able to guide me through these issues. Learning through hands-on experience is rewarding but often complex. Your insights and questions not only help me but could also benefit others facing similar challenges.

Thank you for your patience and expertise!

This doesn't look right:
image
I suspect you actually built it like this, given the fact that you state it works:
image

But as I understand, this was an AI-fart:

Which also makes them virtually useless in your learning process. Or perhaps even worse than useless: they confidently set you on the wrong path.
Keep in mind that the AI models you're using are language models, basically. They put together words (or pixels, or waveforms, etc.) that the model 'knows' generally occur in a certain combination based on its training on large datasets. The model as such has no conception of how something works. It doesn't "know" whether something is right or wrong. It just generates a pattern that fits with its training data. The naked truth is that this does not work at a fundamental level for stuff like engineering. Even if it does, it has the major drawback that it's fundamentally impossible to figure out how the model has arrived at its conclusion, which makes it useless in an education process: based on an AI-generated result, you can never, ever work out the design steps taken to reach that result - because there aren't any!

I also assume you never close either of these switches unless you're checking whether the 24V power supply has a short-circuit protection:
image
In which case it's still an odd and irresponsible test. So again you probably mean something different from what you've drawn.

A similar issue exists with how the drain of the MOSFET is connected to the 24V supply; if you really wired it up this way, you would have built a self-destruct circuit that burns itself out as soon as D7 is set HIGH on the Arduino. It would put you in the good company of Ralph Metzger and Banksy. But it's probably not what you intended, or in fact did.

There's no kickback diode across the MOSFET. This might have killed it, especially if the switched load is inductive. Wire a suitable diode (1n400x would do) with the anode connected to the MOSFET drain and the cathode to the +24V line.

Might be a hardware/wiring or a software issue. Since we effectively know neither, it's impossible to tell at this point.

OK, so it oscillates for some reason. See above; depends on actual hardware design/schematic and code. Power supply may also have something to do with it. If you offer specific and correct information on the system as built, it will likely be possible to point out the cause.

I understand and sympathize. As pointed out above, the schematic needs work; as it is now, it's probably wrong in two ways: (1) it most likely contains a number of design flaws and (2) it doesn't really represent the system as built.

Could you post some clear photos of the system as built?
Also, for updating the schematic, start by simply capturing the way you have wired it up right now, whether that's right or wrong. Just draw each individual component and each connection you've made.

Thank you for the quick answer. I wanted to comment on this first, and look at everything else later when I have the time :slight_smile:

I might have misunderstood the entirety of how the garage door opener actually works, but here is how I have deduced what I was drawing there:

  • Put a multimeter in V mode on the positive and negative terminal of the garage port opener (marked START, see page 6 in the manual I was able to find just now: https://ismartgate.com/manuals/Bernal_GAMMA_600_manual.pdf).
  • Get a reading of 24V (ish).
  • Read manual, read that a normally open switch should be used.
  • Short the two terminals - door triggers.
  • Had a Meross garage door opener connected already - check continuity between the two wires when it triggers. Starts with no continuity and when triggering has about 500 ms of continuity.
  • Wire up a physical switch with a spring to be able to close it when I leave the garage. Normally closed makes the garage door blink and not work when powered on. Normally open works as expected. Pressing the switch and momentarily shorting the "START" and negative closes the door.

This is really the thought process here. So I thought OK, I just need to trigger a MOSFET to short the two wires for 500 ms and the door will start moving!

Is it the fact that I have drawn a DC power source in the schematic that is wrong? I don't quite understand.

In the schematic you'll modify/update, show how you've connected your own circuit to this header of the garage door control module:
image

There's a number of ways to do this.
You could either isolate your own circuit from the garage door thing and use either a relay or an optocoupler to momentarily short pins 1 & 2 to trigger the garage door action.
Alternatively, you could power your own circuit from the 24V of the garage door control box (using a DC-DC step down converter rated for at least 24V input) and use a MOSFET to momentarily short START to the common GND of your circuits.
I suspect you went for a third, hybrid option which is a separately powered Arduino with a common GND to the garage control box.

Whichever option you chose, the schematic you've drawn is not correct. Either you are using the garage control box for the 24V supply, but in that case I hope/assume you're not using the MOSFET to short that supply to GND. Otherwise you would have likely run into bigger problems already - although the garage control thing might be sufficiently fool-proof to withstand this without too much trouble.
Or you're shorting the START control input to GND with your Arduino circuit, but in that case the 24V source drawn in your circuit is either not there in reality, or it's connected differently.

Something is wrong around that 24VDC source, that's for sure. There are several options for what that might be, and some of those options are not even mutually exclusive.

If I were to make a wild guess based on the confusing information available so far, my guess would be that there's a 65% likelihood that the erratic door action is the result of a coding issue in your sketch, which we've not had the chance to see, yet. Might be 60%, though. Who's to say.

Yeah, in principle that should work, but the how & what depends on a couple of other things, too; see above.

Please update the schematic as per your actual wiring and post some photos of what you've got there. It'll convert the guessing game into a troubleshooting exercise.

Got you!

I will try to get some pictures later when I can go to the garage, but I actually made a shield for the Arduino by buying a PCB after sketching it up in Fritzing. Probably hard to get a good view from a picture, but maybe screenshots can help clear some things up.

About the "power supply" part - I just saw 24V potential between pin 1 and 2 from the image you posted and thought "Oh, must be a power supply here in the schematic". I have not redesigned the PCB for the new sensor, just hooked stuff up to ground pins etc. on the PCB I have. I think it would be prudent to see how the working system was put together and work from there.

So here is the original PCB sketch.

Top layer:

Bottom layer:

Both layers:

  • R1 is 220 ohm and R2 is 100k ohm.
  • J5 round is where I put the negative from the garage door motor
  • J5 square is where i put the "START" that has 24V potential against negative
  • I hooked up the ultrasonic sensors to the other terminals (J1 - J4).
  • The Arduino gets power through a USB cable into a wall adapter
  • Arduino ground is not hooked up to anything else, so if we can call the negative on the garage door terminal "ground", then the 100k resistor is the only thing connecting them

I have tried to make a diagram of how it's wired based on this (not showing the Meross and physical switch) in a simpler way:

Here is the code from when everything was working (before the sensor swap):

#include <NewPing.h>

#define TRIGGER_PIN_1 2
#define ECHO_PIN_1 3
#define TRIGGER_PIN_2 4
#define ECHO_PIN_2 5
#define TRIGGER_PIN_3 10
#define ECHO_PIN_3 11
#define TRIGGER_PIN_4 12
#define ECHO_PIN_4 13

#define CAR_MAX_DISTANCE 150
#define DOOR_MAX_DISTANCE 200

#define DOOR_TRIGGER_PIN 7

const unsigned long measurementInterval = 100; // time between measurements in ms
unsigned long lastMeasurementTime = 0;		   // last measurement time

const int validChangeThreshold = 10; // Number of consistent measurements to validate a change
int car_1_ChangeCount = 0;			 // Counter for consecutive measurements of car 1
int car_2_ChangeCount = 0;			 // Counter for consecutive measurements of car 2
bool lastCar_1_Present = false;		 // Last confirmed presence status of car 1
bool lastCar_2_Present = false;		 // Last confirmed presence status of car 2

int car_count = 0;
int last_car_count = 0;

bool door_blocked = false;
const int doorChangeThreshold = 10; // Number of consistent measurements to validate a door blockage change
int doorChangeCount = 0;			// Counter for consecutive measurements of door 1
bool lastDoorBlocked = false;		// Last confirmed blockage status of door 1

unsigned long unblockedStartTime = 0;	// When the door becomes unblocked
bool isCountdownActive = false;			// To manage the countdown state
unsigned long doorClosingStartTime = 0; // When the door starts closing
bool doorIsClosing = false;				// To manage the door closing state

#define SENSOR_NUM 4	  // Number of sensors.
#define MAX_DISTANCE 200  // Maximum distance (in cm) to ping.
#define PING_INTERVAL 100 // Milliseconds between sensor pings (adjust if needed).

unsigned long ping_timer[SENSOR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SENSOR_NUM];		  // Where the ping distances are stored.
uint8_t current_sensor = 0;			  // Keeps track of which sensor is active.

NewPing sonar[SENSOR_NUM] = {
	NewPing(TRIGGER_PIN_1, ECHO_PIN_1, CAR_MAX_DISTANCE),
	NewPing(TRIGGER_PIN_2, ECHO_PIN_2, DOOR_MAX_DISTANCE),
	NewPing(TRIGGER_PIN_3, ECHO_PIN_3, CAR_MAX_DISTANCE),
	NewPing(TRIGGER_PIN_4, ECHO_PIN_4, DOOR_MAX_DISTANCE)};

void setup()
{
	Serial.begin(115200);
	pinMode(DOOR_TRIGGER_PIN, OUTPUT);
	digitalWrite(DOOR_TRIGGER_PIN, LOW);

	// Initialize the ping timers
	ping_timer[0] = millis() + 75; // First ping starts at 75ms
	for (uint8_t i = 1; i < SENSOR_NUM; i++)
	{ // Set the starting time for each sensor
		ping_timer[i] = ping_timer[i - 1] + PING_INTERVAL;
	}
}

void loop()
{
	unsigned long currentTime = millis();

	// Log all ping timer centimeter values on the same line

	Serial.print(cm[0]);
	Serial.print(",");
	Serial.print(cm[1]);
	Serial.print(",");
	Serial.print(cm[2]);
	Serial.print(",");
	Serial.println(cm[3]);

	for (uint8_t i = 0; i < SENSOR_NUM; i++)
	{ // Loop through all the sensors
		if (currentTime >= ping_timer[i])
		{												 // Is it this sensor's time to ping?
			ping_timer[i] += PING_INTERVAL * SENSOR_NUM; // Set next time this sensor will be pinged
			sonar[current_sensor].timer_stop();			 // Ensure previous timer is canceled before starting a new ping
			current_sensor = i;							 // Sensor being accessed
			cm[current_sensor] = 0;						 // Reset distance in case there's no ping echo for this sensor
			sonar[current_sensor].ping_timer(echoCheck); // Start the ping (interrupt will call echoCheck to look for echo)
		}
	}

	if (currentTime - lastMeasurementTime >= measurementInterval)
	{

		lastMeasurementTime = currentTime;
		updateCarCount();
		updateDoorBlockage();

		if (doorIsClosing)
		{
			if (currentTime - doorClosingStartTime <= 30000 && doorClosingStartTime != 0)
			{
				if (door_blocked)
				{
					doorIsClosing = false;
					doorClosingStartTime = 0;
					Serial.println("Door closing aborted because door is blocked.");

					digitalWrite(DOOR_TRIGGER_PIN, HIGH);
					delay(1000);
					digitalWrite(DOOR_TRIGGER_PIN, LOW);
				}
			}
			else
			{
				doorIsClosing = false;
				doorClosingStartTime = 0;
				Serial.println("Door closing status reset.");
			}
		}
		else if (!isCountdownActive)
		{
			// Check if conditions to start the countdown are met
			if (car_count < last_car_count && door_blocked)
			{
				isCountdownActive = true; // Start the countdown only when door becomes unblocked
				Serial.println("Countdown ready to start upon door unblocking.");
			}
		}
		else
		{
			// Countdown has been initiated, check the ongoing status or need to abort
			if ((door_blocked && unblockedStartTime != 0) || car_count > last_car_count)
			{
				// Abort conditions
				isCountdownActive = false;
				unblockedStartTime = 0;
				Serial.println("Countdown aborted due to door blockage or car count increase.");
			}
			else if (!door_blocked && unblockedStartTime == 0)
			{
				// Start the unblocked countdown
				unblockedStartTime = currentTime;
				Serial.println("Countdown started due to door unblocking.");
			}
			else if (currentTime - unblockedStartTime >= 5000 && unblockedStartTime != 0)
			{
				doorIsClosing = true;
				doorClosingStartTime = currentTime;

				// Completion of the countdown
				digitalWrite(DOOR_TRIGGER_PIN, HIGH);
				delay(1000); // Keep it on for 1 second
				digitalWrite(DOOR_TRIGGER_PIN, LOW);

				// Reset everything for next trigger
				isCountdownActive = false;
				unblockedStartTime = 0;
				Serial.println("Countdown completed. Door closing initiated.");
			}
		}

		// Update car count for next cycle
		last_car_count = car_count;
	}
}

void echoCheck()
{ // If ping received, set the sensor distance in the array
	if (sonar[current_sensor].check_timer())
	{
		cm[current_sensor] = sonar[current_sensor].ping_result / US_ROUNDTRIP_CM;
	}
}

void updateCarCount()
{
	unsigned int car_1 = cm[0];
	unsigned int car_2 = cm[2];

	bool car_1_present = (car_1 != 0); // Car is present if the measurement is not zero
	bool car_2_present = (car_2 != 0); // Car is present if the measurement is not zero

	// Check car 1 presence status
	if (car_1_present == lastCar_1_Present)
	{
		if (++car_1_ChangeCount >= validChangeThreshold)
		{
			// Status is confirmed after 20 consistent readings
			if (car_1_ChangeCount == validChangeThreshold)
			{
				car_1_ChangeCount = validChangeThreshold; // Lock the change count to avoid overflow
			}
		}
	}
	else
	{
		car_1_ChangeCount = 1; // Reset the change count on any status change
		lastCar_1_Present = car_1_present;
	}

	// Check car 2 presence status
	if (car_2_present == lastCar_2_Present)
	{
		if (++car_2_ChangeCount >= validChangeThreshold)
		{
			// Status is confirmed after 20 consistent readings
			if (car_2_ChangeCount == validChangeThreshold)
			{
				car_2_ChangeCount = validChangeThreshold; // Lock the change count to avoid overflow
			}
		}
	}
	else
	{
		car_2_ChangeCount = 1; // Reset the change count on any status change
		lastCar_2_Present = car_2_present;
	}

	// Update car count based on validated changes
	if (car_1_ChangeCount >= validChangeThreshold && car_2_ChangeCount >= validChangeThreshold)
	{
		car_count = (lastCar_1_Present ? 1 : 0) + (lastCar_2_Present ? 1 : 0);
	}
}

void updateDoorBlockage()
{
	unsigned int door_1 = cm[1];
	unsigned int door_2 = cm[3];

	//	Bool to hold door blocked status at given moment.
	bool any_door_blocked = (door_1 != 0) || (door_2 != 0);

	// Check if door blocked status has changed.
	if (any_door_blocked != lastDoorBlocked)
	{
		// Increase the count of samples as long as the door status is in a changed state.
		++doorChangeCount;
	}
	else
	{
		// If the door reverts to an unchanged state, reset the change count.
		doorChangeCount = 0;
	}

	// When we reach the sampling threshold, we can trigger the change of the global bool.
	if (doorChangeCount >= doorChangeThreshold)
	{
		// Update global bool.
		door_blocked = any_door_blocked;

		// Reset sampling count.
		doorChangeCount = 0;

		// Set the last blocked status to the current status so we are
		// in an unchanged step the next loop.
		lastDoorBlocked = any_door_blocked;

		// At this point we will not increase doorChangeCount again
		// until one of the door sensors have a new change in status.
	}
}

Is this a setup that should not work in theory? Because it has worked in practice :sweat_smile:

Sidenote: I did not understand the blue down arrow (ground?) in your corrected MOSFET circuit. Is that another ground that's connected to the Arduino ground or is that just to show that we are connecting to the Arduino ground there?

image
That won't work well.
Replace R2 (100k) with a jumper wire.

However, I'd strongly suggest in this case to not use a MOSFET but to use either a relay or an optocoupler. This will keep your garage door box electrically isolated from your Arduino.

OK. Looks like an AI monstrosity. At this point, the AI tools people use for generating code results in overly verbose spaghetti-code that's virtually impossible to make sense of and virtually always exhibits unintended behavior. My recommendation is to set it aside and start over.

Before doing so, make a flowchart that describes what your code will do. That flowchart will be your template for making the code.

Will do!

I'm going to use a relay. I will post a diagram of how I am thinking of connecting everything and I will rewrite the code from scratch considering the relay and new sensor.

Then I'll try to get to something that works in theory before hooking it up in practice. When I have tested the code and circuit I'll have a new PCB made so it's tidy.

I don't have access to my drawing program right now, but if you look at this:

I was in the garage running some wires to make it more tidy and in preparation for building the new circuit with the relay module. See the image above of my other circuit.

I am having trouble understanding this voltage divider. The wires from the photoelectric sensor are 10 meters. So I run 10 meters for ground and 10 meters for the 12v signal up to where the Arduino sits.

If I connect the ground from the sensor to the ground on the Arduino and measure across ground and signal cable, I get 12.12V.

My understanding is that I would read around 4V between the signal and ground after the voltage divider, but I don't. I measure 2.6V.

When measuring across the 10k resistor I measure about 5.2V, and when I measure across the 5.1k resistor I get about 2.6V.

If I connect the 2.6V signal cable after the voltage divider to the Arduino and measure across that and ground I suddenly get 1.2V.

Something is wrong here. Am I measuring wrong, or have I completely misunderstood how to set up a voltage divider to bring the 12V down to a safe voltage? Is the 10 meter cable the problem, but only after connecting to the voltage divider?

I don't think my multimeter has an internal resistance that would make the measurements so wrong? Maybe a bit off, but this much?

Start with a lab/test setup on your desktop with a 12V (or so) voltage source, a DMM that is set to measure current in the loop and two resistors. Build your voltage divider and verify that it works by measuring the voltage at the junction of both resistors. Verify that the total current draw from the 12V (or whatever) supply matches what Ohm's law tells you for both resistors in series.
Now connect the GND of your divider to an Arduino and the junction of the resistors to an analog input. Make sure that on the Arduino you have a sketch that only periodically reads the analog input and outputs that to the Serial monitor. Work on that sketch until you can correctly output the measured voltage to the Serial monitor so that it corresponds with what you can measure with your DMM.

In other words: isolate the subsystem and work with it until you understand it.

From your description it's unclear what may be the cause of your trouble; it could be something silly like the D5 pin somehow set to OUTPUT and LOW in your code. It could be a poor contact or a short somewhere. It could be a simple case of having something miswired.

This may/will become a problem at some point. What if a thunderstorm passes in the area? The induced current in the 2x10m antenna may easily fry the sensor and/or Arduino. One relatively easy way to fix this is to buffer the digital input by running it through a transistor (which will invert the signal, but that's easy to correct for in your code) or even an optocoupler. If the photo sensor is indeed powered by its own, dedicated 12V supply as indicated on the schematic, it would make good sense to use an optocoupler so that the Arduino circuit is effectively isolated from the sensor subsystem.