Resistor! A difficult interaction

Like last week, my goal for this assignment was to create an affective robot–in this case, one that would challenge you when you try to work on it, put it away, or turn it off. Originally I hoped to enclose the whole assembly in a wire-frame ball, so that once turned on it would roll around and be tedious or difficult to turn off. Instead, I created a little bot that just protects itself with a spinning wire. It is afraid of the dark, and so if one tries to cover it with a lid, it will spin wildly, but calm down once again in the light of day.

Materials:

1 photoresistor

1 resistor (330 Ohms)

1 resistor (1k Ohms)

wires

two AA battery holders, one x4 and one x2

1 Arduino uno

1 DC motor

1 diode

1 transistor

soldering iron and solder

1 machine screw

welder…

 

Code:

/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/

const int numReadings = 5;

int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
};
}

void loop() {
// subtract the last reading:
total = total – readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;

// if we’re at the end of the array…
if (readIndex >= numReadings) {
// …wrap around to the beginning:
readIndex = 0;
}

// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(250-average*2.8);
analogWrite(motorPin, abs(255-average*2.8)); // analogWrite can be between 0-255
delay(5); // delay in between reads for stability
}

Video:

https://youtu.be/p5WXQyZC0DY

20161012_024130 20161012_012119

The Moire Effect

Description
With use of a motor and images that have a subtle sense of alignment, I tried to create a lamp that has a Moire effect as it rotates. The motion effect would change depending on the speed. I had also designed the patterns to recreate the effect.

Components

  • Arduino Uno
  • DC Motor
  • Design of static Moire patterns
  • Transistor TIP120
  • Semiconductor 1N4004
  • Jumper wires
  • Potentiometer
  • 1k Ohm Resistor

/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */

int potPin = A0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

img_20161011_234255

Panda Massage Pad

Description

I created a panda massage pad using dc motor, FSR, and Arduino.

Components

  • 1 Arduino
  • 1 DC Motor
  • 1 Transistor
  • 1 Battery
  • 2 Resistors
  • 1 Breadboard

Code

int potPin = A0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
 Serial.begin(9600);
}
void loop() {
 val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
 Serial.println(val);
 analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

Lab 06

Description

I used Arduino with a DC motor. I followed the lab instruction and set up the Arduino with a DC motor. I used the sample code provided in the lab to make Arduino interact with the DC motor. I also made a paper wind mill and attached it to the DC motor. Lastly, I  uploaded the code and took pictures of the result.

Components

  • 1 Arduino
  • 1 DC Motor
  • 1 Breadboard
  • 1 batery case
  • 1 paper wind mill
  • 1 Transistor
  • 1Diode
  • 2 Batteries

Code:

/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave &lt;http://www.0j0.org&gt;
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */

int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}
 

Displaying IMAG1164_BURST002.jpg

Pencil sharpener

Description

I attached a pencil to the rotating end of my DC motor and held the other end of the pencil inside a pencil sharpener. When I turn this setup on, the pencil rotates rapidly inside the sharpener and subsequently sharpens the lead.

Components

Arduino Board
Bread board
DC motor
Wires
Batteries
Pencil
Sharpener


int potPin = 0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

img_20161011_210850

Spinning thread spool

Description

Uses a DC motor to spin a thread spool to put the thread on it. A pot can be used to adjust the speed of the spinning, similar to how someone would use a foot pedal of a sewing machine to adjust the speed of the thread spinning.

Parts

  • 1 pot
  • 1 transistor
  • 1 diode
  • 1 DC motor
  • 1k ohm resistor
  • Arduino uno
  • 3V battery
  • Spool

Code

