Detecting coin weight

In some cases, each coin has a unique weight. From this scenario, we can detect the kind of coin that the user enters into a vending machine. There are many weight sensors with various specific precision features.

The digital weight sensor Gravity, from DFRobot, is one weight sensor that you can use for your vending machine. You can buy this product from https://www.dfrobot.com/product-1031.html. This sensor is a complete kit so you can use it directly with your Arduino board. You can see this sensor here:

It uses an HX711 IC to measure object weight. You can buy the HX711 module and load cells of different models. For instance, you can use the HX711 module from SparkFun (https://www.sparkfun.com/products/13879) and a load cell from SparkFun (https://www.sparkfun.com/products/13329 and https://www.sparkfun.com/products/13332). You can see an HX711 module, called a Load Cell Amp, here:

For demonstration, we'll try to measure coin weight using DFRobot's Gravity sensor on an Arduino board. Based on its documentation, we can connect Gravity to Arduino through analog inputs with the following wiring:

  • Sensor DOUT pin to Arduino A2 pin
  • Sensor SCK pin to Arduino A3 pin

You can see the complete wiring here below:

Source: image from DFRobot (http://www.dfrobot.com)

The wiring needs an I/O expansion shield for the Arduino (https://www.dfrobot.com/product-1009.html) in order for the digital weight sensor to be attached, but you can connect this weight sensor to the Arduino directly. Connect the sensor DOUT and SCK pins to Arduino Analog A2 and A3 pins.

After completing the hardware wiring, we need some coins for testing. In this case, I'll use three coins: 1 euro, 50 euro cents, and 20 euro cents. You can see my wiring and euro coin samples here:

Now we can write a sketch program to measure the coin weight. You can open your Arduino IDE to write the sketch program. To access the HX711 IC on Arduino, we need an additional library that you can download and extract from https://github.com/aguegu/ardulibs/tree/master/hx711. Put this library as the Hx711 folder inside the Arduino libraries folder. You can see the HX711 library on my computer here:

We develop a sketch program to measure object weight. We'll call it getGram() since it gets object weight in grams. Write the following program:

// Hx711.DOUT - pin #A2 
// Hx711.SCK - pin #A3 
 
#include <Hx711.h> 
Hx711 scale(A2, A3); 
 
void setup() { 
  Serial.begin(9600); 
} 
 
void loop() { 
  Serial.print("Coin: "); 
  Serial.print(scale.getGram(), 1); 
  Serial.println(" g"); 
  delay(500); 
} 

Save and upload the program to your Arduino board. Then you can open the Serial Monitor tool from Arduino to see the program output.

Make sure you put the load cell in the correct position. You can see my load cell here:

You can see the current object's weight in the Serial Monitor tool. At first, you'll see approximately 0 grams. Then, try putting a coin onto the load cell. You can note the total weight before and after measurement. You can also can perform a calibration on the sensor.

Based on my experiments with the digital weight sensor from DFRobot and Euro coins, I have the following results:

Coin model

Weight

Original weight

1 euro (€1)

6.7 grams

7.5 grams

50 euro cents (€0.50)

7.1 grams

7.8 grams

20 euro cents (€0.20)

4.5 grams

5.74 grams

To improve accuracy, we can make calibrations or change the measurement box. Since the sensor has a weight range of 1 kg, we may change a load cell with a low weight range to enhance our measurement.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.73.125