ucsd-creative-robotics

Week 3 - Sensors and Sensations

Agenda

Artist(s) of the Day


image

Amy Youngs


Inmi Lee


Lillian Schwartz Pixillation

To make her first film, the four-minute “Pixillation” (1970), for example — a project that took two months — she fed punch cards into an IBM 7094 mainframe computer to produce 85 black-and-white frames on magnetic tape.

Proxima Centari 1968-1969

In 1968, her kinetic sculpture “Proxima Centauri” appeared in a landmark show at the Museum of Modern Art in New York titled “The Machine as Seen at the End of the Mechanical Age,” curated by Pontus Hulten. The piece included discarded street lamp domes and the motor from a sewing machine that Ms. Schwartz had inherited from her mother.

The Times later described a version of the piece, which was in her home, as “a big black cabinet with a plastic dome inserted in the top, with a color sequence running beneath the dome’s surface. When anyone stands close to the cabinet, the dome starts to withdraw and slowly drops out of sight.”

(from nytimes bio + obit)

Lillian Schwartz is a pioneer of computer-generated art. From 1969-2002, she was a “resident visitor” at Bell Laboratories, producing groundbreaking films, videos, and multimedia works. The Schwartz Collection spans Lillian’s childhood into her late career, documenting an expansive mindset, mastery over traditional and experimental mediums alike–and above all–an ability to create inspirational connections between science, art, and technology.

(from The Henry Ford)

Basic Sensing

(Digital and Analog Input)

Digital Input

Pushbuttons on the Dev Board

esp32 diagram showing pinouts and function

The ESP32 Dev Board has onboard buttons attached to pins 12 and 13. You can read these as digital inputs.

The following is based on the Files->Examples->02.Digital->Button example. We need to modify the pinouts to match our dev board:

/*
  Button

  Turns on and off a built-in light emitting diode(LED) connected to digital pin 17,
  when pressing a built-in button attached to digital pin 12.

  Based on code DojoDave <http://www.0j0.org>
  modified by Tom Igoe

  https://docs.arduino.cc/built-in-examples/digital/Button/
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 12;  // the number for one of the built-in buttons
const int ledPin = 17;    // the number for one of the built-in LEDs

// variables will change:
int buttonState = 0;  // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Download: esp32-button.zip

This wil turn the LED on and off when you hold the button.

Exercise:

Analog Input

Image

https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput

On the ESP32 dev board, pins 1-10 and 11-18 function as analog inputs. We need to use those pins for our analog in.

/*
  Analog Input

  Demonstrates analog input by reading an analog sensor on analog pin 0 and
  turning on and off a built-in light emitting diode(LED) connected to 
  digital pin 17. The amount of time the LED will be on and off depends on 
  the value obtained by analogRead().

  The circuit:
  - potentiometer
    center pin of the potentiometer to pin 1 (analog inputs on  1-10, 11-18)
    one side pin (either one) to ground
    the other side pin to +5V

  created by David Cuartielles modified By Tom Igoe
  https://docs.arduino.cc/built-in-examples/analog/AnalogInput/
*/

int sensorPin = 1;   // select the input pin for the potentiometer
int ledPin = 17;      // select the pin for the LED (built-in LED)
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
}

Download: esp32-analog-in.zip

Photoresistor Part 1

https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput

Advanced Sensors

Thermistors

LAST TIME WE DID THIS!

image

Ultrasonic Rangefinder

image

NOTE❗❗: Change the line that initializes the sensor to use pins 11 and 10 from:

UltraSonicDistanceSensor distanceSensor(13, 12);  // Initialize sensor that uses digital pins 13 and 12.

to

UltraSonicDistanceSensor distanceSensor(11, 10);  // Initialize sensor that uses digital pins 11 and 10.

(shown in the diagram above)

HC SR04 Timing Diagram alt text alt text

#include <HCSR04.h>

const byte triggerPin = 11;
const byte echoPin = 10;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);

void setup () {
    Serial.begin(115200);  // We initialize serial connection so that we could print values from sensor.
    Serial.println("Hello...");
}

void loop () {
    // Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters.
    Serial.println(distanceSensor.measureDistanceCm());
    delay(500);
}

Download: esp32-ultrasonic.zip

Gotcha: USB CDC ON BOOT

Be sure you have enable USB CDC ON BOOT: Enabled. See the Getting Started with the Dev Board tutorial.

Beliefs and Desires

Homework

References