Week 12 – Final Project Proposal: PawPortion Smart Pet Feeding Assistant

For my final project, I am creating PawPortion, a smart pet feeding assistant that combines a physical feeding system with a digital interface. The goal of this project is not to fully automate feeding, but to support the user in a way that feels clear and intentional. Instead of the system doing everything on its own, it tracks feeding time, prompts the user when it is time to feed, and gives immediate feedback when the feeding happens. I wanted the interaction to feel simple but still meaningful, where the user understands exactly what is happening at every step.

The system uses both Arduino and p5.js, connected through serial communication. On the Arduino side, the program controls a servo motor, an LED, and an IR sensor. The IR sensor detects when something is placed in front of it, which acts as the trigger for feeding. When the sensor is activated, the servo rotates to open the container and allow the food to pour out into a bowl, and the LED turns on at the same time to make the action visible and obvious. The Arduino also receives a “FEED” command from p5.js, performs the same feeding action, and then sends back a “DONE” signal so the interface can update.

On the p5.js side, I designed a full-screen interface that works as a feeding dashboard. It shows the next feeding time, the last time the pet was fed, and the current system status. There is also a “Feed Now” button that allows the user to trigger the feeding manually. The interface tracks time and changes the pet’s mood depending on the situation. The pet appears neutral while waiting, hungry when it is time to feed, happy after feeding, and sad if the feeding is missed. This makes the system feel more interactive and easier to understand visually. The interface sends the “FEED” command to Arduino and waits for the “DONE” response before updating the state.

So far, I have completed a draft of both the Arduino code and the p5.js interface. The communication between them is set up, and the overall system logic is working. At this stage, my main focus is building the physical structure and refining the aesthetic design. I will be constructing the feeder using cardboard and assembling the Arduino setup based on the wiring I have already mapped out. I want the final result to look clean and intentional rather than just a collection of components, so I will focus on hiding wires and making the structure feel complete.

For materials, I used my stipend to buy items that mainly support the physical design and presentation of the project. I purchased cardboard sheets to build the main feeder structure, colored paper to add visual layers and make the design more cohesive, and a small pet bowl to clearly show where the food is dispensed. I also bought paw print stickers to match the theme and make the project feel more playful, along with wooden sticks and decorative tape to help with building and structuring the feeder. These materials will help me create a clean and visually engaging final product without overcomplicating the technical side. I will also purchase and IR sensor obviously.

Overall, PawPortion focuses on creating a clear interaction between the user, the interface, and the physical system. The sensor or user input triggers the feeding, the Arduino performs the action, and the interface reflects it in real time. By combining a simple mechanism with a responsive interface and thoughtful design, the project turns a basic task into a more engaging and understandable experience.

Amazon Links: 

Final Project – Finalized Concept and Progress

 

Pressure-Based Digital Musical Instrument – Progress Update

For my final project, I am developing a physically interactive digital musical instrument that combines Arduino and p5.js. The main idea is to simulate a small piano-like interface using pressure sensitive sensors (FSRs) as keys. Each key corresponds to a musical note, and when pressed, it triggers both the sound and visual feedback on the computer.

The system is designed to feel closer to a real instrument rather than just a simple button interface. Instead of using traditional push buttons, I chose Force Sensitive Resistors (FSR406 for white keys and FSR402 for black keys) so that the interaction feels more natural when placing fingers on the surface.

The project also includes a visual component in p5.js, where each note triggers a graphical response (such as expanding shapes or bursts) aligned with the keyboard layout.

 

Arduino System Design (Input & Output)

On the Arduino side, the main responsibility is to read input from multiple FSR sensors and send that data to p5.js through serial communication.

Since I am using 13 keys (8 white + 5 black), I needed a way to expand the number of analog inputs. To solve this, I am using a CD74HC4067 multiplexer, which allows me to read multiple sensors using a single analog pin.

Inputs

* 8 × FSR406 (white keys)
* 5 × FSR402 (black keys)

