dimanche 9 décembre 2012

Moonlight Mobile


The purpose of this project was to create a mobile that would distract and become the source of comfort that a baby is seeking when waking up in his crib, at a time where the parent should not step in to comfort him.

Its first purpose was to be interactive and responsive to the baby's screams. The idea was dropped due to conceptual conflicts: a baby could be conditioned to understand that crying meant making the mobile move. Having only a basic knowledge of electronics, I decided to make the mobile static for the moment so that it doesn't interactively responds to the child at the moment.


 





(I apologize for the lack of pictures. The pole of the mobile broke down and it damaged a few components.)

_____

My first inspiration came from the idea that parents should not step inside the room whenever their baby is crying even when they want to. I wanted to create something that would be relaxing for the baby if/when he woke up that would calm him down.

I was looking through mobiles for kids on Google and liked the DIY ideas. Since it was a project I had to build myself, I browsed through a lot of DIY websites such as this one to find ideas.

_____

Feedback during the presentation on december 6th include distracting colours such as the red pole and dangling stars. It was also suggested to develop the 'responsive' part of the mobile, perhaps by having a plastic controller for the kid to play with himself, which would make the mobile turn and light up.
_____

Here was the code I used to control the motor as well as control the RGB lights.
#include <Servo.h>
Servo myservo;
int pos = 0;    // variable to store the servo position

#define MOTOR_P 3

#define GREEN 9
#define RED 10
#define BLUE 11

int lightpos = 0; //position action of the light
int red = 255;
int blue = 255;
int green = 255;

int moveRed = 128;
int moveBlue = 128;
int moveGreen = 128;

#define MOTOR_MIN 50
#define MOTOR_MAX 180

boolean motorMotion = false; //false = move left to right, true = move right to left
int motorPos = MOTOR_MIN;

void setup()
{
  Serial.begin(9600);
  pinMode(12, INPUT); // set pin 12 for input
  pinMode(9, OUTPUT); // set pin 12 for input
  pinMode(10, OUTPUT); // set pin 12 for input
  pinMode(11, OUTPUT); // set pin 12 for input
 
    myservo.attach(MOTOR_P);
    myservo.write(90);

//  pinMode(MOTOR_P, OUTPUT);
//  pinMode(MOTOR_M, OUTPUT);
 
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);

}

void loop()
{
  if (digitalRead(12) == LOW) // pin 12 is connected to gnd
  {
    delay(50);
  
    //digitalWrite(3,LOW);
  
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
  }
  else // pin 12 is not connected to gnd
  {
    Serial.println("active");
    //digitalWrite(3,LOW);

    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
 
    tickColor();
    moveMotor();
    delay(15);
  }
}

void moveMotor() {
 
    if(motorMotion==false)
    {
      if(motorPos < MOTOR_MAX)
      {
        motorPos += 1;
      }
      else
      {
        motorMotion=true;
        motorPos -= 1;
      }
    }
    else
    {
      if(motorPos > MOTOR_MIN)
      {
        motorPos -= 1;
      }
      else
      {
        motorMotion=false;
        motorPos += 1;
      }
    }
  
    myservo.write(motorPos);              // tell servo to go to position in variable 'pos'
}


void changeColor()
{
  if(lightpos == 0)
  {
    //blue
    lightpos = 1;
    moveRed = 50;
    moveGreen = 150;
    moveBlue = 255;
  }
  else if(lightpos == 1)
  {
    //purple
    lightpos = 2;
    moveRed = 100;
    moveGreen = 0;
    moveBlue = 255;
  }
    else if(lightpos == 2)
  {
    //blue
    lightpos = 3;
    moveRed = 100;
    moveGreen = 100;
    moveBlue = 255;
  }
  else if(lightpos == 3)
  {
    lightpos = 4;
    moveRed = 128;
    moveGreen = 128;
    moveBlue = 128;
  }
   else if(lightpos == 4)
  {
    lightpos = 0;
    moveRed = 254;
    moveGreen = 254;
    moveBlue = 254;
  }
}

void tickColor() {
  if(!(red==moveRed && green==moveGreen && blue==moveBlue))
  {
    if(red>moveRed) red -= 1;
    else if(red<moveRed) red += 1;

    if(green>moveGreen) green -= 1;
    else if(green<moveGreen) green += 1;

    if(blue>moveBlue) blue -= 1;
    else if(blue<moveBlue) blue += 1;
  }
 
  else
  {
    changeColor();
  }
    analogWrite(RED,red);
    //analogWrite(GREEN,green);
    analogWrite(BLUE,blue);
  
    delay(10);
}


_____

HI