Open-collector wired AND
Two Hall sensors with open-collector outputs share one wire and a pull-up resistor, so the wire goes low when either sensor sees a magnet. You see a wired AND made from nothing but a wire, and why buses such as I2C work this way.
Build it step by step
0 of 7 doneWire both sensors to 5V, GND and their own pins
Outputs to D3 and D4.
Nothing extra is needed for step one
The sketch turns on the Nano's own pull-ups.
Upload and bring the magnet to each sensor
Each reads 0 on its own.
Join the two outputs with a jumper wire
Keep one 10 kilohm resistor to 5V.
Bring the magnet to sensor 1, then 2, then both
Both pins now read the same.
Fill in a truth table
Idle, one, the other, both.
Remove the jumper
They are separate again.
How do you build an open-collector wired AND?
Two Hall sensors with open-collector outputs share one wire and a pull-up resistor, so the wire goes low when either sensor sees a magnet. You see a wired AND made from nothing but a wire, and why buses such as I2C work this way. You need Arduino Nano, Hall Effect Sensor A3144 × 2, Resistor 10 kΩ, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 70 minutes.
- Level
- Intermediate
- Time
- About 70 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Both A3144 pin 1 (VCC) | Nano 5V | Power |
| Both A3144 pin 2 (GND) | Nano GND | Common ground |
| Sensor 1 output (pin 3) | Nano D3 | Read on its own at first |
| Sensor 2 output (pin 3) | Nano D4 | Read on its own at first |
| Jumper wire | Joins the two output wires together | Added in step two to make the shared wire |
| 10 kilohm resistor | Joined output wires to 5V | The pull-up for the shared wire |
| LED long leg | Nano D8 through a 220 ohm resistor, short leg to GND | Lights when D3 reads low |
Code
The A3144 has an open-collector output. It can pull its output wire down to ground, but it cannot push it up, and it needs a resistor to 5 volts to bring the wire high again. That makes it safe to join two outputs together, because they can never fight each other. In step one the two output wires go to separate pins, each held high by the Nano's own pull-up. In step two you add a jumper wire that joins them, with one 10 kilohm resistor to 5 volts, and now both pins read the same shared wire. The shared wire is high only when both sensors are idle, and low when either one pulls it down, which is the logic of an AND on the idle-high signals. Bring a magnet to sensor 1, then to sensor 2, then to both, and see the table of readings. This is exactly how I2C lets many chips share one wire. Use small magnets, keep them away from phones and cards, and check the pin order of your sensor, since a wrong power connection can ruin it.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const uint8_t OUT1_PIN = 3;
const uint8_t OUT2_PIN = 4;
const uint8_t LED_PIN = 8;
int last1 = -1, last2 = -1;
void setup() {
pinMode(OUT1_PIN, INPUT_PULLUP); // the Nano's own pull-ups serve step one
pinMode(OUT2_PIN, INPUT_PULLUP); // the 10 kilohm resistor makes the shared wire firmer
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("sensor1 sensor2 (1 = idle, 0 = magnet near)");
}
void loop() {
int s1 = digitalRead(OUT1_PIN);
int s2 = digitalRead(OUT2_PIN);
digitalWrite(LED_PIN, s1 == LOW ? HIGH : LOW);
if (s1 != last1 || s2 != last2) {
last1 = s1; last2 = s2;
Serial.print(s1);
Serial.print(" ");
Serial.println(s2);
}
delay(20);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
sensor1 sensor2 (1 = idle, 0 = magnet near) 1 1
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Separate outputs | Each pin follows its own sensor |
| Joined outputs, no magnet | Both read 1 |
| Joined, magnet at either sensor | Both read 0 |
| Joined, magnet at both | Both read 0 |
| LED | Lights whenever the shared wire is low |
If it does not work
Both always read 0
Check the pull-up resistor goes to 5V and not GND.
Neither responds to the magnet
Turn the magnet round or try the other face.
Sensor gets warm
Disconnect, the power pins may be swapped.
Joined wire stays low
A magnet may be left near one of the sensors.
No serial text
Set 9600 baud.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the open-collector wired AND?
Arduino Nano, Hall Effect Sensor A3144 × 2, Resistor 10 kΩ, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the open-collector wired AND take to build?
About 70 minutes for a intermediate maker, in 7 steps.
How do I know the open-collector wired AND works?
Separate outputs: Each pin follows its own sensor. Joined outputs, no magnet: Both read 1. Joined, magnet at either sensor: Both read 0.
Both always read 0: what should I check?
Check the pull-up resistor goes to 5V and not GND.
Neither responds to the magnet: what should I check?
Turn the magnet round or try the other face.
Sensor gets warm: what should I check?
Disconnect, the power pins may be swapped.
Joined wire stays low: what should I check?
A magnet may be left near one of the sensors.
