Week 11 – Serial Communication

Exercise 1

Demo:

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.js:
    • 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:

Implementation:

For this exercise, I decided to use 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

 

Leave a Reply