Moody Useless Machine

This is a project i did a while ago. I made one for my self and two as gifts. I decided to crack open the one I had left, to get some photos and video of the inside. I also did’t remember how I connected the pins to the ATMGEGA 328P. It uses two standard hobby servos, a home made ATMEGA 328P PCB-Board and a MOSFET to turn the power to the servos off in sleep mode. The switch is connected from an input pin trough a 470 Ohm resistor trough the switch and to ground. This will set the input pin to low when the switch is closed. I then use a interrupt to wake the microprocessor.

The boxes in action:

Inside a box:

The PCB that I made has two power inputs. One +5V for the microcontroller, and one +6V for the servos. In this box I use 4 x 1,5V batteries for power. This gets the +6V connected. To get +5V, I connected a diode from +6V to +5V. The voltage drop over the diode is 0.7V, and I then got +5.3V for the microcontroller. This seems to work OK. The switch is connected to S15 (pin 2 on Arduino). The servo for the lid is connected to S05 (pin 12 on the Arduino). The servo for the switch is connected to S06 (pin 13 on the Arduino). MOSFET is conntrolled from Arduino pin 8 (Thats why S01 is missing on the PCB). The ATMGA 328P is programmed on an Arduino. The MOSFET on the picture below is not in the same place as the new version of the PCB.20130706_233418
The contruction was a bit tricky. One servo turns off the switch, and the other open the lid.

20130706_233638
The PCB board fits the wall at the one side:20130706_233837
And the the batteries at the bottom:20130706_234025
The lid uses two nails to allign the edge to the box.20130706_234047
I use a rubber band attached to the inside of the lid.20130706_234059
The rubber band attached:20130706_234139
I then use a piece of foam to hold the batteries firmly in the box.20130706_234213

Wiring diagram:

useless box schematics

Schematic diagram:

Moody Useless Machine

PCB bottom copper view from top:bottom_copper
PCB bottom copper view from bottom (mirrored):bottom_copper_mirror

PCB top silk screen view from top:top_silk

PCB top silk screen view from bottom (mirrored):top_silk_mirrorPartlist:
C1 = 22p
C2 = 22p
C3 = 100n
C4 = 10u
C5 = 100n
C6 = 10u
C7 = 10u
K1 =CMM 2×2-pol connector
Q1 = IRLZ14 or any MOSFET with same pin configuration
U1 = ATMEGA 328P With Arduino bootloader
X1 = 16MHz crystal
Two straps (wire) as marked on the silk screen.
S05 and S06 = Wire or 3 pin header for connecting servos
1 reistor 470 Ohm (The one connected to the switch)
1 diode (1A) for Connection from +6V to +5V
Switch (on/off)
2 Hobby servos
1 Rubber band
Some connection wire
Battery 4 x 1,5V AA case
4 batteries (AA)
Some wooden sticks
Wood glue
2 nails (small)
1 piece of foam

Code:

#include <Servo.h>
#include <avr/sleep.h>
Servo myservo2;  // create servo object to control a servo
Servo myservo1; 
                
int pos = 0;    // variable to store the servo position
int boxon =1;
// Predefined positions for a spesific box/servo
int S1fra = 1400;    // from   s1=Servo1
int S1mid = 1800;    // Mid
int S1mid2 = 1580;
int S1mid3 = 1640;
int S1til = 2050;    // To
int S2fra = 1784;    //From    s2=Servo2
int S2mid = 1200;
int S2mid2 = 1000;   // Almost on the switch
int S2til = 770;
 
int seq = 0;
 
