I am a software engineer. I can make a lot of stuff with many languages and tools, and I touched even more technologies, but I lack the skill to understand hardware better. This is the root, I guess, of my need to take a closer look. The issue is, I never managed to find time for it.
Until one day, I bought an Arduino kit with some basic sensors, indicators, and other components. I did play a bit with it, but guess what I created without any real goal? Arduino’s hello-world: custom weather station, which is worse than what you can buy and even more expensive. It doesn’t work well till this very day, but more about that maybe in another post.
The whole kit was a perfect dust collector. It works that way even if all is turned off, well, actually, even more when it’s turned off. With strict pandemic lockdowns, there was finally the time. My wife had a great idea of what she would like to have—an automatic dim light in the bathroom. The light is still not there, more about that also maybe some other day.
I follow YouTuber Mark Rober, and he created an online course Creative Engineering. That sounded interesting, so I enrolled. I thought that I could learn a lot of manual skills how to build things. Unfortunately, it is more focused on creating builds with a story and how to make it engaging. That’s fine, but not what I was looking for.
Anyway, I’m still glad I did the course because it forced me to sit down and really do something. So if you need some push to start doing something, I can recommend this course. It’s at least fun. And you can definitely learn many tips and tricks; it just depends on your background. I guess kids will appreciate it much more.
One week was about creating something related to art. It could be anything. Fortunately, my wife plays on the piano, and sometimes music sheets span over multiple pages. That’s always hard for her. But easy for me!
It just needs one servo motor attached to Arduino that initiates a move when a button is pressed. It is super easy and practical. The tricky part is how to create the mechanism for turning the pages.
I used a simple clip you can use for papers. This part is used to attach the whole thing to the hardcover. Then I needed something to hold the servo motor. We bought a few IKEA libraries, and every single one had L-shaped pieces of metal to fix the furniture with the wall on the top. I never used it but kept it. Now it was helpful. I just needed to put it together with a bolt.
The last part was to prolong the small arm of the servo motor. Something long, tiny, light, and durable. I couldn’t go to any hardware shop during the strict lockdown, so I found a simple wooden skewer. I think it is not much enduring, but still good enough. It still works after half a year. At the end of the skewer, I attached a clothes peg.
The final touch is ordinary cardboard to hide the Arduino with the button and form a pedal.
That’s it! If you need something like that and have Arduino at home, it’s about an hour or two to make it happen.
Here is the full code. Everything is easy peasy. The most interesting part is to make the flip not at full speed; otherwise, that would rip the arm off:
#include <Servo.h>
Servo servo;
#define PIN_SERVO 3
#define PIN_BUTTON 2
const int MOVING_TIME = 1000; // ms
const int LEFT = 180; // angel position of the arm on the left
const int RIGHT = 10; // angel position of the arm on the right
int prevState = LOW;
int prevPosition = RIGHT;
void setup() {
Serial.begin(9600);
servo.attach(PIN_SERVO);
servo.write(prevPosition);
pinMode(PIN_BUTTON, INPUT);
prevState = digitalRead(PIN_BUTTON);
}
void loop() {
int state = digitalRead(PIN_BUTTON);
if (state != prevState) {
prevState = state;
if (state == HIGH) {
turn();
}
}
delay(10);
}
void turn() {
if (prevPosition == LEFT) {
moveServo(RIGHT);
prevPosition = RIGHT;
} else {
moveServo(LEFT);
prevPosition = LEFT;
}
}
void moveServo(int newPosition) {
unsigned long moveStartTime = millis();
while (true) {
unsigned long progress = millis() - moveStartTime;
if (progress > MOVING_TIME) {
break;
}
long angle = map(progress, 0, MOVING_TIME, prevPosition, newPosition);
servo.write(angle);
}
}