Help create a sensor for my Ostomy appliance

djsfantasi

Joined Apr 11, 2010
9,160
I've drawn another simplified schematic. Note that the yellow tags indicate where you need to connect what to the Pro-Trinket.
bag_sensor.PNG
Note I have drawn in a battery symbol. The Pro-Trinket needs at least 5.5 volts on the positive input, and will take up to 16 V (I am assuming you purchased the 5V version). I guess that you plan on using a 9V Battery to power this. I strongly recommend rechargeable batteries and if they are not too bulky, use 4 - AA batteries.

Also note there are multiple connections to the Gnd connection.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
I've drawn another simplified schematic. Note that the yellow tags indicate where you need to connect what to the Pro-Trinket.
View attachment 88310
Note I have drawn in a battery symbol. The Pro-Trinket needs at least 5.5 volts on the positive input, and will take up to 16 V (I am assuming you purchased the 5V version). I guess that you plan on using a 9V Battery to power this. I strongly recommend rechargeable batteries and if they are not too bulky, use 4 - AA batteries.

Also note there are multiple connections to the Gnd connection.
Thanks again. I really appreciate it.
This has made things slightly easier, I think I'm starting to understand it.
Yep, I bought the 5V version and I'm using a 9V battery for the moment. Just until I get thing running, then will swap it over to AA's.

The multiple connections to ground had me confused for a second, I think it's all good now.
Just need to go and quickly buy a 10K resistor for the sensor. That's the only thing I'm missing out for some reason.
I also think I need to go get different coloured wire - not making things easy for myself by only using limited colours.
Once everything's working I'll clean it up a bit.

I've attached an image for reference, just to check that it's all good. I hope so.

I'm having so much fun at the moment, so mistakes are almost welcomed. Helps me to learn.


EDIT:
Just bought the resistor and wired it into the circuit, however, the bend sensor doesn't activate or change the LED state.
I was just wondering if all my (albeit rather crude) connections are correct or if it's the code that I need to tinker with?

 

Attachments

Last edited:

ebeowulf17

Joined Aug 12, 2014
3,307
I don't see the 180 ohm resistor for the LED. Is it hiding in there somewhere? If it's missing, it maybe could have toasted the LED and/or that output on the Trinket.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
I don't see the 180 ohm resistor for the LED. Is it hiding in there somewhere? If it's missing, it maybe could have toasted the LED and/or that output on the Trinket.
The LED works, when I power on the Trinket, the LED flashes in sync with the LED soldered to the board, then goes off.
My LED has a prewired resistor at the top (notice the little bobble).

Edit:
I've just asked the company I bought them from - the specification for the Resistor is 470 ohms. Is that overkill?
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,160
470 ohms at what voltage? That's the correct value for 9 volts, but you are powering the LED from the 5 volts on the pin. With the larger resistor, there won't be enough current to light the LED.

Use the calibration sketch I provided. As you flex the sensor, you should see the values change. Then,you can intelligently set the range where the LED will turn on. Also, my sketch has a lower range where the LED will flash. But get it to turn on first.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
470 ohms at what voltage? That's the correct value for 9 volts, but you are powering the LED from the 5 volts on the pin. With the larger resistor, there won't be enough current to light the LED.

Use the calibration sketch I provided. As you flex the sensor, you should see the values change. Then,you can intelligently set the range where the LED will turn on. Also, my sketch has a lower range where the LED will flash. But get it to turn on first.
I will try that Sketch now and see what happens.

The reply I got regarding the voltage is:
"The resistance does not change with voltage. However the current driven by the resistor will change. At 12v, it will drive 20mA through the LED." - But yes, powering with a 9V battery via 5V pin.
 

djsfantasi

Joined Apr 11, 2010
9,160
I will try that Sketch now and see what happens.

The reply I got regarding the voltage is:
"The resistance does not change with voltage. However the current driven by the resistor will change. At 12v, it will drive 20mA through the LED." - But yes, powering with a 9V battery via 5V pin.
Of course. But you need to control the current for the LED to operate reliably.
\(Resistance_{currentlimiter}=\frac{(V_{source}-V_{forward})}{Current_{LED}}\)
which is dependent on the voltage supplied.

What concerns me more is connecting the +9V to the 5V pin; it should connect to the Bat+ pin.

Try one of the Arduino demo programs that blink an LED on your Pro-Trinket. The PIN numbers should match (using an LED on pin 13). Let us know if it works.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
Of course. But you need to control the current for the LED to operate reliably.
\(Resistance_{currentlimiter}=\frac{(V_{source}-V_{forward})}{Current_{LED}}\)
which is dependent on the voltage supplied.

What concerns me more is connecting the +9V to the 5V pin; it should connect to the Bat+ pin.

Try one of the Arduino demo programs that blink an LED on your Pro-Trinket. The PIN numbers should match (using an LED on pin 13). Let us know if it works.
Sorry, my mistake - I have my battery connected to the BAT+ pin and to the GRND.
The 5V pin goes to the Flex sensor.
The LED goes to Pin13 and GRND.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
Okay, I've just uploaded the blink sketch to the Pro-Trinket.
Both the red LED soldered to the board and my connected LED are blinking.

Could I theoretically use the soldered LED as my default and do away with the wired in one?

