Introduction: The Petanquemeter

Hi guys,

In this article I'll show you my first Arduino project, so be indulgent ;) It helped me a lot in understanding the Arduino board, because it is a project that uses many common sensors and technics (such as the ultrasonic sensor, a push button debouncing, a LCD screen...). It is based on a game called "la pétanque" which I am sure you'll love!

A quick overview:

The petanquemeter is a device that basically tells which player won the party of petanque. It just compares the distances of the "boules" from the "cochonnet", and indicates which one is the nearest.

Here are all the steps:

  • Step 1 : What is "la pétanque"
  • Step 2 : About the project and the initial ideas
  • Step 3 : The material
  • Step 4 : The Arduino and the circuit (part I : the circuit)
  • Step 5 : The Arduino and the circuit (part II : the schematic)
  • Step 6 : The code
  • Step 7 : The shell
  • Step 8 : The shell customization
  • Step 9 : How it works
  • Step 10 : Outside test
  • Step 11 : Comments, mistakes and improvements

Step 1: What Is "la Pétanque"

The "pétanque" is a game that was born is the early 1900s in south of France, very appreciated here! Below is a quick overview of the petanque, but if you want more details go to the wikipedia page of "Pétanque", there are many informations.

The material :

  • 1 tiny wooden ball called the "cochonnet", or jack in english
  • 2 or 3 steel balls (around 750g each) per person

The goal :

The goal is to places the steel balls the nearest from the "cochonnet". You can play individually, or by team.

  • The first player throw the "cochonnet" away (between 6 and 10 meters) from where he is standing (he adds a mark on the floor, and everyone has to stand on this mark when playing). And he plays his first ball to place it as close as possible to the "cochonnet".
  • Then the second player, the third, etc.
  • When each player already played 1 ball, the one that is the farthest plays another ball.
  • And this last step is repeated until everyone has played his steel balls.

The points :

The ball the nearest to the jack gives 1 point to its owner. And all the opponents have 0. If the second nearest ball also belongs to the same player that has the nearest ball, he has 1 more point. The same with the third ball (but the opponents still have 0!). And the parties are played again and again until someone reaches 13 points.

Now you understand better the goal of the petanquemeter: compare the distances from the jack to the balls, and indicate whose ball is the nearest!

The mains technics to play the balls :

You can roll or toss your balls.

  • If you decide to place the ball the nearest to the "cochonnet", it is called "pointer" (pointing in english)
  • If you want to knock away from the jack the ball of one opponent, it is called "tirer" (shooting in english)

Now you are ready to play! But remember to finish reading this article...

Step 2: About the Project and the Initial Ideas

The goal of the project:

The main goal of the project was to learn how to use the Arduino board, as it is my first project. To make it much more interesting, I wanted something useful but also funny. And as I am playing pétanque and we sometimes struggle to find who won the party because the balls are at similar distances, it was the perfect project.

The initial idea:

At first I wanted to create something that can indicate the distances between the "boules" and the "cochonnet". The idea was simple: place the petanquemeter anywhere on the floor at a fix point, rotate it in the direction of each ball and the jack, and record the distances. With a potentiometer placed on the axis of the petanquemeter, I relate the values of the potentiometer with the angles between the object, and I would be able to calculate the position of each object from the others with the law of cosines. But unfortunately the jack was not detected by the ultrasonic sensor (maybe because of its size, its shape and the material it is made of), making the idea useless...

So the solution was to record the distances of the "boules" from the "cochonet". So the second idea was to create a device with a hole of size of the "cochonet" to place the device on it.

Step 3: The Material

Here is a list of everything I have used:

For the electronic part:

  • Arduino Uno
  • a LCD 16x2 + a potentiometer
  • a push button + a 2kOhm resistor
  • an ultrasonic sensor HC-SR04
  • some wires
  • + a power bank and a suitable cable to connect the power ban to the arduino board
  • + a soldering iron and tin

For the shell:

  • Expanded polystyrene
  • Ecological tape
  • + foam cutter

Attached you can see some pictures of the circuit, and on the next page the schematic to make it more understandable.

Step 4: The Arduino and the Circuit (part I : Photos)

Attached you can see some pictures of the circuit, and on the next page the schematic to make it more understandable.

Step 5: The Arduino and the Circuit (part II : the Schematic)

With the Cuircuits Conctest 2016 including a special judges’ prize for the best project that uses any of the three Autodesk Circuits simulators, I decided to give it a try.

