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.


1 photoresistor

1 resistor (330 Ohms)

1 resistor (1k Ohms)


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




* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <>
* 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() {
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
analogWrite(motorPin, abs(255-average*2.8)); // analogWrite can be between 0-255
delay(5); // delay in between reads for stability


20161012_024130 20161012_012119

Leave a Reply