top of page
  • Writer's pictureJack Chen

Pcomp week 3

This week’s contents include the tone output lab, servo motor control lab, and planning for assignment one.

The first setup in tone output consists of two force sensing resistors in a voltage divider connected to an input pin on the Arduino, then outputting the input onto a speaker. A key component of the coding was to map the input from the rough range produced when interacting with the 2 FSRs to whatever range of frequency desired to be played by the speaker.

The next part of the lab had us playing a melody from the speaker by directly coding the instructions into the Arduino IDE. This was the first time I learned to use a library in a sketch, the example code created a new tab named “pitches.h” containing information on the frequency of each musical notes and called in this information at the beginning of the code. The original code had the notes play once in the setup code, but I moved the code to the loop so it plays repeatedly for easier documentation.

The next part of the lab makes a simple instrument by having different FSRs playing different notes through the speaker as they are pressed. This again was done referring to the “pitches.h” library for the frequency of the notes, and then checking and playing input from each FSR with an “if” statement checking for the intensity of input of FSR nested inside a “for” loop which checked which FSR is pressed. I am not sure how each notes are assigned to individual FSRs in the example code, seems like the order of the notes listed in the “int notes” are automatically assigned to the sensors? I am not sure at this time.

Since I only had 2 FSRs, I removed a note and the sensor amount in the “for” to work with two notes and two FSRs instead of three. Another change I made to the example code was the duration of the notes. At first when I press the FSR the note would play barely long enough to be recognized, so I extended the note duration time to a point where the note continue playing a bit after I release the FSR. The result is shown below.

After completing the Tone output lab, I moved on to the servo motor control lab. The servo motor control lab make use of the servo library in the Arduino IDE. After adding the library, control of the motor’s angle was achieved by having analog input from a sensor (FSR in this example) mapped to an angle on the motor between 0-179 (for 180 degrees of turning) by defining the servo angle integer – a function from the servo library.

When I first set up the lab based on the example provided, the motor did not move when I pressed the FSR. I begin troubleshooting by replacing the motor with an LED, which does light up. I can also hear a small clicking noise from the motor when pressing the FSR with the motor in the circuit, so it would appear that the circuit was setup properly with power being supplied to the motor. I then searched online the specifications of the specific motor I used and found out that the motor’s operating voltage is 4.8-6V. With the current circuit setup drawing power from my 3.3V Arduino Nano 33 IoT, I realized the lack of motor movement was cased by a lack of voltage being supplied from the Arduino. I solved this problem by connecting another power source to the motor using a DC power jack and voltage regulator.

DC power for motor

After getting the motor working, I attached a laughing bread keychain to the motor and made a laughing bread that spins its head whenever I pressed the FSR

Assignment 1 idea:

I looked around my room for inspirations for an idea for assignment 1 and I decided to use a toy dragon I had from before for the assignment. My idea is to create an interactive lock/toy where the user can politely ask the dragon for their treasure by entering the message on a mini keyboard. If the keys are pressed in the correct order, the dragon will lift its hand to allow the user to take what they are looking for.

I plan to do this by first making a combination lock using several pushbuttons. Each pushbutton will have a word written on it and the passcode will be a sentence asking the dragon to hand over what it’s holding underneath its hand (something like “can I have the treasure please”). With a group of “if” statements nested inside each other, I will make the Arduino trigger an output upon the pushbuttons being pressed in the correct order (each button will be labeled with a word from the sentence and put in a mixed order, the correct order of buttons will be one which the words are pressed in an order that makes the coherent password sentence).

The Arduino code will trigger a servo motor movement when the pushbuttons are entered in the correct order, and the servo motor will be attached to the dragon’s arm, lifting it to reveal an object beneath it.

So far I have made a test setup consist of a modified version of the servo motor lab with the motor attached to the dragon’s arm:

0 views0 comments

Recent Posts

See All
bottom of page