The purpose of this project is to predict the approximate weight of items.Tools:
1. Hexabitz Load cell (Strain Gauge) Sensor Module (H26R0x).
2. Hexabitz RGB LED Module (H01R0x).
3. Hexabitz STLINK-V3MODS Programmer Module (H40Rx).
4. FTDI USB to UART Serial cable.
5. Hexabitz Bitz Clamp.
The first step:
We need to connect the forms to each other as shown in the attached figure.
One of the most amazing qualities of Hexabitz units is that they give us the opportunity to choose whatever shape we wish to assemble our units based on this model attached below.
But you can choose any shape you like.
Notes:
1- Since we're using Hexabitz units, this will be a piece of cake. The reason is that modules are supported by many useful and easy to use APIs.
2- You can refer to the Hexabitz website to learn more about the modules and the steps for using the APIs. I will attach the website link at the end.
The second step:
Now, let's walk through the code together.
1. Define the variables used in the code.
The first variable (lock) to ensure that the program will not enter to the same (if) case unless it enters different one.
The second variable (weight) to store the value of the weight placed on the load cell.
int lock=0;
float Weight;
2. To calibrate the load cell in addition to zero weight cell.
The values inside the calibration are from the datasheet of the weight cell.
void UserTask(void *argument){
Calibration(30, 1.9242, 0.0094);
ZeroCal(1);
3. Take the weight values in grams.
while (1) {
weight = SampleGram(1);
4. If the weight is less than 50g, all module RGB LED will be off.
if (weight < 50 && lock != 1) {
lock = 1;
SendMessageToModule(BOS_BROADCAST, CODE_H01R0_OFF, 0);
Delay_ms(100);
}
5. If the weight is between 50g and 150g, the first module RGB LED will be turn red.
else if (weight >= 50 && weight <150 && lock != 2) {
lock = 2;
// color
messageParams[0] = 0;
messageParams[1] = RED;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
}
6. If the weight is between 150g and 250g, the first and second module RGB LED will be turn red.
else if (weight >= 150 && weight < 250 && lock != 3) {
lock = 3;
messageParams[0] = 0;
messageParams[1] = RED;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
Delay_ms(10);
messageParams[0] = 0;
messageParams[1] = RED;
messageParams[2] = 100;
SendMessageToModule(3, CODE_H01R0_COLOR, 3);
}
7. If the weight is between 250g and 350g, all module RGB LED will be turn red.
else if (weight >= 250 && weight < 350 && lock != 4) {
lock = 4;
messageParams[0] = 0;
messageParams[1] = RED;
messageParams[2] = 100;
SendMessageToModule(BOS_BROADCAST, CODE_H01R0_COLOR, 3);
}
8. If the weight is between 350g and 450g, the RGB LED for the second and third module will be turn off and the RGB LED for the first module will be turn yellow.
else if (weight >= 350 && weight < 450 && lock != 5) {
lock = 5;
messageParams[0] = 0;
messageParams[1] = YELLOW;
messageParams[2] = 100;
SendMessageToModule(3, CODE_H01R0_OFF, 0);
Delay_ms(10);
SendMessageToModule(4, CODE_H01R0_OFF, 0);
Delay_ms(10);
messageParams[0] = 0;
messageParams[1] = YELLOW;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
}
9. If the weight is between 450g and 550g, the first and second module RGB LED will be turn yellow.
else if (weight >= 450 && weight < 550 && lock != 6) {
lock = 6;
messageParams[0] = 0;
messageParams[1] = YELLOW;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
Delay_ms(10);
messageParams[0] = 0;
messageParams[1] = YELLOW;
messageParams[2] = 100;
SendMessageToModule(3, CODE_H01R0_COLOR, 3);
}
10. If the weight is between 550g and 650g, all module RGB LED will be turn yellow.
else if (weight >= 550 && weight < 650 && lock != 7) {
lock = 7;
messageParams[0] = 0;
messageParams[1] = YELLOW;
messageParams[2] = 100;
SendMessageToModule(BOS_BROADCAST, CODE_H01R0_COLOR, 3);
}
11. If the weight is between 650g and 750g, the RGB LED for the second and third module will be turn off and the RGB LED for the first module will be turn green.
else if (weight >= 650 && weight < 750 && lock != 8) {
lock = 8;
messageParams[0] = 0;
messageParams[1] = GREEN;
messageParams[2] = 100;
SendMessageToModule(3, CODE_H01R0_OFF, 0);
Delay_ms(10);
SendMessageToModule(4, CODE_H01R0_OFF, 0);
Delay_ms(10);
messageParams[0] = 0;
messageParams[1] = GREEN;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
}
12. If the weight is between 750g and 850g, the first and second module RGB LED will be turn green.
else if (weight >= 750 && weight < 850 && lock != 9) {
lock = 9;
messageParams[0] = 0;
messageParams[1] = GREEN;
messageParams[2] = 100;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
Delay_ms(10);
messageParams[0] = 0;
messageParams[1] = GREEN;
messageParams[2] = 100;
SendMessageToModule(3, CODE_H01R0_COLOR, 3);
}
13. If the weight is between 850g and 1000g, all module RGB LED will turn green.
else if (weight >= 850 && w < 1000 && lock != 10) {
lock = 10;
messageParams[0] = 0;
messageParams[1] = GREEN;
messageParams[2] = 100;
SendMessageToModule(BOS_BROADCAST, CODE_H01R0_COLOR, 3);
}
14. When the maximum weight is reached (greater than 1Kg) , all modules RGB LED will fading (up and down) in green.
else if (weight >= 1000 && lock != 11) {
lock = 11;
// color
messageParams[0] = GREEN;
// mode
messageParams[1] = RGB_DIM_UP_DOWN_WAIT;
// period
messageParams[2] = (uint8_t) (3000 >> 24);
messageParams[3] = (uint8_t) (3000 >> 16);
messageParams[4] = (uint8_t) (3000 >> 8);
messageParams[5] = (uint8_t) (3000);
// wait
messageParams[6] = (uint8_t) (1000 >> 24);
messageParams[7] = (uint8_t) (1000 >> 16);
messageParams[8] = (uint8_t) (1000 >> 8);
messageParams[9] = (uint8_t) (1000);
// repeat
messageParams[10] = 0;
messageParams[11] = 0;
messageParams[12] = 0;
messageParams[13] = 3;
SendMessageToModule(BOS_BROADCAST,
CODE_H01R0_DIM, 14);
I hope you enjoyed reading this article. Follow me if you would like to see more projects in the future. Feel free to write any comments, I will always be happy to help.
- Video link:
Good Luck.
- Hexabitz Company Website
https://hexabitz.com/
Comments