Each FSR is connected through the multiplexer channels (C0–C12). The Arduino cycles through each channel, reads the analog value, and determines whether a key is being pressed based on a threshold.

Processing

* Scan each multiplexer channel
* Detect press events (based on pressure threshold)
* Map each sensor to a note index

Outputs (to p5.js)

* Sends serial data representing which key is pressed
(e.g., key index or note trigger)

 

p5.js System Design (Sound & Visual Output)

The p5.js side handles both sound synthesis and visual feedback.

Input from Arduino

* Receives serial data from Arduino (note index or trigger)
* Interprets incoming data as note events

Sound Output

* Uses p5.sound to generate tones
* Each note is mapped to a frequency (C4 → C5 range)
* Oscillator is used to produce sound (triangle waveform for smoother tone)

Because of browser audio restrictions, the user must click once on the screen before sound can play. This is an important part of the interaction design.

Visual Output

* Background image of a piano keyboard is displayed
* When a note is triggered:
* A visual “burst” or circle appears at the corresponding key position
* The animation fades out over time

This creates a synchronized audio-visual experience.

 

System Interaction Flow

Overall system flow:

1. User presses an FSR key
2. Arduino reads the sensor via multiplexer
3. Arduino sends note data through serial
4. p5.js receives the data
5. Sound is generated
6. Visual feedback appears on screen

This creates a continuous loop of input → processing → output.

 

Current Progress

So far, I have:

* Set up the basic circuit with some FSR sensors and breadboard
* Soldered to connect and tested the CD74HC4067 multiplexer
* Implemented initial Arduino code to read multiple inputs
* Keyboard mapping
* Sound generation
* Visual feedback system
* Tested interaction using keyboard input as a temporary replacement for hardware input

* Make cardboard box to cover and protect wirings

VDO of Current Progress:

On Arduino side, only test Voltage-Divider on 2 FSRs to see the correct circuit and their threshold and on p5 side only test sound oscillator and visual effect by computer keyboards

https://youtu.be/MlDVwkXKKx0?si=0aQA0kxDGdNnhAR8

Github of testing FSR:

https://github.com/skyorachorn/Intro-to-IM/blob/b0862f67a54b640df9c8442db31b8cd9b5a48c83/Test_FSR.ino

p5:

I have also started integrating real sensor input, though I am still refining the stability of readings and mapping.

 

Diagram:

Next Steps

For the next stage of development, I plan to:

* Fully integrate all 13 FSR inputs with stable readings
* Improve serial communication between Arduino and p5.js
* Add the arcade switch as a system control (on/off interaction)
* Refine visual feedback to better align with physical key positions
* Shorter components such as resistors to avoid short circuit

 

Reflection

One challenge so far has been managing multiple inputs with limited Arduino pins, which is why the multiplexer became an important part of the design. Another challenge is balancing hardware reliability with software responsiveness.

At the same time, combining Arduino and p5.js has made the project more interesting, since it allows both physical interaction and digital visualization.

 

References:

https://youtu.be/b_MMGJiUcbM?si=z7di2mc-pPGQBt1R

https://youtu.be/XAOo8DEbvck?si=oO7VKZ046IhJgHwh

https://kjh.ypj.mybluehost.me/glossary/triangular-wave/

Fina_Concept

I want to create a calming, meditation like interface where the usdders physical actions are recorded using arduino sensors and shown as the physical states of a bonsai in the p5 sketch. Essentially, the user will be able to take care of the plant through caring for themselves.

Inspiration

My original thought was only to make something that can feel calming, because I have been staying indoors too much lately and that is emotionally frustrating. When I was thinking of exactly how to do it I thought I am not feeling my best because I am inside and not getting enough sunlight, air, and hydration, which is also what plants need to thrive. Its also spring outside, which gives people a sense of life and flourishing growth, making everything feel hopeful. These just clicked and I thought why not use a plant and a growth of a plant to create the calming, meditating effect? I first thought of using a flower but then the blossom of the flower would be like a “win” ending, which is not exactly what I am aiming for. So I looked for some plants related to meditation and found the bonsai, a sort of specially treated plants coming from Japan. Gardenery and taking care of plants in Japan is considered to be a calming process, generating a meditation effect, so I decided to use that as the final design.

