Arduino: Gladiator killer thumb

Output with servo motor, pietzo and 2 leds. Idea is that when you change the position of potentiometer, sound begins and led lights up. If thumb goes up, green light turns on, if thumb goes down red light goes on. Sound also differs between up and down.

Tools and components:

Components:

Arduino UNO 3.0 (basicly any Arduino fits)

Potentiometer

Pietzo

2 leds, red and green

Servo motor

1 resistor 1k OHM

USB-cable

several jumper wires

Tools:

I used Arduino IDE for coding and to insert my codes to arduino.

Code using basic librarys

Servo.h and pitches.h (pietzo):

#include <Servo.h> 
#include <pitches.h>

Servo myservo;
int led1 = 10;
int led2 = 11;
int soundPin = 9;

void setup() {
  Serial.begin(9600);
  myservo.attach(13); 
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop() {
  int potentiometervalue = analogRead(A0);
  potentiometervalue = map(potentiometervalue, 0, 1023, 0, 180);
  Serial.println(potentiometervalue);
  delay(10);
  myservo.write(potentiometervalue);
  delay(15);
  if(potentiometervalue < 30 ){
    digitalWrite(led1, HIGH);
    tone(soundPin, 440, 10);

  } 
  else{
    digitalWrite(led1,LOW);
  }
  if(potentiometervalue > 150){
    digitalWrite(led2, HIGH);
    tone(soundPin, 880, 10);
  } 
  else{
    digitalWrite(led2,LOW);
  }

}

Cabling of breadboard + Arduino:

Untitled Sketch_bb

Video of the result:

Testing servo manual configuration

Here is just a small testing about servos manual configuration. We had minimum value of about 500, mid value 1450 and high value 2400. Code is from Tero Karvinen Book, Make Arduino Bots and Gadgets. More from teroterokarvinen.com.

int servoPin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(servoPin, OUTPUT);
}
void pulseServo(int servoPin, int pulseLenUs)     
{
  digitalWrite(servoPin, HIGH);
  delayMicroseconds(pulseLenUs);
  digitalWrite(servoPin, LOW);
  delay (50);
}

void loop() {
  for (int i = 1; i<=3000; i=i+2){
    pulseServo(servoPin, i);
    Serial.println(i);
  }

}

Info:

Computer:

Lenovo ThinkPad Twist

Operating System:

Windows 7 64-bit Professional, Service Pack 1

Resources:


Leave a comment