Joy It pressur sensor to Arduino uno <3

Hey!
I'm fairly new to arduino and coding in general. I thought I'd get the hang of it quicker but now I have a deadline coming up and I dont know how to complete it in time so any help would be great!

I'm connecting a Joy-it 20kg to an arduino uno. I want it to light up an LED, ideally multiple LEDs depending on the weight. Eg. 0-5kg = red LED light up, 5-10kg = yellow LED light up, 10-20kg = green LED light up. I've done this project previously but with a DIY pressure plate (essentially when two charged copper plates touch the pressure is detected) and it worked out well, i just want to make the next prototype more technical.

This was my previous code (DIY pressure plate);

const int touchPin = 2; // Pin connected to the touch sensor
const int ledPin = 13;  // Pin connected to the LED

void setup() {
  pinMode(touchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(touchPin, HIGH); // Enable internal pull-up resistor if not using external pull-up resistor
}

void loop() {
  int touchValue = digitalRead(touchPin);

  if (touchValue == LOW) { // Touch detected
    digitalWrite(ledPin, HIGH); // Turn on the LED
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED
    }
}

Any help with code and the layout of the breadboard/arduino is more thank welcome!

Thank you in advance :slight_smile:

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

thanks!

Please edit your original post and add the code tags

The Joy-it is analog out so your code will never work.
What is the Joy-it part number?
Is it the sensor or the load cell bar?

I got an analog to digital converter! forgot to mention that.

Article number of the sensor is:
SEN-Pressure20
or you can just see it here,
Products | Joy-IT emphasized text

Any other information you care to share before we move forward? Did you download the manual and find the example in Sec 5.1?

at the moment I've got;

  • +60 powerrail bread board
  • 3 LEDs
  • A varity of resistors (shouldn't be a problem)
  • 8 wires with vairty of female/male ports
  • Arduino Uno (not R3 or anything it just says arduino uno).
    If i need more things I can get it tomorrow

And for sec 5.1. I dont have the manual with me, my uni doesn't have many so they don't give them out freely :confused:

From the link you provided, download the manual, either English or German.
Section 2 has graphs and a formula. Section 5 has examples


An Op Amp with a gain of 10 would be handy but not required for what you are doing

i really appreciate your help! but i might be going insane, what link are you refering to?

You shared a Joy-it link in Post #6. Open that link. Scroll down until you see the image I posted in Post #9. Click on "SEN-Pressure Manual" in the language of your preference.

Using the lower right graph and provided formula, I calculated
5kg > about 0.18V out
10kg > ~ 0.29V out
20kg > ~0.425V out

Amazing! got the manuals now, thanks! Connected G to GND, V to 5V and S to A0

Run the code and see what displays on the serial monitor. 20kg should display about 90. 10kg should be about 60

Used the code:

float convertToKg(int sensorValue) {
    float voltage = sensorValue * (5.0 / 1023.0); 

    if (voltage <= 0.18) {
        return (voltage / 0.18) * 5.0;
    } else if (voltage <= 0.29) {
        return 5.0 + ((voltage - 0.18) / (0.29 - 0.18)) * 5.0;
    } else if (voltage <= 0.425) {
        return 10.0 + ((voltage - 0.29) / (0.425 - 0.29)) * 10.0;
    } else {
        return 20.0; 
    }
}

void setup() {
    pinMode(A0, INPUT);
    Serial.begin(9600);
}

void loop() {
    int sensorValue = analogRead(A0);
    float weight = convertToKg(sensorValue);

    Serial.print("Weight: ");
    Serial.print(weight);
    Serial.println(" kg");

    delay(2000);
}

It displays well in the serial monitor!!
Just need to incorporate the LED system on the breadboard

Do you have known weights or means to apply a known force to the sensor to do an end-to-end verification? The numbers I provided are approximations from eyeballing the graph.

Is this for work, school or fun?

Happy to help.
Give me a Solution check and I'll be on my way.

Hey 2112 :slight_smile: thanks sm, i have to do other work rn but will be back on it tmr. Its to measure bottles and cans in a fridge to do an automated stock in-take. It's for a uni project.

Your numbers worked so far :), gonna next sort out the LED light up system. Shouldn't be too crazy, your help really got the ball rolling. Thanks!

Keep in mind the strain gage sensor resistance may decrease in a cold environment. You may need to adjust accordingly

Have Fun

hey! thought i would be one the right track but now having some different issues. If you're still down to help that'll be great!
Joy it 20kg pressure sensor coding/hardware isn't working help!

Did you figure it out?
They slapped you around a bit in your new thread. That should have been continued here.

As pointed out

float convertToKg(int sensorValue) {
    float voltage = sensorValue * (5.0 / 1023.0); 
}

is lacking. You had it correct above.

Create another function to control the LEDs. Maybe add

if (weight <= 5.0) {
        digitalWrite(redLED, HIGH);
        digitalWrite(yellowLED, LOW);
        digitalWrite(greenLED, LOW);
    } else if (weight ........