Help create a sensor for my Ostomy appliance

djsfantasi

Joined Apr 11, 2010
9,163
It depends on your experience level. An Arduino will work. If you are comfortable with electronics, a PIC will work, too. There are those here who prefer them. But this application may not need a uC. A discrete circuit of OP amps (comparators), resistors, capacitors, transistor and of course your sensor will work, too.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
It depends on your experience level. An Arduino will work. If you are comfortable with electronics, a PIC will work, too. There are those here who prefer them. But this application may not need a uC. A discrete circuit of OP amps (comparators), resistors, capacitors, transistor and of course your sensor will work, too.
Keeping in mind that I have zero electronics experience, what do you think will be the easiest route?
Arduino does seem great, but there seems to be a ton of different versions and kits available. I wouldn't know what to buy and with what components.
 

djsfantasi

Joined Apr 11, 2010
9,163
I am working on a response. For this project, one of the suggestions to use an op amp or 3914 are excellent suggestions. However, with your lack of experience in electronics, I am suggesting an Arduino. Still, you aren't familiar with programming. So I have written a program for you and am putting together a list of items for you to consider... In the interim, perhaps you could try to learn how to solder. Instructables contains a lot of material, some good some bad, but here is one example; you can find many vy googling "hot to solder electronics". There are some very good one, but they were kind of advanced.
 

djsfantasi

Joined Apr 11, 2010
9,163
You will basically need an Arduino (I've picked the Arduino Micro, as it can be purchased without the headers and still has the USB programming cable). It also is a small size for incluson in your final device. Without headers means you can solder your connections directly to the board. Plus, I've listed an LED for an indicator, a resistor for the LED and the force/bend sensor.

The links to what I think you'll need are below:
  • Arduino Micro without Headers This is the Arduino model I think you can use.
  • USB Cable A/MicroB This is the cable to program the Arduino and power it during development and testing.
  • short Flex/Bend Sensor Your sensor...
  • Ribbon Cable I put this on the list, because you can remove two wires from the ribbon and use the wire to connect your sensor to the uC and lso connect your LED,
  • Red LED Here is an LED for example
  • 180 Ω 1/8W Resistor This resistor was calculated for use with the above LED and the Arduino.
  • 9VDC battery and clip You'll need a battery sources in the range of 6-20V. I listed the 9V battery, but really don't know if it will last sufficiently.
Take look at the program. It is very simple.
Code:
// sketch to read flex sensor attached to an ostomy bag,
// which

#define warningLevel 600
#define alertLevel 800
#define sensorPin A0
#define LEDPin 13

#define maxrepeat 10
#define flashrate 50

int sensor=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(LEDPin,OUTPUT);
  pinMode(sensorPin,INPUT);
}

void flash() {
  for (int repeat=0; repeat<maxrepeat; repeat++) {
    digitalWrite(LEDPin, HIGH);
    delay(flashrate); 
    digitalWrite(LEDPin, LOW);
    delay(flashrate); 
  }
 }

void alert() {
  digitalWrite(LEDPin,HIGH);
}

void normal(){
  digitalWrite(LEDPin,LOW);
}


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

  sensor=analogRead(sensorPin);
  if (sensor > alertLevel) {
  // Bag is fill; alert by turning LED on
    alert();
  } else if (sensor > warningLevel) {
  // warn that bag is almost full by flashing LED
    flash();
  } else {
  // LED is off for normal condition
    normal();
  }
}
It reads the sensor, and then based on predetermined values, turns the LED off, flashes it or turns it on solid. It does use a programming technique for when performing different tasks based on the value of a variable. That is, it tests for the highest value first and only tests for lower values when the previous check have failed.

The predetermined values are determined by experimentation. I have suppled a second program which you can use to determine the values.
Code:
// sketch to input the flex sensor value on analog pin 0,
// and output its value as it changes the console screen.

#define warningLevel=600
#define alertLevel=800
#define sensorPin A0

