ARDUINO meets PROCESSING

Switch


navigation

To build the electronic circuit you need the following parts:

The schematic for the circuit looks like this:

scheme for switch circuit

Switches have three pins. In one position the switch closes the connection between the middle pin an outer pin while the opposite position establishes a connection between the middle pin and the other outer pin. Therefore, we connect 5V to one of the outer pins and the 1kΩ resistor to the middle pin and ground. We will measure 'between' the middle pin and the resistor and therefore have a wire leading from there to pin 7 of the Arduino board. The circuit on your breadboard should look something like this:

picture of switch circuit

If everything is set up right, you can connect the board to the serial (or USB) port of your computer and, if necessary, to the power supply. The power LED should light up and the next step is to export the program which reads the state of the switch to the board. Open the ap_ReadDigital.pde file in Arduino, set the right serial port and baudrate, compile the program, and then press the reset button on your board and click on the export icon to send the program to the board.

To check if everything works fine so far, see if the control LED lights up when the switch is in ON-position. If that's the case, you can then download and unzip pa_Switch.zip and open the file pa_Switch.pde in Processing. Again, you will have to set the right serial port, which you do by editing the variable portname. Eventually you will also have set the correct baudrate by editing its variable (baudrate).

Now, you can run your Processing program. A new window will open and you should see something like this:

From the middle a red (or blue) bar will start growing to the right (or left), depending on the position of the switch. If you change the position of the switch, the other bar will start growing and when both bars are of equal size they will both turn green. Play around a little bit and you will see that rhythmic switching will maintain the bar green, isn't that great?