Sunteți pe pagina 1din 16

5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

Search Maker Pro

Search Maker Pro

Home
Explore

Categories
3D Printing
Amateur Radio
Audio
Augmented Reality
Automation
Automotive
Cloud Computing
Computers & Peripherals
Consumer Electronics
Cyber Security
Displays
Drones
Health & Fitness
Home Automation
Industrial
Industrial IoT
IoT
Lighting
Machine Learning
Mobile
Motor Control
Power
Robotics
Security / Identification
Sensors
Smart Grid/Energy
Telecom
Virtual Reality
Wearables
Weather

View All

Platforms
Linux

Raspberry Pi

Arduino

ESP8266

Custom

PIC

PCB

MicroPython

View All
Projects Education Close Menu

Login

Sign Up

Home
Arduino
Tutorials
How to Make Arduino and Processing IDE Communicate

Arduino

How to Make Arduino and Processing IDE Communicate


https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 1/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

Ali Hamza

1
2
10513

March 21, 2018


Learn how to connect the Arduino to the Processing IDE so they can communicate with one another.

Sign Up

Article
Trending

Monitor a Plant's Soil Moisture Using Netduino and Xamarin


Project

MedUino - Smart Medicine Reminder with Arduino


Project

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 2/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

Create Rainbow Colors with an RGB LED and Netduino


Project

Netduino Pulse-Width-Modulation LED Project


Project

In this tutorial, we will make the communication between the Arduino and Processing. We will make the communication in both the ways, from the Arduino to Processing
and from Processing to the Arduino. We will change the color of the serial window in the Processing IDE through the potentiometer value sent from the Arduino IDE. We
will turn the LED ON and OFF depending upon the mouse button pressed in the Processing Serial window.

About Processing

Processing is a great source for creating graphics. The Processing IDE works for a computer like the Arduino IDE works for a micro-controller. The Processing IDE is
similar to Arduino in terms of structure. It has setup functions and draw functions like an Arduino has a setup and loop function. The Processing IDE can communicate
with the Arduino IDE through serial communication. This way, we can send data from the Arduino to the Processing IDE and also from the Processing IDE to the
Arduino.
https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 3/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro
Installing Processing

If you do not have already installed the Processing IDE, then you need to install it first. To install it, go to the link below and download the latest version of processing
IDE. https://processing.org/download/

After downloading the latest version, open the Processing IDE setup and install it. After installing, open the Processing IDE and you will see something like this.

Arduino Circuit Diagram

The connections for this tutorial are very easy. Connect the two end pins of the 1k potentiometer to the 5V and the GND pin of the Arduino. Then connect the middle pin
of the potentiometer to the A0 on Arduino. Then connect the positive pin of the LED to pin 7 on the Arduino and the negative pin of the LED to the GND pin through the
220 ohm resistor.

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 4/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

How Does It Work?

The Arduino IDE and the Processing IDE will communicate with each other through serial communication. The Processing IDE has a serial library which makes it easy to
communicate with the Arduino.

When we move the potentiometer knob, the Arduino will send a value between 0 and 255 to the Processing IDE. The Processing IDE will then change the color of the
serial window according to the movement of the potentiometer knob.

Similarly, when we press the mouse button in the serial window of the Processing IDE, the Processing IDE will send a ‘1’ or ‘0’ depending on the left or right mouse
button to the Arduino IDE. The Arduino IDE will then turn the LED ON or OFF according to the button pressed.

Arduino Code

The Arduino Code is very easy; everything is explained in the code.

arduino
Copy

int led_pin = 7; // Initializing the LED pin

int pot_pin = A0; // Initializing the Potentiometer pin

int pot_output; // Declaring a variable for potentiometer output

