Introduction: Most Useless Lego Tower.
This useless machine uses a Digispark to control the servo.
Before wasting your time, have a look at how it works.
http://www.youtube.com/watch?v=sp4q9Gl0KuU&feature=c4-overview&list=UU53xZEgBce5oEcyNDEIld5w
If you are still interested, let me explain what I did. There are many implementations of a useless machine, some of them are pure mechanical machines which I love, most of them use two switches, some of them use a 555 timer ... and God know how many others.
The Digispark is a development board based on an Attiny85 microcontroller (http://digistump.com/products/1) it is an Arduino like hardware and software implementation. It is cheap and easy to embed in your projects. I decided to use this board instead of the more popular 2 switches, mainly because you have full control of the servo movement; you can decide the speed and the direction at will.
Parts needed.
- Digispark development board (any other Arduino will work as well using the regular servo library)
- DPDT switch, although I only use half of it
- 180 degrees servo, I’m using HiTech HS-422
- Lego structure, although any other will do
- 5v power supply
Before wasting your time, have a look at how it works.
http://www.youtube.com/watch?v=sp4q9Gl0KuU&feature=c4-overview&list=UU53xZEgBce5oEcyNDEIld5w
If you are still interested, let me explain what I did. There are many implementations of a useless machine, some of them are pure mechanical machines which I love, most of them use two switches, some of them use a 555 timer ... and God know how many others.
The Digispark is a development board based on an Attiny85 microcontroller (http://digistump.com/products/1) it is an Arduino like hardware and software implementation. It is cheap and easy to embed in your projects. I decided to use this board instead of the more popular 2 switches, mainly because you have full control of the servo movement; you can decide the speed and the direction at will.
Parts needed.
- Digispark development board (any other Arduino will work as well using the regular servo library)
- DPDT switch, although I only use half of it
- 180 degrees servo, I’m using HiTech HS-422
- Lego structure, although any other will do
- 5v power supply
Step 1: Most Useless Lego Tower. Part 2.
Part 2. Wiring
I don't have the Digispark part for Fritzing, I'll just list the connections.
Arduino Motor Color
---------- ------- --------------
5V 5V Red
Gnd Gnd Black
pin 3 Signal Yellow
Arduino Switch Color Connector
---------- --------- -------- --------------
pin 0 Signal red mid
pin 2 SW Gnd black any end connector
The digispark has only one pin for ground, if you need more than one you'll have to use a regular pin (2 in this case) and set it to 0 (ground) in the setup section.
I don't have the Digispark part for Fritzing, I'll just list the connections.
Arduino Motor Color
---------- ------- --------------
5V 5V Red
Gnd Gnd Black
pin 3 Signal Yellow
Arduino Switch Color Connector
---------- --------- -------- --------------
pin 0 Signal red mid
pin 2 SW Gnd black any end connector
The digispark has only one pin for ground, if you need more than one you'll have to use a regular pin (2 in this case) and set it to 0 (ground) in the setup section.
Step 2: Most Useless Lego Tower. Part 3
Part 3. Arduino sketch.
The digisparks uses a "special" version of the Arduino IDE based on 1.04. Most of the libraries are also special, basically due to the small memory on the attiny85 microcontroller. In this implementation i use the SoftRcPulseOut library which happens to be the attiny85 implementation of the servo library.
-------
#include <SoftRcPulseOut.h>
SoftRcPulseOut myservo; // create servo object to control a servo
#define SERVO_PIN 3
#define switchPin 0
#define gnd 2
#define REFRESH_PERIOD_MS 20
void setup() {
pinMode(switchPin, INPUT); // set switch pin as an input pin
digitalWrite(switchPin, HIGH); // turn on pullup resistor
pinMode(gnd, OUTPUT);
digitalWrite (gnd, LOW); // use this pin as a ground
myservo.attach(SERVO_PIN); // attaches the servo on pin defined by SERVO_PIN to the servo object
myservo.write(5); // tell servo to move to 5 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
}
void loop() {
int val = digitalRead(switchPin);
delayMicroseconds(20);
if (val == LOW) {
myservo.write(145); // tell servo to move to 145 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
} else {
myservo.write(5); // tell servo to move to 5 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
}
}
-------
That’s all folks !!!
The digisparks uses a "special" version of the Arduino IDE based on 1.04. Most of the libraries are also special, basically due to the small memory on the attiny85 microcontroller. In this implementation i use the SoftRcPulseOut library which happens to be the attiny85 implementation of the servo library.
-------
#include <SoftRcPulseOut.h>
SoftRcPulseOut myservo; // create servo object to control a servo
#define SERVO_PIN 3
#define switchPin 0
#define gnd 2
#define REFRESH_PERIOD_MS 20
void setup() {
pinMode(switchPin, INPUT); // set switch pin as an input pin
digitalWrite(switchPin, HIGH); // turn on pullup resistor
pinMode(gnd, OUTPUT);
digitalWrite (gnd, LOW); // use this pin as a ground
myservo.attach(SERVO_PIN); // attaches the servo on pin defined by SERVO_PIN to the servo object
myservo.write(5); // tell servo to move to 5 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
}
void loop() {
int val = digitalRead(switchPin);
delayMicroseconds(20);
if (val == LOW) {
myservo.write(145); // tell servo to move to 145 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
} else {
myservo.write(5); // tell servo to move to 5 degrees
delay(REFRESH_PERIOD_MS); // waits 20ms for refresh period
SoftRcPulseOut::refresh(1); // generates the servo pulse
}
}
-------
That’s all folks !!!