void setup() {
  // put your setup code here, to run once:
  pinMode(sensorPin,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensor=0;
  int prevValue=-1;
  sensor=analogRead(sensorPin);
  if (prevValue != sensor) {
    Serial.println(sensor);  
  }
}
It displays the values for various positions of the sensor and displays them on your computer screen, through the USB cable. You'll see how it displays the function when you download the Arduino IDE. I recommend you "play around with it". You can compile the sample programs, just not run them without an Arduino; you can write your own simple programs and see if they compile.


Here is a simple schematic, showing where the connections you will need will go. Since the model listed does not have headers, you'll solder directly to the board. You still could purchase headers and use connectors, but I thought since this is a "production" model, reliability would be better if the connections were soldered.
diagram.png


SInce it is based on a microcontroller, its operation can be enhanced easily. By using more pins, you could add more LEDs for status, or you could add an RGB LED to have color show the levels (these methods would require more battery capacity. You could also use external inputs... Such as an alert override.

Another Arduino model could in the future connect to WiFi for Internet access, but the environment is getting more complicated...
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
You will basically need an Arduino (I've picked the Arduino Micro...
Oh gosh, I'm not even sure where to begin... I am genuinely so, so grateful for this. Truly.
Throughout this whole ordeal so many people, most of them strangers, have offered help and shown unwavering kindness. I'm so very thankful!

I'm in the UK, so am trying to source the Arduino Micro from a reputable and certified retailer here. So far I've not been able to find the one without headers. I'll keep looking.

A few people have told me the 9v battery is a really inefficient way of doing this. Happy to go with something else if easier/more efficient.

Just had a read through of that code too - seems relatively straight forward to understand... I think...
If I wanted to have a different coloured 'always on' LED (so I can tell at a glance that the battery is still good), am I right in thinking that I could go about it one of two ways.
1) Connect the LED between the battery and the board
Or
2) Define it as say "LEDPinTwo 14" and attach it to the corresponding point on the board. If I'm understanding the code correctly, then I'd need to add another line to the code along the lines of:
void normal(){
digitalWrite(LEDPinTwo,HIGH);
Is that somewhat correct?

I'm having loads of fun already just reading your post.
Going to source all the items in the UK and get cracking.
I expect that once I'm somewhat okay with the above (and what I understand about the code is correct), I'd be able to add more features, like a vibration motor or a buzzer, and code it accordingly?

Once again, thank you so very much. I truly, truly appreciate your help.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
I've had a good look around, and so far I'm not able to find the Arduino Micro without headers anywhere... At least, not a genuine one. Even the official site is sold out.

Are you able to suggest another board?
I've found an Arduino Pro Micro board - I believe it's a SparkFun board... Would this work too?
 

ebeowulf17

Joined Aug 12, 2014
3,307
For half the price (depending on your location and shipping costs) I'm a big fan of the Adafruit Pro Trinket. Seems to me like both it and the Pro Micro you mentioned (which I also like) would work equally well in your application, but I defer to djsfantasi on this question since I'm not the one with viable code ready to go. Good luck!
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
For half the price (depending on your location and shipping costs) I'm a big fan of the Adafruit Pro Trinket. Seems to me like both it and the Pro Micro you mentioned (which I also like) would work equally well in your application, but I defer to djsfantasi on this question since I'm not the one with viable code ready to go. Good luck!
Thank you!
Yeah, I've found that board at Makersify. They also do the Arduino Micro.
Adafruit Pro Trinket - £10
Arduino Micro - £21

Kind of annoying that prices are quite a bit more expensive in the UK, but hopefully one of these boards will work. I'd obviously prefer using the cheaper Pro Trinket, as it also doesn't have the ICSP pins sticking out (I'd like as low of a profile as I can get).

I await Djsfantasi's response. :)
 
Last edited:

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
My components have finally arrived. Just wondering if you've had a chance to review my message, Djsfantasi?

Edit:
Just tried to load the program into the Pro Trinket and received this message:

"Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"

Sketch uses 1,194 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 13 bytes (0%) of dynamic memory, leaving 2,035 bytes for local variables. Maximum is 2,048 bytes.
avrdude: ser_open(): can't open device "COM1": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences."
 
Last edited:

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
Sorry, but I wasn't getting notified of your posts. But I see you've solved your issue of the board selection. Good choice.
Not to worry. Very happy with the Pro Trinket - lovely and small, and has now accepted the code.
I just need to work out how everything connects together, and what goes where - which is probably the most challenging aspect at the moment, though I suspect it's probably rather simple.
I've been practising my soldering too - happy and confident to take on the challenge.

I posted a while back, just wondering if you're able to read it over?

Oh gosh, I'm not even sure where to begin... I am genuinely so, so grateful for this. Truly.
Throughout this whole ordeal so many people, most of them strangers, have offered help and shown unwavering kindness. I'm so very thankful!

Just had a read through of that code too - seems relatively straight forward to understand... I think...
If I wanted to have a different coloured 'always on' LED (so I can tell at a glance that the battery is still good), am I right in thinking that I could go about it one of two ways.
1) Connect the LED between the battery and the board
Or
2) Define it as say "LEDPinTwo 14" and attach it to the corresponding point on the board. If I'm understanding the code correctly, then I'd need to add another line to the code along the lines of:
void normal(){
digitalWrite(LEDPinTwo,HIGH);
Is that somewhat correct?

I expect that once I'm somewhat okay with the above (and what I understand about the code is correct), I'd be able to add more features, like a vibration motor or a buzzer, and code it accordingly?

Once again, thank you so very much. I truly, truly appreciate your help.
 

djsfantasi

Joined Apr 11, 2010
9,163
My examples only need two connections to the microprocessor, other than it's power supply. The LED connects to a digital pin (pin D0) and the flex resistor connects to an analog pin (A0). If these PIN numbers change, their definition in the code must change, too

Do you understand the schematic?
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
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.
 

djsfantasi

Joined Apr 11, 2010
9,163
The PIN numbers are different. One is for reading an analog value from the sensor and one is a digital output for the LED. I am supposed to be doing yard work, so will try to give a more detailed answer later. When I'm on my laptop.

This schematic is fairly simple. For example consider the LED circuit. The digital pin (D0) is connected to one end of the LED; to it's anode. The other end of the LED (cathode) is connected to a Resistor. Depending on the LED, will determine the resistors value. The other end of the resistor goes to the power supply ground connection.
 

Thread Starter

Al-Khayal

Joined Jun 15, 2015
29
The PIN numbers are different. One is for reading an analog value from the sensor and one is a digital output for the LED. I am supposed to be doing yard work, so will try to give a more detailed answer later. When I'm on my laptop.

This schematic is fairly simple. For example consider the LED circuit. The digital pin (D0) is connected to one end of the LED; to it's anode. The other end of the LED (cathode) is connected to a Resistor. Depending on the LED, will determine the resistors value. The other end of the resistor goes to the power supply ground connection.
No worries at all - thank you again, and sorry to be such a pain.

I've attached a picture of what I've done so far - I don't think it's correct, but thought I'd post it anyway...
 

Attachments

Top