# Octobanger triggered by Ultrasonic Range Finder



## MBrennan (Sep 22, 2008)

Greetings all.
I was wondering if anyone has tried (or if it is even possible) to trigger the Octo with an Ultrasonic Range Finder in place of the PIR with Mikkojays existing app.
Any suggestions?
Happy Prop Building!


----------



## corey872 (Jan 10, 2010)

Have never tried. Taking a quick glance at the workings of the UT sensor, (and what little I know of the octobanger(!), it seems like it would be an uphill battle. The PIR outputs a 'normal' signal (eg - a several seconds long pulse, or more) when it is triggered. Pretty easy to get the octo to read that.

The UT sensor seems to be different in that it requires a micro / millisecond input to start the measurement and puts out a micro / millisecond timing pulse based on the distance sound traveled to the object and back. I don't think the octo is going to be capable of timing intervals like that. Seems like it is based more in the 'seconds' realm for normal triggering purposes. So outside a custom hack of the octobanger sketch with the possibility of getting it to pull double duty, I'd say likely not possible.









How to Set Up an Ultrasonic Range Finder on an Arduino


How to measure distance with an ultrasonic sensor on an Arduino. Temp and humidity can affect the accuracy, but there's an easy way to compensate for it.




www.circuitbasics.com





You could technically use another arduino to drive the UT sensor, then have it output a 'normal' signal pulse when an object is detected in range. That normal pulse could then be worked into the octobanger routine... or could act as a trigger on its own.


----------



## MBrennan (Sep 22, 2008)

Thanks for the info and input!
I was mostly curious as I saw where it was used as a trigger (with a different controller).
Thought it might be interesting to have another triggering option if it wasn't too difficult.
For now - I'll keep using the PIRs


----------



## mikkojay (Sep 15, 2014)

The Arduino source is in the \hex\src sub directory of the Octobanger package, so all you would really need to do is create your own custom version of the Arduino code. There is a function called 
bool check_trigger() that you could tweak to your liking.

From what I understand about these range finders, you'd need to set a default/ambient distance reading at startup, then determine how much of a difference in reading you want to consider a triggerable condition. If that threshold is met, the 
bool check_trigger() function would then return true, and the rest of the firmware would act like it should.

I have a few of these sensors in my s#!t box somewhere, but I cannot guarantee a functional proto by the 31st 

-Mike


----------



## mikkojay (Sep 15, 2014)

I was considering these sensors, I think I actually bought a few of them a couple years back. From what I can tell, they'd be plug and play replacements for PIR's.








Arduino Motion Detector Using a Microwave Proximity Sensor | Arduino


Learn how to use an RCWL-0516 motion detection sensor and build a Proximity Sensor with an Arduino!




maker.pro




One for the experiment queue


----------



## corey872 (Jan 10, 2010)

If the code for the octo is available and open, then that would be one big step out of the way. The next (minor) issue is that the code for the UT sensor would likely need to be 'non blocking' - not using the 'delay' function - which would halt processing of all other functions while waiting on the UT sensor. 

The very first, simple sketch at the link I posted only blocks for microseconds in the main 'UT reading' portion which is likely acceptable - you'd never notice that. It and the rest of the sketches call out delays of 500 milliseconds or half a second in the 'print to screen' function. So that might appear like the octo 'freezing' at certain points. But once you get the sensor set where you want it, no need to serial print, so those functions could likely go away, or be called out on a timer so they don't lock everything else.


----------



## Hallowed31 (7 mo ago)

corey872 said:


> The next (minor) issue is that the code for the UT sensor would likely need to be 'non blocking'


the NewPing library IS non blocking until you tell it to block. In other words:


```
void loop(){

if (myRange >= 20 && myRange <=200){  // range in cm, see New Ping examples if this doesn't make sense to you

octoMom();

}



void octoMom(){

digitalWrite(pinYouWantToFire, HIGH);

delay(3000); // however long the octo needs

digitalWrite(pinYouWantToFire, LOW);

}
```


----------



## Allen_Haunts (Jul 26, 2021)

MBrennan said:


> Greetings all.
> I was wondering if anyone has tried (or if it is even possible) to trigger the Octo with an Ultrasonic Range Finder in place of the PIR with Mikkojays existing app.
> Any suggestions?
> Happy Prop Building!


Yes it does, I have made a prop that uses one. But what you want is a proximity trigger that measures distance, which will send a signal to the board. The sensor has the distance settings on it. They also work with the Pico line of controllers too.


----------



## Allen_Haunts (Jul 26, 2021)

Were you able to figure this out? The sample project document in the Octobanger build describes the trigger logic. you just need to supply a signal to the A0 pin.


----------