Conceptual Interface sketch

(conceptual image generated by gemini)

My current idea is that the user’s breathing or heartrate can be monitored through certain methods. These can be then used to assess stress levels and reflecfted towards the plants growth. If possible I would want the plant itself to move its leaves or wave in sync with the users breath. Watering of the plant can be done by tilting the tilt sensor (like when actually watering plants) or by the user themselves drinking water. I am still deciding between the two ideas.  Light conditions is directly linked to the users light conditions, since staying in a sunlit room is probably more emotionally beneficial to the user than staying in a dark room. Focus might be assessed by fidgiting or other factors, which may include flex or distance sensors, which I havent decided on.

References

https://greengoddess.com/the-zen-of-bonsai-cultivating-tranquility-in-miniature-landscapes/

Google gemini for image genrating.

Tutorials of interest

arduino breathing monitor:

https://www.youtube.com/watch?v=WDRokF_ZW9A

arduino heart rate monitor:

https://www.youtube.com/watch?v=aKus0FV4deU

flex sensor:

https://learn.sparkfun.com/tutorials/flex-sensor-hookup-guide/all

tilt sensor:

https://lastminuteengineers.com/ball-tilt-switch-sensor-arduino-tutorial/

Week 11: Final Project Preliminary Concept

Concept:

For my final project, I want to create an interactive game that smoothly processes between the p5 sketch and Arduino and provides a realistic experience for users. I chose to create an interactive restaurant game/experience where the user is set in a kitchen with multiple sections, such as a food station, desert station, and coffee machine, and gets to choose a section and actually experience creating it as if it were real.

Inspiration:

I actually had multiple inspirations that helped me come up with this idea. Firstly, one of my options for my midterm project was an Emirati kitchen on p5, but I ended up choosing another one, so I thought it would be a good idea to use it for my final project. I also thought of many cooking games I used to play, such as Cooking Mama from my childhood, and Cooking Fever, which is more recent. Then, because I wanted it to feel more realistic, I came up with more interactive ideas.

Vision:

I have a specific vision for my final project that I wish to create if possible. Starting with the p5 sketch, I will have an aesthetic but colorful kitchen setup with around 3 different sections, and in each section there will be animations of the actions the user can perform. On the Arduino side, I would like to create a simple controller, such as arrow buttons or a joystick, to move between selections, and a push button for confirmation. I also want to include an ultrasonic sensor and create kitchen utensils where players can move in front of the sensor to finish the activity. I might also add LED lights of different colors to indicate the state of completion, such as red before starting, yellow during the process, and green when it is done.

References: 

For P5, along with recapping what we learned:

https://youtu.be/b2s8yZ06waQ?si=Su3dHMMqvrrCNXIz  
https://youtu.be/HfvTNIe2IaQ?si=EhtGjs7IjOrHAGLF

For Arduino, along with recapping what we learned:

https://youtu.be/vo7SbVhW3pE?si=ZUV6hNZY7ecwRSva
https://youtu.be/wTfSfhjhAU0?si=So-vFN7DNnjQD3hn
https://youtu.be/a37xWuNJsQI?si=uddzGXgVkkTvSW1k

Week_11_Reading Response

The most interesting idea raised by the article is shifting assistive devices from hiding the disability to embracing design. Glasses were used as an example of a good design that became a fashion trend rather than a clinical tool. But apart from its simple structure and variability in shapes and forms, I would tend to believe that another reason classes is such a success is because nearsightedness is increasingly common, and the variety of design came from the variety of needs. This idea could also insipire designerd to look at what the disabled group actually want for their assistive devices.

The other idea mentioned about not overburdening the device with features relates to one of the other readings in the past weeks about the realationship between mood, design and usability. Keeping the design simple would make it easy and good to use, but would lack emotional function. Adding design to the devices would add emotional support, which would also help bring a more possitive view to disabilities, making it less of a thing to be ashamed of. This would in turn generate more interest in design of diasbility aid and  actively catalyze and inspire broader design culture.

