2022-11-06T23:00:00Z
Hi Elements :
5V DC distance sensor, Arduino uno, 5V DC power supply, macbook
Situation (1)
The distance-sensor was powered by a own power supply. The signal of the sensor was connected to the D8 pin of the Arduino. DigitalRead of pin D8 resulted in random signals of HIGH and LOW. In other words the sensor-signals were no good. Sensor itself behaved correctly.
Situation (2)
When I powered the sensor via the arduino, 5V pin and ground pin, I was able to read the correct signals from the sensor.
Question :
Why does the powering of a sensor separately from the arduino not work ?
If you power up the sensor with a separate power supply, you have to make the grounds common. I mean the GND of the separate power supply should by shorted with the Arduino's GND. For any circuit to work, the GND must be common.
It seems to me that you considerate it like a "hack"...?
It is not the "hack", this is general rule of electric communications. Electric current to be able to flow requieres TWO wires, When you connects data pin of the sensor to the arduino - it makes first wire, and GND will be second.
Hack ? What do you mean ? Two wires I know.
Nevermind : Apparently the GND of the Arduino, when connected to my Macbook, (my Macook suplies Voltage and GND (I think and thought it does) is not sufficient for currents flowing from sensors to the arduino.
Allright.
Solution is clear and my problem has been solved.
Thanks !
What we usually refer to as 'ground' is actually a zero volt reference. The Arduino compares any voltage it gets to that reference. If it's the same as the reference it's a zero, if it's five volts more positive than the reference it's a one. Your sensor does the same thing, but compares everything to the sensor's ground reference. The problem is that the sensor's 'ground' and the Arduino's 'ground' may, and probably will, not be at the same voltage relative to the earth.
The solution to the problem is to make sure they are at the same voltage by connecting them together. In fact, the general rule is to connect all grounds together unless you have a very good reason not to.
Ah, this is the reason why. I understand it. I was not aware of the basic rule of connecting grounds together when you have several electrical circuits. Thanks !!