Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Aya wally
Published

Mother's Day Gift

Here is a special box that opens itself and rotates a mobile inside, then LEDs, music, camera and twitter will be turned on.

IntermediateFull instructions provided2,248
Mother's Day Gift

Things used in this project

Story

Read more

Schematics

schematic of project circuit

Code

Arduino code

Arduino
/*mothers' day project*/


#define CUSTOM_SETTINGS
#define INCLUDE_ACCELEROMETER_SENSOR_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_CAMERA_SHIELD
#define INCLUDE_TWITTER_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
#include <Servo.h>
/* create servo object to control a servo*/
Servo myservo;
int pos = 0;

void setup() {
  // put your setup code here, to run once:
  /* Start communication. */
  OneSheeld.begin();
  /* attaches the servo on pin 9 to the servo*/
  myservo.attach(9);
  /* Set the LEDs pin as output. */
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  /*create a variable which it puts the values of accelerometer in*/
  float X = AccelerometerSensor.getX();
  /*multiply the values of X in (360/18)((angles of rotaion/maximum position of the servo in X axis))*/
  myservo.write(X * 20);
  /* Check X-axis acceleration. */
  if (X > 8)
  {
    /* Set the volume. */
    MusicPlayer.setVolume(5);
    /* Turn on the music. */
    MusicPlayer.play();
    /* Wait for 300 ms. */
    OneSheeld.delay(300);
    digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(2, HIGH);
    /* Turn on the camera flash. */
    Camera.setFlash(ON);
    /* Take the picture. */
    Camera.rearCapture();
    /* Wait for 20 seconds. */
    OneSheeld.delay(20000);
    /* Post the picture on Twitter. */
    Twitter.tweetLastPicture("Posted by @1Sheeld and @Arduino,happy mothers' day ");


  }
}

Credits

Aya wally
2 projects • 0 followers
Aya Adel, 19 years old,i'm in Faculty of Engineering Ain Shams university,2nd year in mechanical department

Comments