It was first quite convincing until I reach the part involving the ultrasonic sensor HC-SR04. As it is not in the component library, I have tried to make it but I got really confused and could not go further (I have check on the internet, but could not find a suitable solution for my problem....).

Therefore I could not perform the simulations... But I have a nice schematic of the project (with an ultrasonic sensor HC-SR04 that has been added later on the picture)!

This image gives a good overview of the circuit, but if you want more information, I have added some in the code you will find on the next page!

Step 6: The Code

You can download the code below. I have commented almost each line to make sure we do not get lost in the code.

I based my code on the examples you can find in the Arduino software (for instance the debouncing), but also examples I found on the internet. Once I have understood each code, I have used some parts, modified some others to get my final program.

Here is basically how it works:

  • The program computes the distance (through the ultrasonic sensor) of the object for each new loop. So the distance is given and refreshed almost in real time.
  • If the push button is pressed, the main loop stops, the program enters a new loop and measures and sums the distance of the object several time. This helps doing an averaged measure so it is more accurate. And it indicates the average distance on the LCD screen for a short period (2 seconds).
  • If the push button is pressed a 2nd time, the program does the same as above, but indicates that this is for object 2.
  • Then the program pauses and show the distances of both object 1 and object 2. And to break the pause, you just need to press the push button. And it refreshes the distances, and starts from zero.

Better idea for the code:

Just before I finish the code I though to a better and more elegant idea. If the push button is press quickly (for example less than 1 second), the program saves a new object (makes the average of the distance and saves the data). And If the push button is pressed for a long time (more than 1 second), the program is paused, and all the objects and the distances are printed on the LCD screens, from the nearest to the farthest for example.

Step 7: The Shell

The main problem of the project was about the case to hold the arduino and the circuit. I have no access to any 3D printer, no access to laser cutter, I have no suitable tools to works with wood, and I live in a tiny apartment...

Something really useful in my case is to work with extruded polystyrene. It is light, cheap, and with a foam cutter it is easy to shape and does not make dust.

So I made the shell with many polystyrene layers.

Here are the main parts to make or keep in mind during the making:

  • a hole, so the device can be placed on the "cochonnet"
  • a ring containing the ultrasonic sensor, so it can be rotated
  • a place in the shell for the battery to power the Arduino
  • a place for the Arduino board
  • a place for all the wires
  • a place for the push button\a place for the screen

Then when all the layers are ready, the layers have to be glued together. Tape and hot glue work great (it is a really cheap way I admit, but it is very easy and fast).

Step 8: The Shell Customization

To cover the shell I used tape again. I first wanted to paint it but I was quite satisfied with the tape so I kept it like this.

And I have added some marks: "Petanquemeter" on the back of the device, and "Oh peuchere" on the front.

Step 9: How It Works

As said previously in step 6 (the code), here are the photos of what is printed on the LCD screen when you press the push button.

Step 10: Outdoor Tests

Here are some pictures of my mates and I playing petanque and using the petanquemeter.

Thanks to my friend Serguei for the photos!

Step 11: Comments, Mistakes and Improvements

Comments about the device:

I am satisfied of the device, I managed the project until the end. Now I am more confident with Arduino boards and I am ready to start new projects. I am not sure I will use it everytime I play petanque because it is a bit big, it requires a battery and it does not work really well... But I will most likely use it for fun, and to impress the opponents!


Sure it is working but... It works from 5cm to 20cm! The ultrasonic sensor works for objects up to 4m, so it does not come from the sensor. The biggest mistake I made here was to test the sensor with another object than a petanque ball BEFORE to continue. I tried with a glass, but I did not take in consideration the material (steel for the ball, glass for the glass), and the shape of the object (cylinder for the glass, sphere for the ball). What is going on is that when the ultrasound reach the ball, they are reflected in all the direction and dispersed... Therefore, the intensity of the ultrasound coming back to the sensor is too low and does not trigger the signal!

Also it seems that there are some mistakes in the code, because the distance does not seem to be exact. I think it comes from the part where the averaged distance is calculated, I will have a look if I build a second version of the petanquemeter.

Improvements that would be interesting:

  • Change the code as explain before: if the push button is press less than one second a new object is recorded, if it is pressed more than one second it stops and all the distances of the objects recorded before are compared.
  • Add a laser to see where the ultrasound beam is pointing.
  • Make the shell with a 3D printer to make it smaller.

If you liked the project, you discovered the petanque and you want to try, or if you have any comment about the project or any advice for my next arduino projects, leave a comment :)

Circuits Contest 2016

Runner Up in the
Circuits Contest 2016

Epilog Contest 8

Participated in the
Epilog Contest 8