Week 11 – Serial Communication

Repository

Repository

Exercise 1

1. Overview

In this exercise, we explored serial communication between Arduino and p5.js. The main objective was to use a single sensor on Arduino and translate its input into visual movement in p5 — specifically controlling an ellipse moving horizontally across the screen. A potentiometer connected to pin A1 served as the analog input, and no data was sent back from p5 to Arduino, making this a one-directional communication exercise.

2. Concept

The core idea was to establish the simplest possible link between a physical input and a digital visual. By turning a potentiometer, the user directly moves an ellipse across a canvas in the browser in real time. This introduced us to the fundamental pipeline of physical interaction: sensor reads a value, Arduino maps and sends it, p5 receives and translates it into something visible on screen. The simplicity of the setup made it easy to trace the data flow end-to-end and understand what was happening at each stage.

3. Process and Methods
    • We began by following the example demonstrated in class and gradually adapted it to better understand the data flow. On the Arduino side, the potentiometer on pin A1 returns a raw analog value between 0 and 1023. We mapped this to a smaller range of 0–255 using map() before sending it through Serial.println(). This made the value easier to work with on the p5 side without losing meaningful range.
    • For p5.js, we used the p5.webserial library following the structure introduced in class. The serial connection is opened manually through a button, which triggers the browser’s port picker dialog. Inside draw(), port.readUntil(“\n”) reads each incoming line, trim() strips the newline character, and int() converts the string into a usable number. That number is then mapped to the canvas width using map(), which drives the ellipse’s horizontal position. The ellipse stays fixed on the vertical centre of the canvas at all times.
4. Technical Details
    • The Arduino maps the raw potentiometer value before sending it to reduce the range to something the p5 side can easily stretch across the canvas:
// ── READ SENSOR ──
// analogRead returns 0–1023 based on the voltage at A1.
// At 0V (GND side) → 0. At 5V → 1023.
int potentiometer = analogRead(A1);

// ── MAP TO SMALLER RANGE ──
// Compress 0–1023 to 0–255 so p5 can easily map it onto the canvas width.
int mappedPotValue = map(potentiometer, 0, 1023, 0, 255);

// ── SEND TO p5 ──
// Serial.println() sends the number as a string followed by a newline character '\n'.
// p5 uses that newline to know where one value ends and the next begins.
Serial.println(mappedPotValue);
    • On the p5 side, the incoming string is cleaned and converted before being mapped to a screen position:
let str = port.readUntil("\n");

if (str.length > 0) {
  // trim() removes the trailing '\n' (and any spaces).
  // int() converts the cleaned string into a number.
  let val = int(trim(str));

  // ── MAP VALUE TO CANVAS ──
  // Arduino sends 0–255. We stretch that range across
  // the full canvas width so the ellipse covers the
  // entire screen as the pot is turned.
  x = map(val, 0, 255, 0, width);
}
    • This two-step mapping — first on Arduino from 0-1023 to 0-255, then in p5 from 0-255 to 0-canvas width — demonstrates how data can be progressively transformed as it passes between systems.
5. Reflection

This exercise gave us a concrete understanding of how physical input can directly influence digital visuals in real time. The most valuable part was seeing the full pipeline in action: turning the potentiometer caused an immediate, visible response on screen, which made the abstract idea of serial communication feel tangible. It also highlighted the importance of consistent data formatting — the newline character that Serial.println() appends is what makes port.readUntil(“\n”) work reliably on the p5 side. If we were to continue developing this, we would explore using different sensors such as FSR or ultrasonic distance sensors, add smoothing to reduce noise, and expand the visuals to control more than one element.

Exercise 2

1. Overview

