1

The SM-1 Project Part 1: Playing around the Seeeduino board @seeedstudio #arduino

So, we have all our parts ready to make our SM-1 project (aka The Annoying IKEA lamp)… and what do we do now? Let´s play around with the Seeeduino board and the Grove Toy Kit sensors.

Here is the video of the resulting components working together: (or The Rise of Skynet?)

The different components we are using (and links to the seeedstudio.com product page of each):

The Seeeduino Board

The Stem Shield

The Servo Motors

The Motion Sensor

The Sound Recorder

The basic idea is to detect if there is movement or not (with the motion detector); if there is movement we start the servo no.2 and play a pre-recorded message. Otherwise, there is working the servo no.1 and a different pre recorded message.

Reading the state of the motion sensor is very simple: we assign and digital input and read the state. The result is a binary data 0 or 1 (quiet or movement). Doing a simple loop and based on this result we start one or another gadgets.

The sound recorder on it´s own, can only play 4 pre-recorded sounds via external signal. To record them there has to change a switch from play to record position and press the desired button (it has 4 buttons, one for each sound) and record it (should be less than 15sec each). Once recorded we change the switch to play position, and access them by the play() function declared on the code.

The servos work in a very simple logic, they have 3 cables: positive, negative and digital data. The first two give the servo the power to move (max 7v) and the third one goes to an digital output where it receives the information on which degree should it be, and the change begins. We are using the sweep tutorial code in this example.

@mrlndr

The code (can be optimized for sure, but we were just playing around and getting to know the new board and sensors):

// Based on the Sweep code by BARRAGAN <http://barraganstudio.com>
// Also includes code examples from the wiki on seeedstudio.com
// Code and schematics by @mrlndr for arduinoarts.com

#include <Servo.h> 

Servo myservo2;
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 pos2 = 0;    // variable to store the servo position
const int ledPin=13;//The led to indicate the motion

char index;
char control;
char state; 

int audiodelay=1000;

void setup()
{
  //Serial.begin(9600);
  //Motion Sensor
  pinMode(2, INPUT);//Use pin 2 to receive the signal outputted by the module
  pinMode(ledPin, OUTPUT);
  //SERVOS
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo on pin 9 to the servo object
  //AUDIO
  DDRD |= 0x0C;   //D2 and D3 in write mode;
  PORTD &= 0xF3;  //D2 and D3 set to low;
} 

void rec_2_begin()
{
 PORTD = (PORTD | 0b00000100)&0b11110111;
}
void rec_2_stop()
{
PORTD &= 0xF3;
}
void play_2()
{
 PORTD = (PORTD | 0b00000100)&0b11110111;
 delay(audiodelay);
 PORTD &= 0xF3;
}
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// function to control the segment_3
void rec_3_begin()
{
 PORTD = (PORTD | 0b00001000)&0b11111011;
}
void rec_3_stop()
{
PORTD &= 0xF3;
}
void play_3()
{
 PORTD = (PORTD | 0b00001000)&0b11111011;
 delay(audiodelay);
 PORTD &= 0xF3;
}
/////////////////////////////////////////////////////
////////////////////////////////////////////////
// function to control the segment_4;
void rec_4_begin()
{
 PORTD = PORTD | 0b00001100;
}
void rec_4_stop()
{
PORTD &= 0xF3;
}
void play_4()
{
 PORTD = PORTD | 0b00001100;
 delay(audiodelay);
 PORTD &= 0xF3;
}
//////////////////////

void check_move()
{
  int sensorValue = digitalRead(2);
  if(sensorValue==1)
  {
  digitalWrite(ledPin,HIGH);
  //Serial.println(sensorValue, DEC);//Print the state of the signal through the serial monitor.
  //servo1();  

}
  else
  {
  digitalWrite(ledPin,LOW);
  //Serial.println(sensorValue, DEC);//Print the state of the signal through the serial monitor.
  //servo2();
  }
}

 void servo1()
{for(pos = 0; pos < 50; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 50; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
}

 void servo2()
{for(pos2 = 0; pos2 < 50; pos2 += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos2 = 50; pos2>=1; pos2-=1)     // goes from 180 degrees to 0 degrees
  {
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

void loop()
{
 check_move();
 int sensorValue = digitalRead(6);
 if(sensorValue==1)
  {
    servo1();
    play_3();

  }
  else
  {
    servo2();
    play_2();

  }
 delay(1000);
}

Related Posts

  • It´s alive!!!!! and it´s a SM-1 baby boy!!!! We have finally done it. The first working prototype. Born from the mix of the SM-1 Project Part 1 and SM-1 Project Part 2 posts. Thanks to this, we have the first working prototype of the SM-1 Project. Check this video to see…
    Tags: the, sm, project, to, and, servo, skynet, tutorial, seeedstudio.com, arduino-like
  •  Welcome to the SM-1 project from ArduinoArts.com! We are proud to introduce you to the SM-1 project (aka the Annoying IKEA lamp), as part of the Toy hacking contest from the SeeedStudio.com friends. The project consists in modifying an IKEA 5€ lamp and adding it some sensors, lights, sound and…
    Tags: the, to, and, project, sm, ikea, hacks, seeedstudio.com, servo, skynet
  • The SM-1 Project Part 2: Installing the servo on the lamp: I have to be honest: this is my first time working with servos, but not the first time i modify this IKEA Lamp (check this mod for Iphone i made and which i use to record this video). Watch the…
    Tags: the, to, servo, skynet, tutorial, hacks, ikea, arduino-like, arduino