void setup()
{
  myservo2.attach(13);  // attaches the servo on pin 13 to the servo object (PB5)
  myservo1.attach(12);  // attaches the servo on pin 12 to the servo object (PB4)
  pinMode(8, OUTPUT);   // For the MOSFET
  pinMode(2, INPUT);    // For the switch interrupt
  digitalWrite(2, HIGH);
  myservo2.write(S2fra);
  myservo1.write(S1fra);
  delay(600);
  digitalWrite(8, HIGH);
  delay(300);
  digitalWrite(8, LOW);
// Put all unused pins to input high to save power.
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
  pinMode(4, INPUT);
  digitalWrite(4, HIGH);
  pinMode(5, INPUT);
  digitalWrite(5, HIGH);
  pinMode(6, INPUT);
  digitalWrite(6, HIGH);
  pinMode(7, INPUT);
  digitalWrite(7, HIGH);
  pinMode(9, INPUT);
  digitalWrite(9, HIGH);
  pinMode(10, INPUT);
  digitalWrite(10, HIGH);
  pinMode(11, INPUT);
  digitalWrite(11, HIGH);
  DDRC = 0;               //Analog input 1/6 (PortC) set to input high also
  PORTC = 63;
.   
     //External interrupt INT0
  EICRA=0;   //The low level of INT0 generates an interrupt request
  EIMSK=1;   //External Interrupt Request 0 Enable
 
}
 
 
void loop()
{
  if(!boxon) //boxon should actually be called boxoff. Did a mistake here.
  {
    delay(500);
    digitalWrite(8, HIGH);
    //seq = int(random(0,10)); //If you want random…
   
    if(seq == 0)Sequense3();
    if(seq == 1)Sequense1();
    if(seq == 2)Sequense3();
    if(seq == 3)Sequense9();
    if(seq == 4)Sequense3();
    if(seq == 5)Sequense5();
    if(seq == 6)Sequense3();
    if(seq == 7)Sequense7();
    if(seq == 8)Sequense3();
    if(seq == 9)Sequense2();
    if(seq == 10)Sequense3();
    if(seq == 11)Sequense10();
    if(seq == 12)Sequense3();
    if(seq == 13)Sequense8();
    if(seq == 14)Sequense3();
    if(seq == 15)Sequense6();
    if(seq == 16)Sequense3();
    if(seq == 17)Sequense4();
    seq++;
    if(seq>17) seq=0;
    delay(100);
    digitalWrite(8, LOW);
    boxon=digitalRead(2);
  }
  else
  {
    //Set sleep mode, turn off MOSFET and servos
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    pinMode(12, INPUT);
    digitalWrite(12, HIGH);
    pinMode(13, INPUT);
    digitalWrite(13, HIGH);
    PRR = 255;
    MCUCR |= (1<<BODS) | (1<<BODSE);
    MCUCR &= ~(1<<BODSE);   
    EIMSK=1;
    sleep_mode();
    // ZZZzzz…
    sleep_disable();     //Awake again…
    PRR = 0;
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
  }
  boxon=digitalRead(2); //If pin 2 is low, box is on and bonxon=flase
}
 
//Fra=From, Til=To (Sorry for some Norwegian variables)
void Sweep(int srv, int fra, int til, int usec) 
{
  if(srv == 1)
  {
    if(fra <= til)
      for(pos = fra; pos < til; pos += 1)
      {
        myservo1.writeMicroseconds(pos);
        delayMicroseconds(usec);
      }
    else
    {
      for(pos = fra; pos>=til; pos-=1)
      {
         myservo1.writeMicroseconds(pos);
        delayMicroseconds(usec);
      }
    }
  }
  if(srv == 2)
  {
    if(fra <= til)
      for(pos = fra; pos < til; pos += 1)
      {
        myservo2.writeMicroseconds(pos);
        delayMicroseconds(usec);
      }
    else
    {
      for(pos = fra; pos>=til; pos-=1)
      {
         myservo2.writeMicroseconds(pos);
        delayMicroseconds(usec);
      }
    }
  }
}
 