/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave &lt;http://www.0j0.org&gt;
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */<strong>
</strong>
int potPin = A0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
 Serial.begin(9600);
}
void loop() {
 val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
 Serial.println(val);
 analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

<img class="alignnone size-medium wp-image-1739" src="http://blogs.ischool.berkeley.edu/i262/files/2016/10/IMG_7426-300x225.jpg" alt="img_7426" width="300" height="225" />

Rotating Pinwheel

For this lab, I built a pinwheel powered by the dc motor. While making the pinwheel wasn’t very hard, a lot of thought and effort went into controlling its stability and speed on the motor’s spindle. After a very few spins, the spindle makes the hole in the pinwheel bigger causing the pinwheel paper to lose contact with the motor which further results in loss of control over the motion of the pinwheel and the speed.

To circumvent the problem, I used a twist tie to harness the motion of the spindle and transfer it onto the pinwheel. The arrangement is depicted in the photo attached. I then hosted the pinwheel and motor on a candy holder to allow for the pinwheel to get enough space to spin. I also placed a sticker on the top of the spindle hole to prevent the paper pinwheel from flying away.

img_20161009_230825https://drive.google.com/a/berkeley.edu/file/d/0ByHw8c_nutT2LU9EcGRNMWR2b28/view?usp=sharing

Code:

/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/

int potPin = 0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 – 1024
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

Sunny Doll + Weather Art Dashboard

For this assignment, I have connected to a weather API that would return the temperature of the city I’m searching for. I’ve made a list of cities in a list and a for loop that would request temperature for the cities every few seconds. The motor is attached to the sunny doll, however, my motor is currently broken so I can’t show the video here. I’ve attached the picture of sunny doll though. The concept is that if a city is hot the motor will spin the doll faster and spin it slower if it’s colder. Sunny doll is a popular item in Japan that people hang on the brink of their roof as a prayer of good weather.

I’ve also connected arduino with processing that would make sine waves of warm/cool color based on the temperature. I’ve attached the video link as below.

Weather Art Dashboard Youtube Video

Sunny Doll Made with Napkin…Will have face by tomorrow
img_0970

Python Code


import pyowm
import time
import serial
# Code to add widgets will go here...

#setting up serial communication
ser = serial.Serial('/dev/cu.usbmodem1411', 9600)
#creating pyowm object
owm = pyowm.OWM(API_key='37ec6df9d804fe26229ccf5d4bfb9a28')
#get address
while True:
    cityID = [(4570707, 'Berkeley'), (3602359, 'Sandy Bay'), (285570, 'Kuwait'), (2205218,'Fiji'), (1259110,'Qadian'), (6362039,'Montesa'),
    (2514896,'Lopera'), (1668341, 'Taipei'), (4930956,'Boston'), (2643743, 'London'),
    (1850147, 'Tokyo'), (734198,'Sokhos'), (5128638, 'New York'), (192950, 'Kenya'),
    (5861900, 'Fairbanks'), (1822029, 'Stoeng Treng'), (2656877, 'Astley'), (3345279, 'Price Town'),
    (256606, 'Nea Kios')]

    cityName = ['Berkeley', 'Sandy Bay', 'Kuwait', 'Fiji', 'Qadian', 'Montesa',
    'Lopera', 'Taipei', 'Boston', 'London',
    'Tokyo', 'Sokhos', 'New York', 'Kenya', 'Fairbanks', 'Stoeng Treng',
    'Astley', 'Price Town', 'Nea Kios']

    for city in cityID:
        observation = owm.weather_at_id(city[0])
        print("city: " + str(city[1]))
        w = observation.get_weather()
        temp = w.get_temperature('celsius')
        temp = temp['temp']
        print temp
        if int(temp) >= 20:
            print 'HOT'
            ser.write(b'' + str(255) + str(city[1]))
        elif int(temp) < 20 & int(temp) >= 10:
            print 'Meh'
            ser.write(b'' + str(120)+ str(city[1]))
        elif int(temp) < 10:
            print 'COLD'
            ser.write(b'' + str(80)+ str(city[1]))
        time.sleep(1)

Arduino Code


/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */
float data;
int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
String str = "";

void setup() {
  Serial.begin(9600);
}
void loop() {
//  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
//  Serial.println(val);
//  analogWrite(motorPin, val); // analogWrite can be between 0-255
  if(Serial.available() > 0) {
    data = Serial.parseFloat();
    Serial.println(data);
    analogWrite(motorPin, data); // analogWrite can be between 0-255
  }
}

Processing Code


import processing.serial.*;
Serial port;
String portname = "/dev/cu.usbmodem1411";
int SerialVal = 0;
String myString = null;
int xspacing = 16;   // How far apart should each horizontal location be spaced
int w;              // Width of entire wave
int r = 255;
int warmIncrement = 0;
int coldIncrement = 0;
int g = 255;
int b = 255;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
float theta = 0.0;  // Start angle at 0
float amplitude = 500.0;  // Height of wave
float period = 500.0;  // How many pixels before the wave repeats
float dx;  // Value for incrementing X, a function of period and xspacing
float[] yvalues;  // Using an array to store height values for the wave
String[] cityName = {"Berkeley", "Sandy Bay", "Kuwait", "Fiji", "Qadian", "Montesa", 
  "Lopera", "Taipei", "Boston", "London", "Tokyo", "Sokhos", "New York", "Kenya",
  "Fairbanks", "Stoeng Treng", "Astley", "Price Town", "Nea Kios"};
int cityIndex = 0;

void setup() {
  size(1300, 800);
  w = width+16;
  dx = (TWO_PI / period) * xspacing;
  yvalues = new float[w/xspacing];
  
 port = new Serial(this, portname, 9600);
 port.bufferUntil('\n');
}

void draw() {
 while (port.available() > 0) {
   myString = port.readStringUntil(lf);
   if (myString != null) {
     print(myString);  // Prints String
     SerialVal = int(myString);  // Converts and prints float
     if (SerialVal == 255) {
       //textSize(100);
       //fill(190, 190, 190);
       //text(cityName[cityIndex], 500, 400);
       //cityIndex += 1; 
       r = 255;
       g = 50 + warmIncrement;
       b = 0 + warmIncrement;
       warmIncrement += 50;
       if (warmIncrement > 255){
         warmIncrement = 0;
       }
     } else if (SerialVal == 120) {
       //textSize(100);
       //fill(190, 190, 190);
       //text(cityName[cityIndex], 500, 400);
       //cityIndex += 1; 
       r = 190;
       g = 190;
       b = 190;
     } else {
       //textSize(100);
       //fill(190, 190, 190);
       //text(cityName[cityIndex], 500, 400);
       //cityIndex += 1; 
       r = 0 + coldIncrement;
       g = 180 + coldIncrement;
       b = 255;
       coldIncrement += 50;
       if (coldIncrement > 255){
         coldIncrement = 0;
       }
     }
     println("val="+SerialVal);
   }
 }
 calcWave();
 renderWave();
}

void calcWave() {
  // Increment theta (try different values for 'angular velocity' here
  theta += 0.02;
  // For every x value, calculate a y value with sine function
  float x = theta;
  for (int i = 0; i < yvalues.length; i++) {
    yvalues[i] = sin(x)*amplitude;
    x+=dx;
  }
}

void renderWave() {
  noStroke();
  fill(r, g, b);
  // A simple way to draw the wave with an ellipse at each location
  for (int x = 0; x < yvalues.length; x++) {
    ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
  }
}

Bow – wow water!

Components:

  • 1x 10KΩ resistor
  • 2 nails
  • 1 DC motor
  • 2x AA batteries
  • Battery holder
  • Wire
  • Jumper wires
  • USB cable
  • Computer
  • Arduino Uno
  • Breadboard
  • Cardboard, pieces of wood, hot glue gun, cork

Description

For this week’s project I made a dog that will let me know when my plants need water.

When the soil is dry, Pantufla (the dog), will alert me by moving her tail, and moving. Once the soil gets wet, she will stop moving. To detect the level of the moisture I made a very low fidelity sensor using two nails.

Code

int sensorPin = A0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
int sensibility=600;

void setup() {
Serial.begin(9600);
pinMode(motorPin, OUTPUT);   // sets the pin as output
Serial.println(“Welcome to the Bow wow water project”);
}

void loop() {
val = analogRead(sensorPin);    // read the value from the sensor, between 0 – 1024
Serial.println(val);
if (val <= sensibility){
analogWrite(motorPin, 0); // analogWrite can be between 0-255
}
else
{
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}
}

20161011_193140

Failed spiral

For this lab, I wanted to create an optical illusion through the movement of the DC motor. I stuck a round shaped piece of stiff paper and tried out several designs. What I wanted was an outward moving spiral and I think my design is right because I can kind of see it when the motor is turning off but otherwise, the motor spins too fast for the effect to be visible to the naked eye. I settled with a design which too demonstrates how perception works and what we see may not be what is.

Components

  • Arduino Uno
  • breadboard
  • 1 DC motor
  • 1 Transistor
  • 1 Diode
  • 1 resistors (one 1KΩ)
  • 1 potentiometer
  • battery pack
  • two AA batteries
  • jumper wires

Arduino Code

/*
* one pot fades one motor and LED
*/

int potPin = A0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val; // variable to store the value coming from the sensor
void setup() {
pinMode (potPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 – 1024
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

photo-on-10-11-16-at-7-08-pm-2