In this exercise, we reversed the direction of communication — from p5.js to Arduino. The objective was to control the brightness of a physical LED using mouse movement in the browser. p5 continuously sends a brightness value based on the mouse’s horizontal position, and Arduino uses that value to dim or brighten the LED through PWM. No data is sent back from Arduino to p5.

2. Concept

Where Exercise 1 used hardware to control software, this exercise flipped that relationship. The browser became the controller and the LED became the output. Moving the mouse across the screen is a familiar, intuitive gesture, and seeing that gesture reflected immediately in a physical light made the connection between the two systems feel direct and satisfying. This exercise also introduced us to the handshake pattern, which is necessary when Arduino needs to wait for p5 to be ready before the communication loop can begin.

3. Process and Methods
    • We kept the overall structure close to what was demonstrated in class and simplified the communication to a single value per message. On the p5 side, mouseX is mapped to a range of 0–255 using map() and constrained with constrain() to prevent out-of-range values. This number is sent to Arduino as a string followed by a newline character using port.write().
    • On the Arduino side, the sketch begins with a handshake loop that repeatedly sends “0” and blinks the built-in LED until p5 responds. Once connected, Serial.parseInt() reads the incoming integer from the serial buffer. After confirming the message ends with ‘\n’, analogWrite() applies the value to the LED on pin 5. Because analogWrite() requires a PWM-capable pin, the LED must be connected to one of the pins marked with a tilde (~) on the Arduino board — in our case, pin 5.
4. Technical Details
    • The p5 sketch maps mouse position to brightness and sends it continuously while the port is open:
// ── CALCULATE BRIGHTNESS ──
// Map the mouse's horizontal position across the canvas
// to a brightness value in the range 0–255.
// This matches the range that analogWrite() accepts on Arduino.
let brightness = int(map(mouseX, 0, width, 0, 255));

// ── CONSTRAIN ──
// Clamp the value so it never exceeds 0–255,
// even if the mouse moves outside the canvas.
brightness = constrain(brightness, 0, 255);
// ── SEND TO ARDUINO ──
// Only write if the port is open (i.e., user has connected).
// We append '\n' so Arduino's Serial.read() can detect
// the end of the message after parseInt() runs.
if (port.opened()) {
  port.write(brightness + "\n");
}
    • Arduino reads the value and applies it to the LED:
// ── READ BRIGHTNESS ──
// parseInt() reads digits from the buffer and returns them as an integer. 
// It stops at any non-digit character (including the newline).
int brightness = Serial.parseInt();

// ── CONFIRM COMPLETE MESSAGE ──
// After parseInt(), the next character should be '\n'.
// This confirms we received a full message and not a partial one, preventing corrupted values.
if (Serial.read() == '\n') {

  // ── SET LED BRIGHTNESS ──
  // analogWrite(pin, 0–255) uses PWM to control brightness.
  // 0 = fully off, 255 = fully on, values in between = dimmed.
  analogWrite(ledPin, brightness);
}
    • The ‘\n’ check after parseInt() is important — it confirms that a complete message was received before acting on the value, which prevents the LED from responding to corrupted or partial data.
5. Reflection

This exercise made the communication feel more interactive than Exercise 01, because the browser was no longer just a display — it was actively sending instructions to hardware. The main issue we encountered was that the LED did not dim smoothly at first. After checking the wiring, we found the LED was connected to a non-PWM pin, which meant analogWrite() had no effect. Moving it to pin 5 resolved this immediately. This was a useful reminder that the physical wiring must match the assumptions in the code. If we were to continue, we would replace mouse control with a more interesting interaction such as key presses or dragging, add multiple LEDs with independent brightness values, and eventually expand into bi-directional communication.

Exercise 3

1. Overview

This exercise brought together everything from the previous two by implementing full bi-directional communication between Arduino and p5.js. A joystick connected to Arduino controls the wind force in a physics simulation, while p5 sends a signal back to Arduino to light up an LED every time the ball bounces. Data flows in both directions simultaneously.

2. Concept