ISR(INT0_vect)   // Step rising edge interrupt. Switch flipped.
{
  EIMSK=0;   //Turn off interrupt
  boxon=digitalRead(2);  //Read the switch a couple of times to avoid a nasty non working thing some times.
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
  boxon=digitalRead(2);
}
void Sequense1()
{
  delay(700);
  Sweep(1, S1fra, S1mid, 3000);
  delay(1000);
  Sweep(1, S1mid, S1fra, 500);
  delay(1000);
  Sweep(1, S1fra, S1til, 1000);
  Sweep(2, S2fra, S2mid, 1800);
  Sweep(2, S2mid, S2til, 500);
  delay(100);
  Sweep(2, S2til, S2fra, 500);
  Sweep(1, S1til, S1fra, 500);
}
void Sequense2()
{
  delay(800);
  Sweep(1, S1fra, S1mid2, 3000);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(120);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(120);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(120);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(120);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(120);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(120);
  Sweep(1, S1mid2, S1fra, 3000);
  Sweep(1, S1fra, S1mid, 3000);
  delay(1000);
  Sweep(1, S1mid, S1til, 1000);
  Sweep(2, S2fra, S2mid, 1800);
  Sweep(2, S2mid, S2til, 500);
  delay(100);
  Sweep(2, S2til, S2fra, 500);
  Sweep(1, S1til, S1fra, 500);
}
void Sequense3()
{
  delay(50);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense4()
{
  delay(500);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2mid2, 1);
  delay(450);
  Sweep(2, S2mid2, S2til, 30000);
  delay(1);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense5()
{
  delay(1000);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(2, S2til, S2mid2, 1);
  delay(110);
  Sweep(2, S2mid2, S2til, 1);
  delay(110);
  Sweep(2, S2til, S2mid2, 1);
  delay(110);
  Sweep(2, S2mid2, S2til, 1);
  delay(110);
  Sweep(2, S2til, S2mid2, 1);
  delay(110);
  Sweep(2, S2mid2, S2til, 1);
  delay(110);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense6()
{
  delay(1500);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(1, S1til, S1fra, 1000);
  delay(2000);
  Sweep(1, S1fra, S1til, 1000);
  delay(2000);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense7()
{
  delay(500);
  Sweep(1, S1fra, S1mid, 1);
  delay(200);
  Sweep(1, S1mid, S1mid2, 1);
  delay(100);
  Sweep(1, S1mid2, S1mid, 1);
  delay(100);
  Sweep(1, S1mid, S1mid2, 1);
  delay(100);
  Sweep(1, S1mid2, S1mid, 1);
  delay(100);
  Sweep(1, S1mid, S1fra, 1);
  delay(200);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense8()
{
  delay(200);
  Sweep(1, S1fra, S1mid, 1);
  delay(200);
  Sweep(1, S1mid, S1mid2, 1);
  delay(100);
  Sweep(1, S1mid2, S1mid, 1);
  delay(100);
  Sweep(1, S1mid, S1mid2, 1);
  delay(100);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1fra, 1);
  delay(200);
  Sweep(1, S1fra, S1til, 1);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense9()
{
  delay(1000);
  Sweep(1, S1fra, S1mid, 2000);
  delay(500);
  Sweep(1, S1mid, S1mid2, 1000);
  delay(1);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(50);
  Sweep(1, S1mid2, S1mid3, 1);
  delay(50);
  Sweep(1, S1mid3, S1mid2, 1);
  delay(500);
  Sweep(1, S1mid2, S1mid, 5000);
  delay(1);
  Sweep(1, S1mid, S1til, 1000);
  delay(1);
  Sweep(2, S2fra, S2til, 1);
  delay(450);
  Sweep(2, S2til, S2fra, 1);
  delay(200);
  Sweep(1, S1til, S1fra, 1);
  delay(400);
}
void Sequense10()
{
  delay(800);
  Sweep(1, S1fra, S1til, 30000);
  delay(1);
  Sweep(2, S2fra, S2til, 3000);
  delay(1);
  Sweep(2, S2til, S2fra, 3000);
  delay(1);
  Sweep(1, S1til, S1mid, 30000);
  delay(1);
  Sweep(1, S1mid, S1fra, 1);
  delay(300);

}

There might be some typos in the code…

Better use this file : UselessMachine.pde  <<<<<—–Download this!

This entry was posted in Hardware projects. Bookmark the permalink.

97 Responses to Moody Useless Machine

  1. Rhino says:

    Someone in europe who could build and sell this to me?

  2. Bob says:

    Really nice work. Would you be prepared to show me a circuit diagram? Thanks

  3. Gerald says:

    sell me one or several pls :D

  4. Txai says:

    Your project is amazing! Do you still have the schematic? if you do, can you send it to me?

    thank you!

  5. Bernd says:

    Please tell me the complete circuit diagram of the PCB, because I am not able to make a PCB. Thank you.

    • arvid says:

      Hi. I will put together a shematic diagram. Coming up soon…

      • Nick says:

        Sorry to be a nag, but any news on the schematic? Viewing your machine has created a group of simpleton electronics wanabees i’m afraid.
        By making a machine so awesome you’ve created a rod for your own back. lol

  6. Brian says:

    I would seriously like to buy a set – please contact me if you are interested in selling a pair at minimal

  7. Oliver says:

    Hello first compliment for your box is very good! I wanted to ask if you have a box to sell? greetings

  8. Jonathan says:

    This looks amazing! If you have plan to make and sell them, let me know. I’d buy one for a fair price!

  9. Daemon says:

    Hey man, great stuff!

    I’m doing this ‘useless’ machine for an arduino project for university, but I have a very basic understanding of it and cant vibe with this field very easily so I was wondering if you could break down how to make a simpler version of this, and break down of the code? It would mean so much.

    Cheers.

  10. Tchello Silveira says:

    I’m using 1.0.5 with Arduino Arduino UNO and received the error message below, would help?

    useless_machine:18: error: stray ‘\’ in program
    useless_machine:115: error: stray ‘\’ in program
    useless_machine:154: error: stray ‘\’ in program
    useless_machine:8: error: expected constructor, destructor, or type conversion before ‘void’
    useless_machine:10: error: expected constructor, destructor, or type conversion before ‘extern’
    useless_machine:19: error: expected constructor, destructor, or type conversion before ‘int’
    useless_machine.ino: In function ‘void setup()’:
    useless_machine:53: error: expected primary-expression before ‘.’ token
    useless_machine:55: error: expected unqualified-id before ‘(‘ token
    useless_machine.ino: In function ‘void loop()’:
    useless_machine:69: error: ‘seq’ was not declared in this scope
    useless_machine:70: error: ‘seq’ was not declared in this scope
    useless_machine:71: error: ‘seq’ was not declared in this scope
    useless_machine:72: error: ‘seq’ was not declared in this scope
    useless_machine:73: error: ‘seq’ was not declared in this scope
    useless_machine:74: error: ‘seq’ was not declared in this scope
    useless_machine:75: error: ‘seq’ was not declared in this scope
    useless_machine:76: error: ‘seq’ was not declared in this scope
    useless_machine:77: error: ‘seq’ was not declared in this scope
    useless_machine:78: error: ‘seq’ was not declared in this scope
    useless_machine:79: error: ‘seq’ was not declared in this scope
    useless_machine:80: error: ‘seq’ was not declared in this scope
    useless_machine:81: error: ‘seq’ was not declared in this scope
    useless_machine:82: error: ‘seq’ was not declared in this scope
    useless_machine:83: error: ‘seq’ was not declared in this scope
    useless_machine:84: error: ‘seq’ was not declared in this scope
    useless_machine:85: error: ‘seq’ was not declared in this scope
    useless_machine:86: error: ‘seq’ was not declared in this scope
    useless_machine:87: error: ‘seq’ was not declared in this scope
    useless_machine.ino: At global scope:
    useless_machine:117: error: expected constructor, destructor, or type conversion before ‘void’

  11. Tchello Silveira says:

    Resolved, to copy text with formatting code created small tab spaces that caused the errors.
    Thank you!

  12. Daniel Müller says:

    I would like buy this. Can somebody sell it for me?

  13. Mark Thomason says:

    Get this error code on verify with Arduino Uno

    pinMode(11, INPUT);
    digitalWrite(11, HIGH);
    DDRC = 0; //Analog input 1/6 (PortC) set to input high also
    PORTC = 63;
    .
    //External interrupt INT0
    EICRA=0; //The low level of INT0 generates an interrupt request
    EIMSK=1; //External Interrupt Request 0 Enable

    Seems to be the “.” after PORTC = 63;

  14. Mark Thomason says:

    Sorry, left out the error code

    UselessMachine.pde: In function ‘void setup()’:
    UselessMachine:57: error: expected primary-expression before ‘.’ token
    UselessMachine:59: error: expected unqualified-id before ‘(‘ token

  15. Patrik Weber says:

    Hello first compliment for your box is very good! I wanted to ask if you have a box to sell? greetings

  16. Peter Wagner says:

    Hi first of all your box is amazing. Very cool really. I’m from Germany so sorry for my bad english. I build your box with the same Programm and the same PCB like you. It seems to work. If the Switch is on and the pcb is connected with the batteries the servos move. If i turn the Switch of the servos Ends the current Programm step and don’t move anymore. So far so good. Now the Problem. When i turn on the Switch again nothing happens. Only if i let the Switch in the on Position and disconnect the batteries and connect them again, the servos work in the same way i describe in the top. I realy don’t know why. I hope you understand my english and maybe you can help me with this Problem.

    Greetings
    Peter

    • arvid says:

      Hi. I hope you used the downloadedble link for the program, and not copied the code from the page. There might be some wrong formatting in that text. I also had some problem with the switch not working, but only one of 10 cycles or so. So I added a few digitalread to “fix” that:

      ISR(INT0_vect) // Step rising edge interrupt. Switch flipped.
      {
      EIMSK=0; //Turn off interrupt
      boxon=digitalRead(2); //Read the switch a couple of times to avoid a nasty non working thing some times.
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      boxon=digitalRead(2);
      }

      But if it’s not working at all, I guess the interrupt is not set up properly:
      //External interrupt INT0
      EICRA=0; //The low level of INT0 generates an interrupt request
      EIMSK=1; //External Interrupt Request 0 Enable

      Thats what I can think of. Hope it helps.

      And your English is as good or better than mine (I’m from Norway)

  17. Peter Wagner says:

    First of all thank you for the fast answer. So now first of all yes i used the downloadable code. So i think it is not the problem with the several read of the switch. But what do you mean with the interrupt is not set up? These programm lines are in the downloadable code or not?

    Greetings peter

    • arvid says:

      Hi.
      Yes, if you use the downloaded code, the program lines are included. I’m not shure why you get this behavior. Is the switch connected from the pin from the ATMEGA328 via the resistor (470 Ohm) to GND? Then it should have worked. You can maybe try to lower the reistor a bit. There should be an interrupt occuring when the pin goes low.

  18. Peter Wagner says:

    It works thank you. But i had another question. How can i tell the programm to make the steps in random mode. I’ve read in your programm that it is possible but i don’t know exactly what i had to do. Sorry for the maybe stupid questions but thats one of my first bigger projects with microcontrollers. Especially with arduino

    Greetings
    Peter

    • arvid says:

      Change from this:

      void loop()
      {
      if(!boxon) //boxon should actually be called boxoff. Did a mistake here.
      {
      delay(500);
      digitalWrite(8, HIGH);

      //seq = int(random(0,10)); //If you want random…

      if(seq == 0)Sequense3();
      if(seq == 1)Sequense1();
      if(seq == 2)Sequense3();
      if(seq == 3)Sequense9();
      if(seq == 4)Sequense3();
      if(seq == 5)Sequense5();
      if(seq == 6)Sequense3();
      if(seq == 7)Sequense7();
      if(seq == 8)Sequense3();
      if(seq == 9)Sequense2();
      if(seq == 10)Sequense3();
      if(seq == 11)Sequense10();
      if(seq == 12)Sequense3();
      if(seq == 13)Sequense8();
      if(seq == 14)Sequense3();
      if(seq == 15)Sequense6();
      if(seq == 16)Sequense3();
      if(seq == 17)Sequense4();
      seq++;
      if(seq>17) seq=0;

      Change to this:

      void loop()
      {
      if(!boxon) //boxon should actually be called boxoff. Did a mistake here.
      {
      delay(500);
      digitalWrite(8, HIGH);

      seq = int(random(0,10)); //If you want random…

      if(seq == 0)Sequense1();
      if(seq == 1)Sequense2();
      if(seq == 2)Sequense3();
      if(seq == 3)Sequense4();
      if(seq == 4)Sequense5();
      if(seq == 5)Sequense6();
      if(seq == 6)Sequense7();
      if(seq == 7)Sequense8();
      if(seq == 8)Sequense9();
      if(seq == 9)Sequense10();

  19. Peter Wagner says:

    Thank you very much

  20. Jay says:

    Hi, is it possible to have one made that I can buy off you? This would make a really fun toy to sit on my desk at work..

    Thanks heaps.

  21. Anonymous says:

    I too would like to buy one ready made but I noticed you haven’t replied to any similar requests…do you sell them?

    • arvid says:

      I don’t have time to make kits for sale. And the prize will bee to high. So no, I will most probably never sell these. And they are not that hard to make yourself,

  22. Alan Rands says:

    Do you sell the PCB? I can’t seem to find that part (or a substitute) anywhere. Thanks

    • Peter Wagner says:

      certainly you don’t find the pcb anywhere. it is selfmade. and how arvid says the price to sell will be too high

  23. Peter Wagner says:

    I just want to help the people build a owen useless box. No reason to delte my comment. Not everybody has the knowledge and the material to build everything alone. So if someone needs help, material or a pcb contact me.
    peterwagner321@gmail.de

  24. Vitali says:

    Hello!

    Sorry for my english, i am from Estonia.
    I want to build my useless box as like you, and i think i can build it: wooden box, mechanics, PCB board. But i wasn’t make programming earlier…
    Tell me please, is this hard? What i need for it?
    And thank you very much for help!

    Vitali.

  25. Torsten Albrecht says:

    Hi,

    a BIG thank you for this project!

    I want to build this with an Arduino UNO.
    But at which ports I must connect the servos?
    Do I modify your code for Ardunio?

    Regards,

    Torsten

    • arvid says:

      Hi.
      The ports used in the code is digital pin 12 and 13.
      Code that sets the ports:
      myservo2.attach(13); // attaches the servo on pin 13 to the servo object (PB5)
      myservo1.attach(12); // attaches the servo on pin 12 to the servo object (PB4)

      The code is made for an Arduino UNO…

      Regards
      Arvid

      • Torsten Albrecht says:

        Okay.

        The Switch is connect to PIN2 and the ground at the Arduino?
        And the MOSFET to ground and the ground at the servos, right?

        Regards,

        Torsten

  26. Torsten Albrecht says:

    Hi,

    thank you for assistance with the pin problems.

    I build the machine with my Ardunio and lower the voltage from 6V for the servos to ~5V for the Ardunio with a diode.

    But the servos running weird. The lid servo open and close the lid in a loop (open, close, open, close…) and the switch servo doesn’t respond. I see the orange light at the UNO when the lid servo is addressed and just a slight flicker when the switch servo is addressed.

    Is this a code problem?

    Cheers,

    Torsten

    • arvid says:

      Hi.

      I’m not sure. Did you use the downloadeable code at the end of the page? I think there might be some character problem if you copy the code text from the page. It actually seems to me that the servos are mixed up, or the pin number are wrong. Strange…

      Regards
      Arvid

  27. Torsten Albrecht says:

    Hi,

    I read about the copy and paste problem and download the code.

    But I think it could be a power problem with my Arduino.

    If I connect my notebook to the Arduino, both servos are working. The wrong direction but both are working. Can I invert the values of the servos?

    If I disconnect the notebook I got the same problem (only one servo is working).

    Torsten

    • arvid says:

      To reverse the servos, you’ll need to edit the prdefined positions. You should anyway do this as two servos never are the same, and your box probably is not exactly the dimensions that I made.
      Just play around with the values, from 600 to 2200 (some servos may work with 500 to 2500)

      // Predefined positions for a spesific box/servo
      int S1fra = 1400; // from s1=Servo1
      int S1mid = 1800; // Mid
      int S1mid2 = 1580;
      int S1mid3 = 1640;
      int S1til = 2050; // To
      int S2fra = 1784; //From s2=Servo2
      int S2mid = 1200;
      int S2mid2 = 1000; // Almost on the switch
      int S2til = 770;

  28. MICHAEL MULCAHY says:

    Do you have a schematic diagram for the circuit?

  29. Ricardo Souza says:

    Hello Arvid. Great stuff, man!!
    There are dozens of versions of this “Useless Box” toys around the net however, your’s is the best Project overall, especially because of this page!! Congrats!

    I’ve built three of these boxes to give to my nephews for XMas. The mechanical bits are done and the program loaded on the Arduino IDE (I decided to use the Random mod). Now, all I’m missing is the electronic schematic, so that I don’t have to trace the PCB for the proper connections.

    Would you happen to have it handy? Would you be able to sent it to me by email or post it to the site, since so many people have already expressed their desire to have it as well?

    I really want to finish them this weekend, so that I don’t miss the XMas deadline (sorry for the pressure!!)

    Thanks in advance and best regards!

  30. Ricardo Souza says:

    I already did!!

    May I have your email, so that I can send you my Fritzing file?

    That way you can just double-check it and fix any mistakes I may have made (I am NOT well versed in that program!).

    Afterwards you can post it here.

    Thanks for replying so quickly!

    • arvid says:

      Hi.

      I did not see your post in time, so I have made a schematic diagram anyway. My email can be found on the “about” page : arvid@lamja.com
      The schematic can be found above in the post.

      Regards
      Arvid

  31. Ricardo Souza says:

    Thanks!

    I’ll send you my file anyway.

    Thanks for helping out with such shirt notice, and Congratularions again on your great project!

    Merry XMas and a Great New Year!

  32. Mike says:

    Hi, love the box. Very fun project. Thanks for putting it up. This is my first introduction into circuits and im using your project as a teaching guide. Very helpful. I had a couple of quick questions if thats ok. I have a good handle on all the components, but and a little confused on the need for all the compositors. Can you provide a simple explanation for each compositor? I understand the purpose for the compactors connected to the timer and I think i understand the need for C7 and C4. But the purpose of the others seem a little confusing. I too am having an issue with the box not responding right away when the switch it flipped. It seems to be at random for its response. Sometimes it is right away and other times it will sit for a while. I originally started with you downloaded code, but after encountering the issue i tried working with it to fix it. I followed this code to see if it might help: http://playground.arduino.cc/Learning/arduinoSleepCode

    Seem to be a dead end. Im thinking it has to do with power management which is why im asking about the compositors. Also, i didn’t have a 1ou 100v capacitor so i used a 10u 50v capacitor. My understanding is this would be find. Any input here also would be appreciated. Thanks for putting this up. Its be a very fun project to dive into. Here is the bulk of my current code (im excluding the sequence stuff because i didn’t really modify those):


    #include
    #include

    Servo switchLeverServo; // create servo object to control a servo
    Servo lidServo;

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

    // Predefined positions for a spesific box/servo
    int lidClosedPOS = 1400; // from s1=Servo1
    int lidMidPOS = 1800; // Mid
    int lidMid2POS = 1580;
    int lidMid3POS = 1640;
    int lidOpenPOS = 2050; // To

    int switchLeverHiddingPOS = 2200; //From s2=Servo2
    int switchLeverMidPOS = 1200;
    int switchLeverMid2POS = 1000; // Almost on the switch
    int switchLeverPushingPOS = 920;

    /*
    pins
    */
    int lidServoPin = 11;//13
    int switchLeverServoPin = 10;//12
    int switchpin = 2;//2
    int servosMOSFET = 9;

    int seq = 0;

    void setup()
    {
    pinMode(switchpin, INPUT);// For the switch interrupt

    switchLeverServo.attach(switchLeverServoPin); // attaches the servo on pin 13 to the servo object (PB5)
    lidServo.attach(lidServoPin); // attaches the servo on pin 12 to the servo object (PB4)
    pinMode(servosMOSFET, OUTPUT); // For the MOSFET

    digitalWrite(servosMOSFET, HIGH);
    switchLeverServo.write(switchLeverHiddingPOS);
    lidServo.write(lidClosedPOS);
    delay(600);
    digitalWrite(servosMOSFET, LOW);

    // Put all unused pins to input high to save power.
    int emptyPins[] = {4,5,6,7,8,12,13};
    for(int i=0;i19) seq=0;

    delay(100);
    digitalWrite(servosMOSFET, LOW);
    }
    else
    {
    sleepNow();
    }
    delay(100);
    boxoff=digitalRead(switchpin); //If pin 2 is low, box is on and boxoff=flase
    }

    Any help would be appreciated. Thanks!

    • Mike says:

      Stupid autocorrect, im referring to capacitors not compactors. thanks

    • arvid says:

      Hi. C3 and C5 is to get capasitors close to the two power pins on the ATMEGA 328. This is usually very important with any IC. C6 and C7 is electrolytic capasitors to pair up the ceramic ones (c3 and C5). Ceramic capasitors are good for high freq. filtering, and electrolitics are good at low freq. filtering and power reserve. These four capasitors are all on the 5V rail. I also included one capasitor on the 6V rail, to make the servos happy. I know it might be overkill, but it’s easier to put them there in the first place, rather having to search for a noise problem afterwards. Remember that the servos can generate some nasty noise.

      The problem you have. It might be the resistor. I’m not sure why I put it tn there at all. The pin for the switch should be pulled up internally in the Atmega328, and it only need a Connection to ground to make the interrupt. You can try lowering this, or remove it completly. I’m not sure what will happend to the power usage of the atmega if you do.

      Regards
      Arvid

  33. Christopher says:

    I don’t have an Arduino, would it be possible to buy a pre programmed ATMEGA 328P form you with random actions?
    I really like this useless machine

  34. Christopher says:

    Quick question, would it be possible to remove the ATmega328 from an arduino and drop an ATmega328 with Arduino Optiboot (Uno) from sparkfun load up the code here take it out and it be good to go?
    Sorry I’m a total newb to arduino.

    • Anonymous says:

      The atmega is shipped from Sparkfun only with the bootloader, you will need to record the “LAMJA firmware” in the new atmega. The best solution would be to buy an Arduino NANO USB and which is reduced in size, or an Arduino UNO to a slightly larger box.

  35. Faith says:

    I would like to buy one of these boxes. If possible please contact me.

  36. CaptnJB says:

    Hey, guys. Need a little MOSFET help. I don’t want to spend 8 bucks for an IRLZ14, it says anything with a similar pinout, so would the IRF510 power mosfet work? I have one of those laying around. Just not sure and I can’t find a decent cross reference.

    Thanks,
    JB

  37. protter says:

    I have connect everything and upload the code, but the servo didn’t move any idea how to identify the error?
    I have tested the board and there is on everz field currency
    Thanks

  38. Brayden says:

    im doing this project at school and was wondering if you could tell me more on the compositors in the parts list because my Systems teacher and i dont understand what the ” p, n, u ” are

  39. matze says:

    Hi,

    First: sorry for my bad english :)

    Is it possible to take a “ATtiny85″ and not the ATMega328?

  40. SiL3nT says:

    Great project, just had a question on the dimensions of the box you built and the dimensions of the PCB. I plan on attempting to etch my own PCB at home and building this project for fun.

  41. jakop says:

    can i program the atmega328p with this ? USB Serial Light Adapter ?

  42. jakop says:

    can i program the atmega328p with a raspberry pi ? or can i do it with a TXD RXD GND 3.3V cables ? how then.

  43. jakop says:

    Can i use a Arduino Mini 5 instead of atmega328 p ?

  44. Felix says:

    Hi,

    thank you for this great project!
    I never had tryed something with Arduino?
    Are there any problems or changes in the code if I use a
    STK500 Board (http://de.farnell.com/jsp/displayProduct.jsp?sku=3884429&gross_price=true&CMP=KNC-GDE-FDE-GEN-LISTINGS-SEPO-ATMEL&mckv=gnjKZRrt|pcrid|33492810667|plid|&gclid=CO7pgaC5jL0CFQcTwwod0n4ANg) ?

    Or is it possible to put the code directly? You use the Arduino only as a programm interface?

    Best Regards
    Felix

  45. Felix says:

    Where can I get the right and ?

    I’ve I can build the electronic, i will send you the files to make the woodwork by CNC-Router.

    Greetings!

  46. Bogdan says:

    IF you do not want to make a board just buy a Arduino mini pro on ebay for like $4

    • Vladimir says:

      Hi Bogdan
      Have you implemented this project with Arduino mini pro?
      Could you please show me the scheme of connection?

  47. Igor says:

    someone could do with the Arduino one? could send a photo of the connections of the servos. and tips about the voltage and if you used a mosfet or not. Thank in advanced. Any help will welcome.

    • Bogdan says:

      It says in the Schematic diagram: what pins to connect to.
      Mosfet is to save battery. Eg. turn of servos when not in use.

  48. bob R says:

    Pretty slick! I don’t have the stuff to make the PCB… but I have everything else… I think I will pick up a proto board and give this a shot! Very cool.

  49. Jack says:

    Clever diode trick for the microcontroller voltage.

  50. Tommy JL says:

    How would I wire the servos if I just wanted to use an UNO, two servos, and a 5 volt power supply from the wall? I see the signals from the servos go to pins 12 and 13, the switch goes to pin 2 with a 470 Ohm resistor. I take it the servo ground wires would go to the GND pin and the servo power wires would go to 5v pin and the switch, correct?

  51. Linor says:

    What is that box you used? Is that something you made yourself, or did you use a sigar box or something similar? I like how it doesn’t seem to show the opening door (at least on the video) and just looks like a box with a switch on top.

    • arvid says:

      Hi.

      I made it myself. I used small wood sticks, glue and a lot of sanding. And yes, it was one of my intensions to make it look like there is no lid when it’s closed.

      Best Regards
      Arvid

  52. v says:

    Hello,

    when I try to compile the code I get this errors:

    UselessMachine:109: error: ‘BODS’ was not declared in this scope
    UselessMachine:109: error: ‘BODSE’ was not declared in this scope

    Any ideas how to solve that?

    Thans!

  53. Nickcat says:

    I’m trying to build this with ATmega8 instead of Atmega328 and got stuck at the code.
    I used Arduino IDE then i choose “Tool -> Board ->Arduino NG or w/ Atmega8″ to compile the code. I got this message

    “UselessMachine:61: error: ‘EICRA’ was not declared in this scope
    UselessMachine:62: error: ‘EIMSK’ was not declared in this scope
    UselessMachine.ino: In function ‘void loop()’:
    UselessMachine:110: error: ‘PRR’ was not declared in this scope
    UselessMachine:111: error: ‘BODS’ was not declared in this scope
    UselessMachine:111: error: ‘BODSE’ was not declared in this scope
    UselessMachine:113: error: ‘EIMSK’ was not declared in this scope
    UselessMachine.ino: In function ‘void __vector_1()’:
    UselessMachine:167: error: ‘EIMSK’ was not declared in this scope”

    I think there is a problem with sleep mode on Atmega8, maybe it’s different. Is ther any solution for this ?

    • arvid says:

      Hi. Not sure. Haven’t worked with Atmega8 before. But your’e probably right.

      • Nickcat says:

        Can you explain the code in detail for me, maybe it will be a little help.

        pinMode(8, OUTPUT); // It’s mean INT0 as output
        pinMode(2, INPUT); // switch will trigger the int
        digitalWrite(2, HIGH); // when it’s LOW so u have to made it HIGH

        delay(600);
        digitalWrite(8, HIGH); // why here is HIGH
        delay(300);
        digitalWrite(8, LOW); // then LOW

        DDRC = 0; // i dont understand from there, please help.
        PORTC = 63; // Where i can read about this

        //External interrupt INT0
        EICRA=0; //here also
        EIMSK=1;

        And a whole code there :
        //Set sleep mode, turn off MOSFET and servos
        set_sleep_mode(SLEEP_MODE_PWR_DOWN); // this is the most saving energy mode
        sleep_enable(); // then enable it
        pinMode(12, INPUT); // why set this pin input and high there
        digitalWrite(12, HIGH);
        pinMode(13, INPUT);
        digitalWrite(13, HIGH);
        PRR = 255; // I need expain form there too
        MCUCR |= (1<<BODS) | (1<<BODSE);
        MCUCR &= ~(1<<BODSE);
        EIMSK=1;
        sleep_mode();
        // ZZZzzz…
        sleep_disable(); //Awake again…
        PRR = 0;
        pinMode(12, OUTPUT);
        pinMode(13, OUTPUT);

        Thank you.

  54. Greg says:

    Great project – going to start building it now.

    There is a typo I picked up in the code (from the link)

    PORTC = 63;
    .
    //External interrupt INT0

    The period shouldn’t be there.

  55. FHauser says:

    Awesome!
    I’m trying to build this using an Arduino Mega 2560 (is the board I use for experimenting). The code (once removed that missing period) doesn’t even compile. I have to comment out some code on the setup:

    ****************************
    else
    {
    //Set sleep mode, turn off MOSFET and servos
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    pinMode(12, INPUT);
    digitalWrite(12, HIGH);
    pinMode(13, INPUT);
    digitalWrite(13, HIGH);
    //PRR = 255;
    //MCUCR |= (1<<BODS) | (1<<BODSE);
    //MCUCR &= ~(1<<BODSE);
    //EIMSK=1;
    sleep_mode();
    //ZZZzzz…
    sleep_disable(); //Awake again…
    //PRR = 0;
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    }
    boxon=digitalRead(2); //If pin 2 is low, box is on and bonxon=flase
    }

    *****************************

    I've read that it has something to do with the board you are using… does somebody have the equivalent code for my original arduino?

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>