Category Archives: Week 6

Sunglasses

I made some sunglasses that are super useful for when you need protection from bright lights but also need to be able to look down and take notes with clear vision.

I forgot to take photos for documentation though, so I made this video to make up for it.

 

Here is my code: I got parts of it from the arduino and sparkfun tutorials on accelerometers and servos.

 

#include <Wire.h>
#include <SFE_MMA8452Q.h>
#include <Servo.h>

MMA8452Q accel;
Servo right;
Servo left;

int posSL = 0;
int posSR = 180;

void setup()
{
//myservo.attach(10);
right.attach(9);
left.attach(10);

Serial.begin(9600);
accel.init();
}

void loop()
{
if (accel.available())
{

accel.read();

Serial.println(accel.cx);
if (accel.cx >= 0) {
posSR = 180;
posSL = 0;
} else if (accel.cx < 0) {
posSR = 0;
posSL = 180;
}

right.write(posSR);
left.write(posSL);
}
}

HAOTIAN_HOMEWORK

I make a fortune cat by using a servo and a pressure sensor. The fortune cat waves his hand to gather good luck and fortune. If you press his right hand, he will moves his hand faster.IMG_3141 IMG_3144

 

Code_________________________________________

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

int sensorPin = 0;
int pre = 0;
int val = 0;

void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
pre = analogRead(sensorPin);
val = map(pre,0,500,1,10);

for(pos = 30; pos < 160; pos += val) // goes from 30 degrees to 160 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 160; pos>=30; pos-=val) // goes from 160 degrees to 30 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
Serial.println(val);
}

EgoBot

1

So this thing has an ego problem (or maybe its just shy). It looks away each time you get real close to it.

Code:

#define trigPin 10
#define echoPin 11
#include <Servo.h>

Servo myservo;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(9);

randomSeed(analogRead(0));
}

void loop() {
int duration, distance,pos=0,i;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println(” cm”);
if(distance<15)
{
myservo.write(random(0,180));
//Serial.print(distance);
//Serial.println(” cm”);
}
delay(100);
}

LUOBIN_HOMEWORK

The goal is to make a rain wiper for a glass. Whenever it detects rain, it starts wiping. This project uses water sensor, servo motor and an Arduino. Didn’t find any rubber to imitate the wiper on the windshield on a car, so instead I used a piece of transparent plastic. What to be improved is, the water doesn’t vanish because of the plastic is too loose to touch the glasses surface. This will be improved in next phase.

I saw this after doing the project..:

http://notedelhotel.blogspot.com/2009/09/someone-already-did-it-windshield-wiper.html
http://notedelhotel.blogspot.com/2009/09/someone-already-did-it-windshield-wiper.html

code____________________

//by peterobbin

//courtesy to:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

Servo wiper;
int waterPin = 1;
int waterValue = 0;
int servoPin = 2;
int pos = 90;

void setup()
{
wiper.attach(servoPin);
Serial.begin(9600);
}

void loop(){
waterValue = analogRead(waterPin);
Serial.println(waterValue);
//float servoW = map(waterValue, 0, 1024, 0, 179);
delay(100);
if (waterValue > 400 && waterValue < 650){
swipeSlow();
}
else if(waterValue >= 650){
swipeFast();
}
//swipeSlow();
}

void swipeSlow(){

for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
wiper.write(pos); // tell servo to go to position in variable ‘pos’
delay(10); // waits 15ms for the servo to reach the position
}

for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
wiper.write(pos); // tell servo to go to position in variable ‘pos’
delay(10); // waits 15ms for the servo to reach the position
}
}

void swipeFast(){

for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
wiper.write(pos); // tell servo to go to position in variable ‘pos’
delay(5); // waits 15ms for the servo to reach the position
}
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
wiper.write(pos); // tell servo to go to position in variable ‘pos’
delay(5); // waits 15ms for the servo to reach the position
}
}

eyeMask

My originally idea was to make a eye mask for my trip in airplane or train. When I nearly finished my wife suddenly found it was very suitable for me when I sat on the beach. So it gave me inspiration.

We made the lens as heart shape.  If I laid down the mask would be on. So I could hide myself from the sunshine. If I sat up the mask would be off. So it wouldn’t bother me for enjoying bikini girls ;-D

IMG_1337 IMG_1336

The code is here,

 

#include <Servo.h>

Servo myservo;

int switchPin = 3; // tilt sensor input to 3
int val; // the tilt value, 0 or 1

void setup()
{
myservo.attach(9);
pinMode(switchPin, INPUT);
Serial.begin(9600);
}

void loop()
{
val = digitalRead(switchPin);
Serial.println(val);

if (val == 1){
myservo.write(90);
delay(15);
}
if (val == 0){
myservo.write(180);
}
}

 

The Spinning Bow Tie

I created this spinning bow tie that will spins when there is someone near you using the servo and a motion sensor. The motion sensor goes at the back, while the bow tie at the front so that if there’s someone who walks up to you from behind, the bow tie will start to spin. The trouble is that the sensor is too sensitive and it picks up motion unless you’re sitting absolutely still.

Used my mug since it was tricky trying to shoot a decent selfie shot.

Continue reading The Spinning Bow Tie

HW_WEEK6_Qianjing_Liu

Photo on 10-2-14 at 23.15

I’ve made an indicator which can move when people revolve the knob. And with the movement of the indicator, 2 leds will be turned on. If the indicator moved in 120 degree, the green one will be brighter and brighter, but it will turned off if the indicator moved more than 120 degrees. After the green one turned off, the right one will be on and show the dangerous. I am trying to get some connection between this one with the speed of the car.

 

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
int led1 = 6;
int led2 = 5;
Servo myservo; // create servo object to control a servo
int sensor = A0;// a maximum of eight servo objects can be created
int brightness;
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9);
Serial.begin(9600);
pinMode(sensor, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT); // attaches the servo on pin 9 to the servo object
}

void loop()
{
pos = map (analogRead(sensor),0,1023,0,180);
myservo.write(pos);
if(pos>=60){
brightness= map(pos,60,180,255,0);
analogWrite(led1, brightness);
analogWrite(led2,LOW);
}else{
brightness= map(pos,0,60,255,0);
analogWrite(led2,brightness);
analogWrite(led1, LOW);
}
Serial.println(pos);
}

Weeks 4-6: Piezo Buzzer and Servo Motor w/ Sensors

Octi
Reactive Octi
Based on the pressure or flex applied to the embedded sensors in Octi’s arms, his eyes rotate to make him look either sad or mad.
#include <Servo.h>
Servo myservo;
int servo = 7;
int piezo = 8;
int pressure = A0;
int servo_pos = 0;
int current_pressure = 0;
int current_note = 200;
int current_spin = 1;
void setup() {
  // put your setup code here, to run once:
  pinMode(servo, OUTPUT);
  pinMode(piezo, OUTPUT);
  pinMode(pressure, INPUT);
  myservo.attach(servo);
  Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
  current_pressure = analogRead(pressure);
  Serial.print(current_pressure);
  Serial.print(” “);
  current_note = map(current_pressure, 0, 1024, 200, 2000);
  Serial.print(current_note);
  Serial.print(” “);
  current_spin = map(current_pressure, 0, 1024, 1, 20);
  Serial.println(current_spin);
  tone(piezo, current_note);
  myservo.write(servo_pos);
  servo_pos += 1*current_spin;
}