void setup ( ) {

pinMode(led_pin, OUTPUT); // Declaring the LED pin as output pin

Serial.begin(9600); // Starting the serial communication at 9600 baud rate

void loop ( ) {

pot_output = analogRead (pot_pin); // Reading from the potentiometer

int mapped_output = map (pot_output, 0, 1023, 0, 255); // Mapping the output of potentiometer to 0-255 to be read by the Processing IDE

Serial.println (mapped_output); // Sending the output to Processing IDE

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 5/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

if (Serial.available ( ) > 0) { // Checking if the Processing IDE has send a value or not

char state = Serial.read ( ); // Reading the data received and saving in the state variable

if(state == '1') // If received data is '1', then turn on LED

digitalWrite (led_pin, HIGH);

if (state == '0') { // If received data is '0', then turn off led

digitalWrite (led_pin, LOW);

delay(50);

More

Processing Code

The Processing IDE will accept the data from the Arduino IDE through the Serial communication and will change the color of the serial window according to the data. It
will also send ‘1’ or ‘0’ depending on the mouse button pressed. The Processing IDE has a serial library which makes it able to communicate with the Arduino IDE.

processing
Copy

import processing.serial.*; // Importing the serial library to communicate with the Arduino

Serial myPort; // Initializing a vairable named 'myPort' for serial communication

float background_color ; // Variable for changing the background color

void setup ( ) {

size (500, 500); // Size of the serial window, you can increase or decrease as you want

myPort = new Serial (this, "COM3", 9600); // Set the com port and the baud rate according to the Arduino IDE

myPort.bufferUntil ( '\n' ); // Receiving the data from the Arduino IDE

void serialEvent (Serial myPort) {

background_color = float (myPort.readStringUntil ( '\n' ) ) ; // Changing the background color according to received data

void draw ( ) {

background ( 150, 50, background_color ); // Initial background color, when we will open the serial window

if ( mousePressed && ( mouseButton == LEFT ) ) { // if the left mouse button is pressed

myPort.write ( '1' ) ; // send a '1' to the Arduino IDE

if ( mousePressed && ( mouseButton == RIGHT ) ) { // if the right mouse button is pressed

myPort.write ( '0' ) ; // Send a '0' to the Arduino IDE

More

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 6/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

How to Make Arduino and Processing IDE Communicate

Now that you've learned some basic Arduino programming, you're ready to tackle some more Arduino projects!

as das dasd asda sdas d

Ali Hamza
For custom projects, Contact me at admin@electronicshobbyists.com
Author

Comments (2)

tanhandmedia 5 months ago


1 reply

Thank you! This tutorial clearly taught me everything I needed to know to begin linking these two programs together.

Maker Pro Team 2 months ago

That is great tanhandmedia!

Basak Helvaci 2 months ago

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 7/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro
1 reply

Thanks. It helped me a lot with my project. :)

Maker Pro Team 2 months ago

Thats great to hear!

Comment on this tutorial

Submit

Categories
Sensors
Automation
Computers & Peripherals
Cloud Computing
Lighting

Tags

Arduino
Processing IDE
IDE

Related Arduino Projects & Tutorials

Masterclass Maker Projects | How to Build a USB Volume Knob

Arduino
May 13, 2019

Daniel Hertz
0 0 32

How to Build a Weight Scale With an Arduino

Arduino
April 29, 2019

Reginald Watson
0 0 209

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 8/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

How to Set up an XBee Module with Arduino


Arduino
May 8, 2019

Jonathan Miller
0 0 52

How to Turn an Arduino Into a Keystroke Automation Tool

Arduino
April 26, 2019

Robin Hartley
1 0 279

How to Use a Proximity Sensor With an Arduino Uno


Arduino
May 1, 2019

Jonathan Miller
0 0 156

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 9/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

How to Connect an Ultrasonic Sensor to an Arduino


Arduino
April 25, 2019

Don Wilcher
0 0 219

How to Create Long-Distance Serial Communication Between Arduinos

Arduino
April 30, 2019

Reginald Watson
0 0 240

Smart Home Automated Lights With ESP8266 and Philips Hue (part 2)
Arduino
April 21, 2019

Petr Lukáš
0 0 376

Show Footer

We Are
https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 10/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

We provide a place for makers like you to share your designs, collaborate with one another, and learn how to take your product to market.

Network sites
AllAboutCircuits.com EEPower.com Mikrocontroller.net ElectronicsPoint.com

Categories

3D Printing
Amateur Radio
Audio
Augmented Reality
Automation
Automotive
Cloud Computing
Computers & Peripherals
Consumer Electronics
Cyber Security
Displays
Drones
Health & Fitness
Home Automation
Industrial
Industrial IoT
IoT
Lighting
Machine Learning
Mobile
Motor Control
Power
Robotics
Security / Identification
Sensors
Smart Grid/Energy
Telecom
Virtual Reality
Wearables
Weather
View All

Platforms
Linux
Raspberry Pi
Arduino
ESP8266
Custom
PIC
PCB
MicroPython
View All

Connect with Us

Facebook
Twitter
YouTube
Pinterest

About Us
Contact Us
Write for Us
Help Center

Account

Login Sign Up
EETech Media, LLC. All rights reserved

Privacy
Terms of Service

Top

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 11/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 12/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 13/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 14/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro

Quote of the day

“”
https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 15/16
5/15/2019 How to Make Arduino and Processing IDE Communicate | Arduino | Maker Pro
-

https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate 16/16

S-ar putea să vă placă și