Or, Pacman - three ways.
This Instructable includes:
- Using an adjustable resistor as input to the Arduino Micro-controller
- Controlling two servo motors from the Arduino
-Controlling animation on the computer from the Arduino
Here are the basic steps:
- Servo control with Arduino and potentiometer
- Replace potentiometer with a flexible sensor
- Create animation on the computer screen
- Setup communication between the computer and Arduino
- Mount everything in a usable way and test it out!
Here is a good book for learning arduino:
Programming Arduino Getting Started with Sketches
Here is an arduino starter kit on amazon:
Starter Kit for Newsite Uno R3 - Bundle of 6 Items: Newsite Uno R3, Breadboard, Holder, Jumper Wires, USB Cable and 9V Battery Connector
There are videos, photos, and code along the way.
Remove these ads by
Signing UpStep 1: Servo Code for Arduino
-two servos
-opposite angles
-Pot input
////////// Arduino Code ///////////////
//This is from an example inluded with Arduino IDE download.
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
//MPC - added serial output 'n stuff
/*
Here is the wiring:
Wiring -
|------Arduino Gnd
Encoder |------Analog 0
|------Arduino 5V
| Yellow ------ Digi 9 (PWM)
Top servo | Red -----------5V
| Brown -------Gnd
| Yellow ------ Digi 10 (PWM)
Bottom servo | Red -----------5V
| Brown ------
*/
#include < Servo.h >
Servo myservo; // create servo object to control a servo
Servo otherServo ;
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int valComp;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
otherServo.attach(10);
Serial.begin(9600);
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
valComp = analogRead(potpin);
Serial.println(val);
val = map(val, 0, 1023, 90, 179); // scale it to use it with the servo (value between 0 and 180)
valComp = map(valComp, 1023, 0, 0, 90);
myservo.write(val); // sets the servo position according to the scaled value
delay(15);
otherServo.write(valComp);
delay(25); // waits for the servo to get there
}













































Visit Our Store »
Go Pro Today »




Really enjoyed it!
Just trying to think of what else could be done with it!