The gravity and wind sketch provided a compelling context for bi-directional communication because it has two clearly distinct interactions that naturally map to each side: the joystick controls something in the simulation, and something in the simulation triggers a response on the hardware. Rather than the user controlling a parameter directly, the LED reacts to an event — a bounce — which made the physical and digital feel genuinely connected rather than just linked. Replacing keyboard input with a physical joystick also made the experience more immersive, since it gave the user a tangible way to influence the simulation.

3. Process and Methods
    • We started from the gravity and wind example provided in class and kept the simulation structure mostly unchanged. The main modifications were replacing keyboard-based wind control with joystick input, and adding bounce detection that communicates back to Arduino.
    • On the Arduino side, the joystick’s horizontal axis is read from pin A0 using analogRead() and sent to p5 via Serial.println() after every incoming message. On the p5 side, the value is read with port.readUntil(“\n”), trimmed, converted to an integer, and mapped from 0-1023 to a wind force range of -1 to 1. This value is applied to the wind vector each frame, so tilting the joystick left or right pushes the ball accordingly.
    • For the return signal, we added bounce detection inside draw(). Each frame, a variable bounced is initialised to 0. If the ball hits the floor with a downward velocity greater than 2, it is counted as a real bounce and bounced is set to 1. This value is sent back to Arduino using port.write(). Arduino reads it with Serial.parseInt() and calls digitalWrite() to turn the LED on or off.
4. Technical Details
    • The bounce detection uses a velocity threshold to distinguish real impacts from the small residual movements that occur when the ball settles on the ground:
  // ── BOUNCE DETECTION ──
  let bounced = 0;                    // assume no bounce this frame
  let floorY = height - mass / 2;    // y where ball touches the floor

  if (position.y > floorY) {
    position.y = floorY;   // prevent ball from going below floor

    // ── VELOCITY THRESHOLD ──
    // Only count as a real bounce if the ball hits with enough
    // downward speed (> 2). This filters out the tiny movements when the ball is nearly at rest
    // Would otherwise cause the LED to flicker continuously.
    if (velocity.y > 2) {
      velocity.y *= -0.9;   // reverse and reduce (energy loss on impact)
      bounced = 1;           // signal a real bounce to Arduino
    } else {
      velocity.y = 0;        // ball has come to rest — stop it completely
    }
  }

  // ── SEND BOUNCE STATE TO ARDUINO ──
  // Sends 1 if a real bounce happened this frame, 0 otherwise.
  // Arduino uses this to briefly light the LED on each bounce.
  // '\n' is appended so Arduino can confirm end of message.
  if (port.opened()) {
    port.write(bounced + "\n");
  }
}
    • On the Arduino side, the received state is applied directly to the LED:
// ── READ LED STATE FROM p5 ──
// p5 sends '1' when a bounce is detected, '0' otherwise.
// parseInt() extracts the integer from the incoming string.
int ledState = Serial.parseInt();

// ── CONFIRM COMPLETE MESSAGE ──
// Check for the newline that p5 appends with port.write().
// This prevents acting on partial or corrupted values.
if (Serial.read() == '\n') {

  // ── CONTROL LED ──
  // ledState is 1 (HIGH) when p5 detects a bounce → LED on.
  // ledState is 0 (LOW) otherwise → LED off.
  digitalWrite(ledPin, ledState);
}
    • The joystick read and send happens inside the same while (Serial.available()) block, directly after the LED state is processed. This keeps the two directions of communication tightly coupled within each communication cycle.
5. Reflection

This was the most technically demanding exercise of the three, and also the most rewarding. The biggest challenge was the LED flickering continuously when the ball came to rest on the ground. Even though the ball appeared stationary, the physics simulation kept generating tiny downward movements due to gravity, which the system kept interpreting as bounces. Introducing the velocity threshold velocity.y > 2 solved this cleanly and also taught us something broader: physics simulations produce continuous, noisy output, and meaningful events often need an explicit threshold or condition to be extracted from that noise. If we were to continue, we would add a dead zone to the joystick centre to reduce drift, use both joystick axes for more complex motion, and add more LEDs to represent different simulation events.

