Wireless Switch for Processing




This is an instruction using a wireless pushbutton to control your processing sketch.

Step 1: Prepare Supplies

1. Hardware: 2 Xbee modules, Xbee dongle and shield, arduino board, Push button, 10k ohm resistor, 9v battery or usb power bank.

2. Software: Arduino(www.arduino.cc), Processing(www.processing.org), XCTU.

Step 2: Configuration

1. Download XCTU: https://www.digi.com/products/xbee-rf-solutions/x...

2. Label on Xbee modules: One is a sender and the other is a receiver.

3. Connect a Xbee dongle to your computer and press the "+" button left upper side. You can see all details of your xbee modules. You should check three elements, ID, DL and MY.

4. ID have to be identical for both Xbee modules.

5. ID and MY have to be crossing symmetry. For an example, the sending module(#1)'s DL is 5678, MY is 1234 and the receiving module(#2)'s DL is 1234, MY is 5678.

6. Press the 'Write' button which is a pencil icon on it.

Step 3: Wiring a Push Button.

1. Put one end of a 10K resistor to the 5v pin and the other end to a breadboard.

2. Put a wire of your pushbutton wire in the same row of the resistor on the breadboard. Put the other wire to the ground pin.

3. Connect a wire from a pin of the pushbutton and resistor low to your arduino board digital #7 pin.

4. If you don't want to use a breadboard you can solder them on the Xbee shield.

Step 4: Arduino Code

1. Set a slide switch of a Xbee shield to DLINE to upload program

2. There is a code.

int buttonPin = 7; //Connect a push button or any digital sensors.

int buttonState = LOW;

int lastButtonState = LOW;

long lastDebounceTime = 0; // the last time the output pin was toggled

long debounceDelay = 50; // the debounce time;

void setup()


pinMode(buttonPin, INPUT);



void loop()


int reading = digitalRead(buttonPin);

if (reading != lastButtonState)


lastDebounceTime = millis(); // reset the debouncing timer


if ((millis() - lastDebounceTime) > debounceDelay)


if (reading != buttonState) // if the button state has changed:


buttonState = reading;

if (buttonState == HIGH)






lastButtonState = reading;


3. After uploading the code, change the switch status to UART

Step 5: Processing Code

import processing.serial.*;

Serial xbee;

void settings()


fullScreen(P2D, 2);


void setup()



xbee = new Serial(this, Serial.list()[5], 9600);


void draw()

// Do something here!!


void serialEvent(Serial xbee)


int val = xbee.read();

if (val == 'H')


// Do something here!!





    • Gardening Contest

      Gardening Contest
    • Arduino Contest 2019

      Arduino Contest 2019
    • IoT Challenge

      IoT Challenge



    2 years ago

    Thanks for sharing :)