Connection
Expansion board MB2
The cash register has one IR sensor that is connected with 3 Dupont wires and a button that is connected with 2 wires.
There are 4 pins on the IR sensor – VCC (power), GND (ground), D0 (Digital signal) and A0 (Analog signal). The IR sensor is connected to the expansion board as follows. We connect all the duponts to pin 2 so that the signal pin DO to the yellow signal bar, VCC to the white power bar and GND to the black ground bar.
There are 3 pins on the button – C, N0 and NC. We connect the button to pins C and N0. We connect pin C to the expansion board on P1 to the yellow signal bar, we connect pin N0 to the black ground bar.
And finally, we connect the servo motor to pin 0 so that the yellow dupont is connected to the yellow strip.
Recommendation
Program
The insatiable piggy bank
This code works so that the cash register responds to coin detection.
First, we set pins P1 and P2 so that they are ready for detection. The principle of the whole program is that the micro:bit constantly waits until the signal is interrupted. The signal is interrupted by feeding the money box with a coin. Pin P2 then issues a signal that starts the servo motor. It turns to a value of 180 and opens the money box using its arms. It waits in this position for 500 ms. Then the servo turns to a value of 90. The last step is that the program waits 1 second for the whole process to finish. Then the money box waits for the next coin. But be careful, the money box is very greedy!