6. Resources

Week 11 — Reading Response

What struck me most about Pullin’s argument is the way he reframes concealment — not as a neutral design default, but as a value judgment quietly embedded in every flesh-toned hearing aid and skin-matching prosthetic. I’d always assumed that “discreet” design for disability was simply considerate, a way of respecting the user’s desire to blend in. Pullin destabilizes that assumption by asking who decided blending in was the goal in the first place. The eyeglasses example is effective precisely because it’s already resolved: nobody today apologizes for visible frames or tinted lenses, and the question of why hearing aids can’t occupy the same cultural space is genuinely difficult to answer without exposing some discomfort about how disability is perceived. What this raises for me is whether the concealment instinct in design is a response to user needs or a projection of the designer’s own unease — and whether those two things are even distinguishable in practice. If a designer has never lived with a hearing aid, their intuition about “what users want” is shaped by imagining the stigma from the outside, which may be a very different thing from what someone actually navigating that stigma would choose.
The tension I keep returning to is the one between designing for expression and designing for choice — and I’m not sure Pullin fully resolves it. His most compelling cases, like Aimee Mullins’ carved wooden legs, work because they belong to a specific person with a specific relationship to visibility and performance. But what interests me is the middle ground he gestures at: the user who neither wants to pass as non-disabled nor be conscripted into a narrative of disability-as-spectacle they didn’t ask for. That unresolved space feels like the honest core of the book, and it connects for me to broader questions in interaction design about whether personalization is a solution or a way of deferring a harder design decision. Giving users options is good, but the options still frame what’s possible — and right now, as Pullin shows, the frame has been set almost entirely by clinical priorities and the discomfort of people who aren’t disabled. That framing shapes perception in ways I hadn’t fully considered before reading this.

Week_11_Assignment

Schematics

Video Demo

P5 code

https://editor.p5js.org/JingyiChen/sketches/8ggtbgHZV

I made changes to the code to include the serial communication components and also adjust the LED logic slightly so it would fit the bounce better. The code for serial communication was all adapted from the week 11 example 2 bidirectional communication example.

//original bounce code, but it doesnt work well if I put the ledState deciding if else in here.
if (position.y > height - mass / 2) {
  velocity.y *= -0.9; // A little dampening when hitting the bottom
  position.y = height - mass / 2;
}
//so I added another if statement to individually decide whether the LED should light up according to ball y position
//first line creats a 15 pixel range near the bottom line for the led to light up, to prevent the glitch like blinks that would happen with the original bounce code.
if (position.y > height - mass / 2 - 15) {
  // Use the absolute of the velosity so the ball triggers the LED on both the way down and up
  if (abs(velocity.y) > 2) {
    ledState = 1;
  } else {
    ledState = 0;
  }
} else {
  //if the ball is not within the 15 pixel range
  ledState = 0;
}

This code snippet is where I added some logic to make the LED poerform more in sync with the bounce. Originally I added the ledStae changee directly to if (position.y > height – mass / 2){}, which resulted in a bit of a glitchy looking blink, which I think might have to do with the very small time frame on the on signal and the time it takes for the information to be communicated between p5 and arduino. So I added another if statement to have the LED turn on when the ball is in a 15 pixel range above the bottom line, and also checked the velocity so the led does not stay on when the ball is barely bouncing or stationary. This make the led a lot more stable and light up correctly every bounce.

Arduino code

https://github.com/JingyiChen-jc12771/Intro-to-IM/blob/8f5bdbc0282acbce4a7edea2334f1305c493216c/W11_01_serial_simple_potentiometer.ino

The arduino code is also adapted from the week 11 example 2 bidirectional communication example. I changes the code very slightly so it would reflect the wiring of having only one input from the potentialmeter.

Difficulties and areas for improvemment

The biggest difficulty was the glitchy blink when I added blink code to the original code. I spend some time trying to figure out why but because I couldnt find anything wrong with the p5 or arduino code I had to guess it was timing differences. It would have been better if I had been able to uncover the root cause of the problem and figured out how to solve it in the original code.

 

 

