Processing quiz

Hello Everyone !

I have a project with my university, i have to create à quizz which you can chose the answer by using Arduino button. For the moment i can’t send the stat of my button to processing and i dont know why.

Arduino :

int bouton = 4;

void setup() {

  pinMode(bouton, INPUT);             // Set pin 0 as an input
  Serial.begin(9600);                    // Start serial communication at 9600 bps

void loop() {
  if (digitalRead(bouton) == HIGH) {  // If switch is ON,
    Serial.println("oui"); // send 1 to Processing
  } else {                               // If the switch is not ON,
    Serial.println("non"); // send 0 to Processing

Processing :

import processing.serial.*;
int val;
Serial myPort;  // Create object from Serial class

void setup()

  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
  String myPortName = Serial.list()[0];

void draw()
  if ( myPort.available() > 0) {
    val =;
  if ( val == 1) {
    fill(127, 0, 0);
  } else {
    fill(255, 200, 200);


What are you fill() ing?

There are lots of resources and examples here:


1 Like

Hi @Rayenblue, I can see that you started with the Processing example ‘SimpleRead’. This does work, I’ve just tried it, but there are ways that it can be messed up. You’ve added some println to see if the Arduino is working. There’s a conflict here because those prints are also going to Processing and confusing things. You want only the 1 and 0 to go to Processing. Once you’ve seen the Ard prog is working (you’re using the serial monitor?), please remove them all. (We’ll talk about how to have both later.)

Are you sure your Processing is connecting to the port? Don’t have the Serial Monitor running when you start your Processing sketch. Do you have the com port name correct? Suggest you use this line
myPort = new Serial(this, “COM13”, 9600);
instead of the serial.list[] method. Change the port name to same as in the Ard IDE.

See if those 2 fix it, let us know…

1 Like

Thank you for your replay !

But unfortunely that didn’t work , i removed Serial.print and try your methode on Process, can you explain me what do you mean when your say " Are you sure your Processing is connecting to the port?", becauce I sucessed to send text .

I use your command “myPort = new Serial(this, “COM3”, 9600);” .

Hello @Rayenblue,

If you are in fact connecting you need a shape to fill() !
Your code is missing one.

You could also add:

val =;

This will show all the extra characters you are sending; you are sending '0' or else… the else is all the extra characters from your Serial.print() statements.

What does this (below) display on your console?

My Arduino is on “COM6” so I would use:

  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);

Have fun!



1 Like

@Rayenblue Yes, from your IDE image COM3 is the correct name. I would use it direct. The list()[] method works but the list can change if any other devices are added/removed. Is your Arduino a real one? The cheap Chinese ones take a different COMn number in different USB sockets.

Have you added the print as @glv said? Is anything printing?

The Ard sketch only sends every 100 mS. If you press and release the button quickly it may happen within 100 mS and be ignored. I think for the quiz you will find it too slow to react. The 100 delay at the end of the Ard sketch is too big. Suggest you change it to 40 mS. You could go less but it must be greater than the loop delay of the Processing, and we don’t know that yet. Once you get it working I think we should alter the Ard sketch to send on change, and on a slow frequency.

1 Like


Awesome ! Now i am sure that arduino is well connecte but my condition is still not working.

1 Like

Thank you @RicharDL, my arduino is not a fake and my COM is the good , i add @glv code ( thank you :star_struck: :star_struck: by the way) and it show me values. 40 ms was a very good call , thank you again.

1 Like


Thank you ,it’s work know !

Now the real challenge can begin


Have fun!

There are lots of topics related to serial communication.
It gets easier…

If you need further assistance ask.


1 Like