Week 4

Microcontroller Programming

Arduino Close UP
Kinetic Sculpture Circuitry

Problem

For this week's assignment, I wanted to build upon last week's project where I built a miniature version of the famous Ali and Nino statue. The main issue with kinetic component of the sculpture was that the motors rotated far too fast for the heads to intersect smoothly. To that end, I aimed to incorporate a potentiometer and L9110 motor driver to better control the speed of the sculpture.

Solution

In order to drive the two motors, I built upon the code that we learned in class this week. By incorporating two motor drivers, I was able to easily control how much voltage each motor got. I connected one end of each motor to pins 3 and 6, and I inserted a potentiometer into my Adafruit METRO board in pins A0, A2, and A4. The setup for the circuit with the two motors is shown below. The Arduino code used to program the microcrontroller is at the bottom of the page. The resulting kinetic sculpture moved at a slower speed, although it was still a bit faster than the actual Ali and Nino statue. This makes sense because the actual statue is at a much larger scale, so it is much harder to move quickly. The final moving sculpture can be found in the documentation for Week 3.

top view
Circuit Set Up

Arduino Code:


        /*  Code to run motors in one direction based on potentiometer reading.
         *  Motor driver speed control on pins 3 and 6 (direction LOW by default)
         *  Potentiometer plugged into A0, A2, and A4 on Metro M0 (or similar).
         */

        void setup() {
          pinMode(3, OUTPUT);
          pinMode(6, OUTPUT);
          pinMode(A0, OUTPUT);  //This will be GND for the potentiometer
          pinMode(A4, OUTPUT);  //This will be 5V for the pot

          digitalWrite(A0, LOW);
          digitalWrite(A4, HIGH);

    
        }

        void loop() {
          int pot_value = analogRead(A2);   //pot wiper is on A2
          int motor_speed = map(pot_value, 0, 1023, 255, 0); // map motor_level to pot_value so that zero corresponds to lowest speed
          analogWrite(3, motor_speed); // controls motor 1
          analogWrite(6, motor_speed); // controls motor 2
          delay(1);
        }