Week 11 – Serial Communication

Exercise 1

Demo:

Schematic:

Implementation:

  • Arduino
    • I began by setting up a simple circuit with an ultrasonic sensor to control the circle’s position in p5 using my hand’s distance from the sensor.
    • For the code, I used the same distance calculating code I used in one of my previous assignments that used the ultrasonic sensor. The only thing I changed is
      void loop(){
      //...
        Serial.println(mappedDistance);
      //...
      }

      where I used println instead of just print, so that a new line is printed with every write to the serial monitor.

  • p5:
    • I used the same connection logic from the class example using the “click to connect” button. Then, I read from the serial monitor and convert the string it reads into a value. Then, I draw the ellipse and insert the x-value we read from Arduino into its appropriate place in the parameters.

Exercise 2

Demo:

Schematic:

Implementation:

For this exercise, I used a slider on p5 to control the brightness of an LED on my Arduino.

  • Arduino:
    • I started by setting up a simple circuit with one LED light connected to pin 9
    • For the code, it reads the incoming values from p5, then it constrains the incoming value to be between 0-255 to match the values for brightness, and then it analogWrites the value to the LED.
  • p5:
    • I used the createSlider() function to create a simple slider that controls the LED’s brightness. The slider ranges from 0-255 and by default sets to 127, the halfway point.
    • I, again, used the connect button logic to prompt the browser to connect to the Arduino
    • In the draw function, the slider’s value is read. If the port is open and the connection is established with the Arduino, then p5 sends the slider’s value as a string followed by a newline character “\n” so Arduino knows when a full value has arrived. It also displays the “Disconnect” text on the button if the port is open. If the port is closed, it shows “Connect to Arduino” on the button. The current brightness value is also displayed as text on the canvas

Exercise 3

Demo:

Schematic:

Implementation:

  • Arduino
    • For my circuit, I connected a potentiometer and an LED light to pins on the Arduino
    • For the code, it can be divided into two main sections: sending information from the potentiometer to p5 and receiving information from p5 for the LED
      1. Potentiometer:
        • It reads the potentiometer’s value
        • It maps it from 0-1023 to -100-100 and divides my 100.0 to get a float value. This gives us a good range for the wind variable in the p5 sketch (-1 to 1)
        • It prints the mapped value to the serial monitor using println() to send the data to p5
      2. LED:
        • It checks if data has been received and reads it
        • If the data reads ‘H’ for HIGH, then it turns on the LED, else if it’s ‘L’ for LOW then it turns off the LED
  • p5:
    • For the wind, it reads the value through the port from Arduino and just sets the wind’s x value to the pot’s value
    • For the ball, when it hits the bottom of the screen it sends an ‘H’ to Arduino to signal the LED to turn on, and when the ball is in the air it sends an ‘L’ to signal the LED to turn off.

Reflection

Due to the nature of the tasks and their specific requirements, I found it a bit difficult to get creative with my ideas for each exercise; however, they were an excellent way to familiarize myself deeply with serial communication and test my knowledge.

Arduino/P5 Exercises

https://drive.google.com/drive/folders/17BOPjKsdqArQirTPjNIaXM87Vg7DWi_E?usp=sharing

Exercise 1: change horizontal position of ellipse

https://github.com/da3755-ui/intro-to-im/blob/4715fd118fa2091c8d727f6e3131c1cfebcfeccd/p5_to_ardunio_example1.ino

references:

https://stackoverflow.com/questions/1133770/how-can-i-convert-a-string-to-an-integer-in-javascript

Exercise 2: control led brightness from p5

https://github.com/da3755-ui/intro-to-im/blob/4274788ff7e0d80f2de29f5b4b86e653817c0fcc/P5_arduino_exercise2.ino

Exercise 3: bidirectional

https://github.com/da3755-ui/intro-to-im/blob/b749d30cee9ae91995d3ad61607f140d6e2135fd/P5_AND_ARDUINO_EX3.ino