I've been working on an IV fluid drip monitor using an IR obstacle sensor module. I desoldered the sensor's TX and RX IR LED so it can be soldered to a much longer wire. The problem is with the output to be displayed on an OLED. I decreased the sensitivity of the module. It detects the droplet because the LED indicator turns off but it doesn't register that a drop has been detected. The drip value on the dispaly doesn't change. Even when monitoring it through Serial Monitor it still doesn't update. But slower objects that passes between it is registered. I've tried a different obstacle sensor that hasn't been tinkered with (with sensitivity adjusted similar to the one being used previously) but it's the same. Is it problem with my code or the obstacle sensor itself can't do the task?
It may be that the droplet is passing too fast to be reliably picked up. You need to check the output from the sensor is wired correctly ( circuit diagram ?) . If it’s a really fast event you might want to look at using interrupts or google “ fast digital read” for Arduino using port manipulation .
The whole of your code is not shown , so there could well be other issues slowing down it’s response and making it miss .
Yes the pins on the obstacle sensor is wired correctly with the arduino. Maybe I can try using interrupt, but from what I know, interrupt is only used to interrupt another process. I am also using a timer and a button to increase a value in my system. Maybe that's why it can't pick up the output in time. I'll also try your other suggestions. Thank you.
grIMAG3:
Maybe I can try using interrupt, but from what I know, interrupt is only used to interrupt another process.
Well, that is sort of what you want - the "other process" is your main program, and the interrupt code handles the unscheduled event than has to be handled immediately (the droplet input pulse).
What you probably don't know, is that that is just the bare mechanics of it - you need to understand the framework around an ISR that co-ordinates the interrupt and main code. Once you learn that, it will become clearer to you, exactly how it can work with your existing code.
pourduino:
If it works when they're soldered but not with the long wire then you probably have a noise problem.
It is still the same even when using the unsoldered module. It can't register the inputs which are too fast (droplets falling) but it can register slower ones (passing a straw between it).
grIMAG3:
It is still the same even when using the unsoldered module. It can't register the inputs which are too fast (droplets falling) but it can register slower ones (passing a straw between it).
Then the problem is not speed. IR sensors are extremely fast. I think your problem is that the drop is not big enough to trigger the IR sensor. You have to find a way to make the sensor see the drop.
Edit: Unless your code is very slow. Are you perhaps using delays in your code?
If you are not using interrupts your loop has to be very fast.
pourduino:
Then the problem is not speed. IR sensors are extremely fast. I think your problem is that the drop is not big enough to trigger the IR sensor. You have to find a way to make the sensor see the drop.
Edit: Unless your code is very slow. Are you perhaps using delays in your code?
If you are not using interrupts your loop has to be very fast.
It actually detects the drop. I've tried recording a slow motion (960fps) video on the system I have set up. The LED indicator on the module that indicates something is detected actually turns off (based on my code). I put a 1 millisecond delay after the code. I haven't tried setting it as an interrupt though.
grIMAG3:
It actually detects the drop. I've tried recording a slow motion (960fps) video on the system I have set up. The LED indicator on the module that indicates something is detected actually turns off (based on my code). I put a 1 millisecond delay after the code. I haven't tried setting it as an interrupt though.
Use interrupts then.
It might sound daunting if you haven't used them before but they're actually extremely easy to use and in a lot of cases more straightforward than polling.
You would do something like this:
const int inputPin = 2; //only pin 2 and 3 on the Arduino can be used for external interrupts
bool dropDetected = false;
void handleDrop(){
//interrupt routines have to be as fast as possible
//for that reason we only set a flag in here and do the actual handling in our loop
dropDetected = true;
}
//in your setup() code
attachInterrupt(digitalPinToInterrupt(inputPin), handleDrop, RISING); //if your sensor outputs a LOW when it detect the drop then use FALLING instead
//in your loop() code
if(dropDetected){
//do whatever you want to do when a drop is detected
dropDetected = false;
}
pourduino:
Use interrupts then.
It might sound daunting if you haven't used them before but they're actually extremely easy to use and in a lot of cases more straightforward than polling.
You would do something like this:
const int inputPin = 2; //only pin 2 and 3 on the Arduino can be used for external interrupts
bool dropDetected = false;
void handleDrop(){
//interrupt routines have to be as fast as possible
//for that reason we only set a flag in here and do the actual handling in our loop
dropDetected = true;
}
//in your setup() code
attachInterrupt(digitalPinToInterrupt(inputPin), handleDrop, RISING); //if your sensor outputs a LOW when it detect the drop then use FALLING instead
//in your loop() code
if(dropDetected){
//do whatever you want to do when a drop is detected
dropDetected = false;
}
Hello! Sorry for the very late respone. Been busy with some work. I've tried your suggested code and it seems it continous to count even with no input from the obstacle sensor.
pourduino:
Use interrupts then.
It might sound daunting if you haven't used them before but they're actually extremely easy to use and in a lot of cases more straightforward than polling.
You would do something like this:
const int inputPin = 2; //only pin 2 and 3 on the Arduino can be used for external interrupts
bool dropDetected = false;
void handleDrop(){
//interrupt routines have to be as fast as possible
//for that reason we only set a flag in here and do the actual handling in our loop
dropDetected = true;
}
//in your setup() code
attachInterrupt(digitalPinToInterrupt(inputPin), handleDrop, RISING); //if your sensor outputs a LOW when it detect the drop then use FALLING instead
//in your loop() code
if(dropDetected){
//do whatever you want to do when a drop is detected
dropDetected = false;
}
Oh wait my bad. It was attached to the wrong pin. The interrupt only stops the oled from updating when no input is given to the obstacle sensor. It only refreshes after each drop and it doesn't seem to have a difference from my previous code. It's still very slow. It still cannot detect the drops everytime they pass the obstacle sensor.