Week 8

 

This week, I used to different Arduino boards, the Itsybitsy M4 and a SAMD11C14A to create a lil dancin buddy to keep me company during these trying times.

The setup

I got the boards up and running. I used two seperate instances of the Arduino IDE to control each one

Image

A quick test

To see that I can get the boards to communicate with each other, I set up a simple circuit with a button and a servo. The SAMD11 checks for a buttom press then transmits a signal to the ItsyBitsy. Once the ItsyBitsy reads that signal, it send a signal to the servo.

Dance test

Now that this worked, it’s time to build a body for my dancer.

Forging a body

First, I install a connector piece onto each one of servos so that I can secure them to the body frame. Image

The frame I’m using for the body is a simple camera mount from an old project. The holes allow me to secure the servos onto them well. I also use a little bracket on the inside to hold the middle servo in place. This makes it so that the large bracket moves instead of the servo itself. The middle servo controls the body of the dancer while the servo at the bottom controls the neck. You’ll see what I mean soon.

Image

I lock the servo with the tilt axis.

Image

Now onto the code!

The test code

Here’s the code for the Transmitter:

const int out_pin_one = 2;
const int button_pin_one = 4;

const int out_pin_two = 9;
const int button_pin_two = 14;

void setup() {
  pinMode(button_pin_one, INPUT_PULLUP);  //This is the button pin.
  pinMode(out_pin_one, OUTPUT);         // pin 5 for digital Write

   pinMode(button_pin_two, INPUT_PULLUP);  //This is the button pin.
  pinMode(out_pin_two, OUTPUT);         // pin 5 for digital Write

  Serial.begin(9600);        //for the USB serial devices, this baud rate is meaningless - can be "0"
}

void loop() {
  int buttonState_one = digitalRead(button_pin_one);
  int buttonState_two = digitalRead(button_pin_two);
  
  Serial.println(buttonState_one);
  Serial.println(buttonState_two);
  
  digitalWrite(out_pin_one, buttonState_one);
  digitalWrite(out_pin_two, buttonState_two);
  delay(10);
  }

And here’s the code for the receiver:


#include <Servo.h>

Servo myservoFirst;  // create servo object to control a servo
const int inputPinFirst = 12;
const int servoPinFirst = 10;

Servo myservoSecond;
const int inputPinSecond = 9;
const int servoPinSecond = 7;

void setup() {
  pinMode(inputPinFirst, INPUT_PULLUP);   // pin 12 for digitial read
  pinMode(inputPinSecond, INPUT_PULLUP); // pin 5 for digi read
  myservoFirst.attach(servoPinFirst);  // attaches the servo on pin 9 to the servo object
  myservoSecond.attach(servoPinSecond);
}

void loop() {
  if (digitalRead(inputPinFirst)){
    myservoFirst.write(0); // commands the servo to jump to its middle position (90 degrees)
  }
  else {
    myservoFirst.write(90); 
  }

  if (digitalRead(inputPinSecond)){
    myservoSecond.write(10); 
  }

  else {
    myservoSecond.write(60);
  }

}

The completed circuit

Here’s the upgraded circuit. It has a button for each servo so that I can control them seperately.

Image

The final result!

To give my friend a head, I cut open an old rubber bouncy toy I had and placed it on the ‘neck’ servo.

And off he goes!

Sound dance

I should probably secure the head on a little better……..