Could we assemble a wall that drop ball when lever is pressed? Coding part is super simple, but what about mechanics?
Here is short video with operation. Ball droped after button is pressed.
Servo and button with lever attached.
Lever with a simple push button.
Servo in a lego enclosure.
Rotating panel, that unload ball.
Source code for nodemcu:
//rotate SG90 90degrees on button press, then rotate back
#include <Servo.h>
//nodemcu have inverted LOW/HIGH
#define TURN_ON 0
#define TURN_OFF 1
int led2 = D0;
int button_pin = D1;
int servo_pin = D4;
Servo servo;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(button_pin, INPUT);
//pinMode(servo_pin, OUTPUT);
blinkInternal();
servo.attach(servo_pin);
servo.write(0);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button_pin) == 1) {
blinkInternal();
activateGate();
}
delay(100);
}
void activateGate() {
servo.write(90);
delay(1000);
servo.write(0);
delay(1000);
}
void blinkInternal() {
digitalWrite(LED_BUILTIN, TURN_ON);
delay(200);
digitalWrite(LED_BUILTIN, TURN_OFF);
delay(200);
}