So I've been working on getting two sensors to work in harmony while connected to an Arduino Micro or Uno. I'm using a digital PIR sensor and an analog ultrasonic sensor to detect motion. To make things nice an compact I designed a case the sensors can sit in and connect to a 4 wire JST (one for GND, one for PWR, one for data from PIR, and the other for data from Ultrasonic).
The sensors work completely fine by themselves and even when they are placed on a breadboard together using a common ground to the Arduino. However, as soon as I soldered the GNDs from the two sensors together to one of the JST wires the analog readings of the ultrasonic sensor no longer make sense an either stick to the same number or spike.
I also found it strange that during prototyping I had a 12 LED Neopixel ring light up whenever both sensors reached a threshold. The LEDs were also using the same GND/PWR and whenever they would turn on the analog readings of the Ultrasonic sensor would jump. But when I moved the GND of the Ultrasonic sensor to a different pin on the Arduino the readings were find even when the lights were on. I just found this strange since I thought the Arduino has the same ground potential on each pin.
Thanks for fixing the picture. Now I can see it all I can positively say I am non the wiser as to what it shows.
However if your problem is one of things not working when you join grounds it is unlikely to be your software that is at fault, it is likely to be the hardware. Can you produce a schematic showing what you have wired please.