Edit: I also don't think the second sketch will work with the Pro-Trinket as I can't connect it properly via serial. There's a bootlader that works briefly only to upload sketches - not sure it monitors.

Edit 2: IT WORKS! The original sketch works perfectly when plugged in via USB. Both LED's flash.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,160
The pin we've selected to drive your LED is hard-wired to the one on the board. So theoretically use that one; I thought you might want to mount the warning LED elsewhere.

So we've broken down the problem and proved that the Trinket is working and it can drive an LED. Now we want to read the sensor.

As an engineer, I take things very literally. Please describe to me how you've wired the flex sensor. You said,
Al-Khayal said:
I have my battery connected to the BAT+ pin and to the GRND.
The 5V pin goes to the Flex sensor.
The LED goes to Pin13 and GRND.
So what does the second pin of the Flex sensor connect to? Are there other connections to the sensor?
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
The pin we've selected to drive your LED is hard-wired to the one on the board. So theoretically use that one; I thought you might want to mount the warning LED elsewhere.

So we've broken down the problem and proved that the Trinket is working and it can drive an LED. Now we want to read the sensor.

As an engineer, I take things very literally. Please describe to me how you've wired the flex sensor. You said,

So what does the second pin of the Flex sensor connect to? Are there other connections to the sensor?
Sorry to be a pain. I really do appreciate the help.
The board is going to be mounted close to the Ostomy appliance anyway, so might be easier to lose the wires and the LED.

I wonder perhaps whether it's a power issue? Maybe I've wired something wrong.
I attached a picture earlier.
I'm tinkering with the program now to try and get the settings right.

The flex sensor is attached as follows (Flex1 Refers to the first left pin on the flex sensor, whilst Flex2 refers to the right pin on the sensor):
Flex2: 5V PIN
Flex1: A0 + 10K Resistor > GRND

There is one wire from the battery to the GRND pin on the board that intersects midway and has the LED(Cathode) + FLEX(10K Resistor) attached.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,160
Good! Good luck with the calibration sketch. Do you know how to see the sketch's output on the console?

One more item. The flex sensors are directional, that is, they'll change their value when bent in one direction, i.e. forward. But they will not change if bent in the opposite direction, i.e. backward. Test both directions until you can identify the correct direction.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
Good! Good luck with the calibration sketch. Do you know how to see the sketch's output on the console?

One more item. The flex sensors are directional, that is, they'll change their value when bent in one direction, i.e. forward. But they will not change if bent in the opposite direction, i.e. backward. Test both directions until you can identify the correct direction.
Okay, I don't know what I did, but it's now working on batteries.
I am so excited.

Now all I need to do is tinker a little with the code.
I have no idea how to see the output on the console... Didn't think it was possible with the Pro-Trinket?

EDIT:
I can't seem to get it to reliably work. Unsure if it's a hardware or software issue?
 
Last edited:

BillB3857

Joined Feb 28, 2009
2,570
Have you thought of using a small vibration motor, like those in cell phones, as an alert for a level you choose? That would provide an alert without having to look at an LED.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
Have you thought of using a small vibration motor, like those in cell phones, as an alert for a level you choose? That would provide an alert without having to look at an LED.
Yes, this is definitely on my list of things to add. I just wanted to get it all working first with LED's, do some tests and whatnot and then implement other elements.

At the moment though, I can't seem to get it to reliably work, and I'm not too sure why.
 

djsfantasi

Joined Apr 11, 2010
9,160
In the upper right corner of the Arduino IDE, is an icon to display the console.
Capture.PNG
The IDE calls it the serial monitor My calirbration sketch writes th values read from th sensor on the serial monitor.. The code line which does this starts with "Serial.print..." Data is not available in the serial monitor until the sketch is done uploading.

A quick example:
C:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); // initialize the monitor. 9600is a good defaut vakue
  Serial.println("Al-Khayal"); // prints your name on a line
  Serial.println("djsfantasi"); // prints my name on another line
  Serial.print("djsfantasi"); // start to contruct a line
  Serial.print(" likes helping");
  Serial.println("Al-Khayal"); // finish the line
}

void loop() {
  // put your main code here, to run repeatedly:

}
This short sketch produces the followung output in the servial monitor (you also can see th serial monitr, too.
Capture2.PNG
 

ebeowulf17

Joined Aug 12, 2014
3,307
Unless I'm misreading the Adafruit website, serial out doesn't feed through the USB on the Trinket. It mentions the option of using an FTDI for serial output.
 

ian field

Joined Oct 27, 2012
6,536
Ah I see. Hmm.
I think the PIN numbers are the same.

Not entirely sure I understand all of the schematic. I'm trying to look up schematic aids so i can understand it better.
At the moment, not understanding entirely where everything goes is the only hold up.
My idea (probably) avoids any schematic at all.

Monitor its weight - you can get digital luggage scales, but I don't know how small they go - shop around for one that has an alarm function.

For a small enough scale you may have to look at 'specialty' suppliers - the ones that sell scales for weighing naughty substances.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
My idea (probably) avoids any schematic at all.

Monitor its weight - you can get digital luggage scales, but I don't know how small they go - shop around for one that has an alarm function.

For a small enough scale you may have to look at 'specialty' suppliers - the ones that sell scales for weighing naughty substances.
I had thought about this. How would it be implemented though? Surely the scales would need to be secured on something?
 
Top