The Petanquemeter

5.6K279

Intro: 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!

Mistakes:

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 :)

9 Comments

I am thinking of designing a simular device, using a pipe that can be sitated over the cochonet (internal dia >25 mm) and at the outside a VL53LOX. On top of the pipe a smal box is loated wit mpu6050, a display and Anduino. You turn the pipe so that the disatance to the other ball can be measured. With help of the mpu6050, you make the pipe exactly vertical. After this you push the measuring buton (compare with height measuring device for a child ) Do you think this is better or worse? (Android has a similar device in the smartphone, where you can take a picture of the situation and let the smartphone measure. But even paid apps work use too much install time.

I don't know if it is better or worse, but anyway it is quite interesting and worth give it a try! ;) I guess it depends on your skills and your knowledge about the VL53LOX and mpu6050. Did you already make projects with these modules? I have never used them, but after a quick research on the internet, the VL53LOX seems to be much better than the ultrasonic sensor I have used. About the mpu6050, it seems more complicated to use as I suppose you will have to add some motors to keep the pipe vertically...

Upload a picture and add a comment when you're done with this project, I'd be interested to see how you made it and how it works!

Dear Matlek. I do not have Experience with the 2 devices. I know about Arguilo only since a couple of weeks. I am a petanqueplayer and I know that a lot of my petanquefriends hate it to go on their knees to measure (especially the wifes). Therefor I was thinking of using a stick of say 1,2 m length with a flat box at the top . In this box we find the arduino, the mpu6050 and a display a button and eventual some leds. The inner dia of the pipe is just over 25 mm, so it goes over the but. Problem is to have the stick exactly vertical, so that you do not measure the distance at 2 mm above the ground, but at say 35 mm. Look in the (free) appstore of Google and find several meters. I never succeeded in using them, it takes to much time.
I got the idea looking at following project http://www.electronics-lab.com/using-vl53l0x-arduino-measure-height/ . Sorry Matlek, the project only exists in my 70 year old brains. Keep me posted!!

Your project is very interesting, and if you have time and motivation I would suggest to build it ;) But as I said before I cannot help you because I have no idea about these module and I don't know how it will react in the configuration you want to build it (the box on the stick).

But before you start:

If you are not confident with these modules and the Arduino board, it might take a lot of time and you have to be aware of this. It took me few weeks to build mine, because I had to learn how the arduino board works, and how to make the program to control it. Also, it might not work as expected at the end but don't be disappointed! To finish, even if you spend a lot of time on your project, and it does not work as expected, you will have new skills in these fields, that is why it worth give it a try!

Keep me posted!

By the way, where are you from?

Matlek

Good idea but unfortunately it's very difficult to get a repeatable reading from a spherical object and to get a measurement to the nearest milimeter you need to get everything sorted in less than 5μs - repeatably.

Sensors must be on the same plan as the equator of the balls. Measures can be repeated several times while turning the sensors until the smallest is read.

Yes, that is exactly how it works. However I'm not sure the ultra sound beam hits the equator of the balls...

I was also thinking to add a motor to rotate the sensor. The sensor records the distance for each step of the motor, for 180° for example. At the end, the 2 smallest distances are printed on the LCD screen, and it should correspond to the 2 nearest balls (if there is no other object on the playground). As a control, a ring made with LEDs centered on the jack could verify that the objects correspond to the balls. The LED pointing in the direction of the 1st ball is blinking, the LED pointing in the direction of the 2nd ball lights continuously.

Did you try the google app? It works, but if I want to use it and have the app working, somebody is already on his knees. A rotating beam might be a solution. A question to Matlek: Does the device work in a competition f.i? Do you think the measuring device I proposed gives better results?

I have tried the app "mMesure" form the famous petanque brand "Obut", but indeed it takes time to use and it does not give the distance between the objects but just the some numbers according to the position (closest ball is mentioned 1, the second 2, etc...). I have no idea about using such devices in competition, but I think it is not allowed. To be sure the device you proposed gives better results I suggest to simply try the VL53LOX, and make sure it fits for measures on petanque balls. That was one of the mistake I made, I did not try on the petanque balls before to build it (I tried on a glass, but it is different...), and the result was a bit disapointing.