A better way to detect angle than a tilt switch

Rampz

Well-known member
Following on from my question ref can a certain pib be used for ADC input, the question was leading to this.
I have bought a SCA60C module online its based on a chip by VTI N1000060, it has a LM393 to give 2x switched output that i was hoping to use in the first instance, but it seems they are really too sensitive for what i want, there is also an analogue output that goes from 0 degrees through to 180 degrees, the output starts at 0.5v and goes through to 4.5v.

I found some code from a post on here that displays voltage from the readadc10 command

Code:
#picaxe 08m2
SetFreq M16
#no_data
#terminal 19200

main:
readadc10 c.2,w0
   w0 = w0 * 44 / 9           
   bintoascii w0,b2,b2,b3,b4,b5
   sertxd (b2,".",b3,b4,b5," Volts ",lf)
pause 1000
goto main:
Using the above code and trying to merge with other code that takes say 50 readings then averages it out, my ouput reading is way out, i guess due to my lack of grasping ADC maths

It does give me a voltage display and it does change when the board is tilted either way, but my output is going from 0.4v to 4.5v and i assume the code above is going from 0v to supply? I have been reading up on adc maths and really not getting my head around it all.
In my code i am running the clock at M16 because the code it will ultimately be used in is running at that speed.

I'm using this module because it seems slightly easier in my head to deal with an analogue voltage rather than something digital, but that said the module i bought is obsolete and has been for several years, so maybe i should be starting somewhere else.

This will ultimately replace the tilt switch input that i currently use, the tilt switches are Mercury based, they don't work all that great and are the weak link in everything, if there is a 1, 2, or 3 axis sensor that i should really be using instead of try to get really old technology to work i'm open to any ideas?

Ok so with some playing about and loads of reading, gone right back to the start, i have no need to display what voltage is coming from the module, so instead will display the ADC10 value, then if thats 1023 divide it by 180 degree's to give 5.68 ADC points per degree.

Code:
#picaxe 08m2
SetFreq M16
#no_data
#terminal 19200

main:

readadc10 c.2,w0
w0 = w0 * 21 
w0 = w0 / 119
bintoascii w0,b2,b2,b3,b4,b5
   sertxd (b3,b4,b5," degree's ",lf)
pause 3000
goto main:
with the pcb laid flat it should give about 90 degree's which it does and it alters nicely in both directions, but having measured the output of the module it seems to go from 1.186v to 3.384v i guess thats something to do with either the multimeter or the LM393 thats on the pcb too?
Either way how do alter my scale to get rid of the lowest part of the range and the top part, since due to the chip i can't reach either?
 
Last edited:

AllyCat

Senior Member
Hi,

That code is correct for converting a READADC10 value to (milli-)Volts, assuming that the PICaxe's supply supply rail is exactly 5.0 volts. The 44 / 9 is a "simple" way to convert a Full-scale ADC reading of 1024 to 5000 (mV). However, to try then to average the value of a large number of additional measurements will be more difficult, and probably reduce accuracy.

A better solution is to simply accumulate (add) a series of (say) 50 measurements (to give a full scale around 1024 * 50 = 51200) and then scale it down using the ** operator, for example 5000 / 51200 * 65536 = 6400 (using a pocket calculator if necessary). Then so calculate the accumulated ADC value ** 6400 to give the value in milliVolts. To manage the ~400mV "sit up", you will need to subtract approximately 400 / 5000 * 1024 = 82 from each ADC value and then the full-scale reading becomes 1024 - 82 = 942 .

Beware that the surface tension of mercury gives the switches very considerable hysteresis (effectively positive feedback) which you will probably need to emulate in the program maths.

Cheers, Alan.
 

Rampz

Well-known member
Beware that the surface tension of mercury gives the switches very considerable hysteresis (effectively positive feedback) which you will probably need to emulate in the program maths.
Hello

I tried putting too much info into my opening lines, i am trying to move away from a mercury switch if possible and use other methods of getting angle detection, the mercury switch at best is 15 degree's and that varies on every switch, looking for something more repeatable at a lesser angle.
 

Rampz

Well-known member
ADXL345 or an MPU6050.
I was wondering which way to go, i'll try and get one of them and see if they work better, at this point of the project its a case of working out which direction is best, the mercury tilt switch does work, but there is must be a better way to sense small changes of tilt and act on it?
 

papaof2

Senior Member
There are ball-and-contact switches available for angles of 15, 30 or 45 degrees. They are sealed, so the contacts should stay clean "forever".
Not exactly high resolution but consistent in making contact at their manufactured angle.

One US surplus electronics dealer that usually has them is: https://theelectronicgoldmine.com/
There are probably others as well.
 

Rampz

Well-known member
There are ball-and-contact switches available for angles of 15, 30 or 45 degrees.
I have tried these and they don't work very well at all, mercury works better, what tilt switches don't seem to like is very slow change of angle, they don't operate well if used very slowly. I have look at all sorts of tilt sensing.
 

Buzby

Senior Member
The ADXL45 is very easy to use ...

 
Top