3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

スイッチを押し返すロボット(uselessbox)制作期

Last updated at Posted at 2023-12-01

ESP32の使い方が分かってきて、そろそろハードウェア関係に手を出そうかなと思っていたところ簡単に作れそうでかつ面白そうなものがあることを思い出しました。
その名もuselessboxです!

昔ニコニコでバズってたそうですね、youtubeのものになりますが参考動画はこれです↓

材料

制作には以下のものを使いました

3Dプリンターを使った方がいい気もしたのですが、単純に3Dプリンターをもっていないのと金欠だったので紙粘土で頑張りました。簡単な形でかつ負荷があまりかからないなら、紙粘土はいい選択肢だと思います()

制作

箱にトグルスイッチ用の穴をあける

彫刻刀を使って穴をあけました。位置はこの辺です
箱穴.png
ちょっとずつ穴を開けてトグルスイッチがちょうどハマるサイズになるようにしました

トグルスイッチの取り付け

トグルスイッチには4つ部品があって始めどう使えばいいのかよくわからなかったので、後続の人のためにここに取り付け方の動画を置いておきます

サーボモータの取り付け

紙粘土を土台にしてサーボモータを取り付けました。蓋の高さギリギリに取り付けて蓋を開ける動作やトグルスイッチを押す動作をしやすくしています

スイッチを押す腕を作る

これが結構難しく、大きさの調整や耐久性に色々悩みました。最終的には大きさを整えてそこそこの耐久性を持つ紙粘土の腕を作りました。(写真は撮り忘れたのでないです)

MDFで作った作成途中の腕です。サーボモータの部品にこんな感じで取り付けました。ただこのやり方は腕にそこそこ負荷がかかるので違うやり方の方がいいのかもしれません

負荷がかかるとこんな風にもげて壊れます。とほほ

スケッチの作成

https://livingtips.blog/blog/useless-box-prototype/
を参考に作りました
サーボモータの制御ライブラリはこれのバージョン1.1.1を使いました
https://madhephaestus.github.io/ESP32Servo/annotated.html

uselessbox.ino
#include <ESP32Servo.h>
#define WAIT_TIME 50 // 500ms wait
#define SERVO_PIN_1  4    
#define SERVO_PIN_2 2                                                                                                                                                                                                                    
#define LED_PIN  32
#define SW_1  33

Servo sg90Lid;
Servo sg90Hand;
int opendelay;    // 蓋開けディレイ時間(*100ms)
int opendelayLimit = 2;
int closedelay;   // 蓋開けディレイ時間(*100ms)
int closedelayLimit = 2;

hw_timer_t * timer = NULL;

void Lidtimer() {
  opendelay++;
  closedelay++;
}

void setup() {
  Serial.begin(115200);
  sg90Lid.attach(SERVO_PIN_1, 510, 2400);
  sg90Hand.attach(SERVO_PIN_2, 510, 2400);
  pinMode(LED_PIN, OUTPUT);
  pinMode(SW_1, INPUT_PULLUP);

  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &Lidtimer, true);
  timerAlarmWrite(timer, 1000000, true);
  timerAlarmEnable(timer);
  // 100msごとにLidtimerを呼び出し、タイマースタート
}



void loop() {
  if(digitalRead(SW_1) == HIGH) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("on");
    
    sg90Lid.write(110);
    if(opendelay > opendelayLimit) {
      Serial.println("move_on");
      sg90Hand.write(175);

      closedelay = 0;
    }
  }

  if(digitalRead(SW_1) == LOW) {
    Serial.println("off");
    digitalWrite(LED_PIN, LOW);
    sg90Hand.write(0);

    if(closedelay > closedelayLimit) {
      Serial.println("move_off");
      sg90Lid.write(10);
      opendelay = 0;
    }
  }

}

箱の中に組み込み

ブレッドボードなどを適当に組み込みました

完成!

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?