3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

A Little Switch and Potentiometer Box for Your Arduino

Step 3Programming & Testing

Programming & Testing
You can use your switch box in any way you like. What is included here is a small Arduino program that polls the Switch Boxes state and sends it over its USB connection to a computer (once every 100 milliseconds). Also there is a small program written in Processing to display the state of the box. The code is all highly commented to hopefully make jumping in and making changes easy.

To get it up and running.

Arduino:
Option 1: (download and unzip)
  • Download the file ( 07-POTB-Arduino-SerialSwitch.zip ) from below and un-zip it into your Arduino folder. (default My Documents\Arduino\)
  • Open it in the Arduino development environment and download it to your Arduino.

Option 2: (copy and paste)
  • Copy the text of the Arduino program (from below (Appendix 1)
  • Open up the Arduino development environment. Paste the text and upload it to your board.

Processing Program
Option 1: Download an exe
  • Download the attached zip file ( 07-POTB-Processing Switch Watcher (windows exe).zip ).
  • Unzip it anywhere on your computer.
  • Run _POTB_SwitchWatcher.exe.

Option 2: Download Processing Source
  • Download the attached zip file ( 07-POTB-Processing Swtch Watcher (source).zip ).
  • Unzip anywhere on your computer.
  • Open ( _POTB_SwitchWatcher.pde ) in the Processing development environment, and run and edit to your hearts content.

To Run
  • Start the program.
  • Click on the Comm port your Arduino is attached to.
  • Watch the dials spin whilst you spin yours.

Appendix 1: Arduino Code
      /* * Potentiometer and Switch Box (POTB) - Serial Updater * For more details visit: http://www.oomlout.com/ *  * Behaviour: Will feed the state of the 5 plugged in               potentiometers and three switches to a connected              PC every 100 ms.  * * Wiring: Twist Potentiometer (01) - analog 1 *         Shoulder Potentiometer (02) - analog 3 *         Elbow Potentiometer (03) - analog 2 *         Wrist Potentiometer (04) - analog 4       *         Gripper Potentiometer (05) - analog 0 *         Switch 1 - pin 02 *         Switch 2 - pin 03  *         Switch 3 - pin 04 *          * License: This work is licenced under the Creative Commons  *          Attribution-Share Alike 3.0 Unported License. To  *          view a copy of this licence, visit  *          http://creativecommons.org/licenses/by-sa/3.0/  *          or send a letter to Creative Commons, 171 Second  *          Street, Suite 300, San Francisco, California 94105,  *          USA. *         */  //-------------------------------------------------------------------------//START OF POTENTIMETER BOX PREAMBLE//Defining constants corresponding to the pin each Potentiometer is plugged into //change to whatever you are using them for#define TWIST_POT 1      #define SHOULDER_POT 3   #define ELBOW_POT 2      #define WRIST_POT 4#define GRIPPER_POT 0    //Defining constants corresponding to the pin each Potentiometer is plugged into //change to whatever you are using them for#define SWITCH_1 2#define SWITCH_2 3#define SWITCH_3 4//Gets everything up and runningvoid setup()                  {  Serial.begin(9600);                //Starts the serial port  potbSetup();                       //sets the state of all neccesary                                      //pins and adds servos to your sketch}//The main program loopvoid loop()                     {  potbSendData();             //sends the current switch and potentiometer data  delay(100);                //waits 100 ms}//------------------------------------------------------------------------//START OF POTENTIOMETER AND SWITCH BOX (POTB) ROUTINES/* * sets up the appropriate digital inputs and outputs for your potentiometer * and switch box*/void potbSetup(){  pinMode(SWITCH_1, INPUT);          //sets the switch one pin to input  digitalWrite(SWITCH_1, HIGH);      //turns on the internal pull up resistor                                     //(this means it will read high when off and low when on   pinMode(SWITCH_2, INPUT);          //sets the switch one pin to input  digitalWrite(SWITCH_2, HIGH);      //turns on the internal pull up resistor                                     //(this means it will read high when off and low when on   pinMode(SWITCH_3, INPUT);          //sets the switch one pin to input  digitalWrite(SWITCH_3, HIGH);      //turns on the internal pull up resistor                                     //(this means it will read high when off and low when on }void potbSendData(){  Serial.print("POTB Data");  Serial.print("%SWITCH_1=");  Serial.print(getSwitchData(SWITCH_1));  Serial.print(" %SWITCH_2=");  Serial.print(getSwitchData(SWITCH_2));  Serial.print(" %SWITCH_3=");  Serial.print(getSwitchData(SWITCH_3));  Serial.print(" %TWIST_POT=");  Serial.print(getPotData(TWIST_POT));  Serial.print(" %SHOULDER_POT=");  Serial.print(getPotData(SHOULDER_POT));  Serial.print(" %ELBOW_POT=");  Serial.print(getPotData(ELBOW_POT));  Serial.print(" %WRIST_POT=");  Serial.print(getPotData(WRIST_POT));  Serial.print(" %GRIPPER_POT=");  Serial.print(getPotData(GRIPPER_POT));  Serial.print(" ");    Serial.println();}int getPotData(int potNumber){  return analogRead(potNumber);}int getSwitchData(int switchNumber){ return digitalRead(switchNumber); }  //END OF POTENTIOMETER AND SWITCH BOX (POTB) ROUTINES//---------------------------------------------------------------------------
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
408
Followers
14
Author:oomlout