Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:08 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Ball-switch vs Accelerometer....

     Page 1 of 2    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 10:59pm 17 Nov 2017
Copy link to clipboard 
Print this post

Further to the problems I was having with the ball-switch to sence a tilt in this thread, I have started taking a close look at using an Accelerometer for simple detection of a tilt to the left or the right.

I am currently looking at the MPU-5060, which can be had as a module for only a buck or so from the likes of eBay here.

Do the members think this would be an option worth pursuing?
Has anyone used these sensors before?
Anyone used ANY accelerometer chip before?
If so, can those members throw any light on how hard or easy they were to use?

In MY case, all I would want to know from the sensor, would be if it had been rotated 90' to the left or the right - it can ignore everything else, and I am not interested in any of it's advanced features.

Just looking for options now, as the ball-switch has been a total failure, so I need to chuck that idea in the bin and redesign using something else.

EDIT: I found this website which talks about using this module, and explains how it works etc - quite useful information here....Edited by Grogster 2017-11-19
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:12am 18 Nov 2017
Copy link to clipboard 
Print this post

Don't know if this is a helpful solution or not, but you could load an Accelerometer App on a smart phone to see what sorts of output it gives for the movement you need to detect.

Plenty of them about & avoids the wait for the module.

Phil.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:21am 18 Nov 2017
Copy link to clipboard 
Print this post

One I had loaded outputs G's in each axis,
Moved my phone around a bit & got this.

Cheers.





Edit,

Graph spans maybe 30 seconds.Edited by Phil23 2017-11-19
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:52am 18 Nov 2017
Copy link to clipboard 
Print this post

Haven't used it for anything useful yet but here is some code to play with:

  Quote   ' TassyJim
' 16 October 2015
' MPU-6050 gyro/accelerometer
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
OPTION EXPLICIT
DIM MPU = &h68 ' MPU-6050 address
DIM temp, accelX, accelY, accelZ, gyroX, gyroY, gyroZ, tilt, accelM, lc
DIM gyro(14)
PRINT CHR$(27)+"[2J" ' VT100 CLS
I2C OPEN 100,0

I2C WRITE MPU,0,2,&h6B,0 'wake up the MPU-6050
IF MM.I2C = 0 THEN
DO
I2C WRITE MPU,1,1,&h3B 'Reset memory pointer.
I2C READ MPU,0,14,gyro(1) 'Read 14 bytes
accelX=sint16(gyro(1)*256+gyro(2))
accelY=sint16(gyro(
3)*256+gyro(4))
accelZ=sint16(gyro(
5)*256+gyro(6))
temp=sint16(gyro(
7)*256+gyro(8))/340+36.53
gyroX=sint16(gyro(
9)*256+gyro(10))
gyroY=sint16(gyro(
11)*256+gyro(12))
gyroZ=sint16(gyro(
13)*256+gyro(14))

accelM=
SQR(accelX*accelX+accelZ*accelZ)

IF accelM=0 THEN ' avoid divde by zero error
IF accelY<0 THEN
tilt=-
90
ELSE
tilt=
90
ENDIF
ELSEIF accelZ<0 THEN
IF accelY<0 THEN
tilt= -
180 - DEG(ATN(accelY/accelM))
ELSE
tilt=
180 - DEG(ATN(accelY/accelM))
ENDIF
ELSE
tilt =
DEG(ATN(accelY/accelM))
ENDIF
IF lc>100 THEN
PRINT CHR$(27)+"[2J"
lc =
0
ENDIF

PRINT CHR$(27)+"[1;1H",TIME$
PRINT "ACCEL_XOUT ",accelX
PRINT "ACCEL_YOUT ",accelY
PRINT "ACCEL_ZOUT ",accelZ
PRINT "TEMP_OUT ",STR$(temp,3,1)
PRINT "GYRO_XOUT ",gyroX
PRINT "GYRO_YOUT ",gyroY
PRINT "GYRO_ZOUT ",gyroZ
PRINT
PRINT STR$(tilt,4,1),"Degrees (+/-)"
tilt = ((tilt*
10+3600) MOD 3600)/10 ' MOD gives the result in integers
'if tilt = 0 then tilt = 360 ' uncomment if you want 360 instead of 0
PRINT STR$(tilt,4,1),"Degrees (0-360)"
lc=lc+
1
PAUSE 1000
LOOP
ELSE
PRINT "I2C error ",MM.I2C
ENDIF
END

FUNCTION sint16(x) ' convert to signed 16 bit number
IF x>32767 THEN
sint16 = x -
65536
ELSE
sint16 = x
ENDIF
END FUNCTION


I was going to mount one on the tractor but I decided that the old method works well enough:
"if the back wheel is off the ground, the slope is too much"

Peterm did a LOT of work with gyros etc to stop his plane falling out of the sky.

JimEdited by TassyJim 2017-11-19
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:55am 18 Nov 2017
Copy link to clipboard 
Print this post

Thanks guys, and Jim for the sample code. I might get a few then to play with as you have already done some demo code.

[Quote=TassyJim]if the back wheel is off the ground, the slope is too much[/Quote]

LOL!!!
Well, quite.
Smoke makes things work. When the smoke gets out, it stops!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 01:12am 18 Nov 2017
Copy link to clipboard 
Print this post

  Quote  Has anyone used these sensors before?


Like this?
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 04:47am 18 Nov 2017
Copy link to clipboard 
Print this post

@matherp love how you make things just flow like water.

Your other video too. so cooool


And this option too.
ADXL345

you can get better price on ebay

ebay
Edited by Quazee137 2017-11-19
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:04pm 18 Nov 2017
Copy link to clipboard 
Print this post

@matherp - FANTASTIC HORIZON!!!

Paul in NY
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:56pm 18 Nov 2017
Copy link to clipboard 
Print this post

@ matherp - EXACTLY like that. I will have to get some of these modules and have a little play.
Smoke makes things work. When the smoke gets out, it stops!
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 08:59pm 19 Nov 2017
Copy link to clipboard 
Print this post

Hi Grogster;

The simplest direct angle sensor, outside of the pair of mercury switches, would be
a pot with a weighted pendulum connected to the shaft.
This forms a variable voltage divider that can be read with the A2D on the uMITE.

Standard linear pots can rotate about 270deg, more than enough for your +-90deg range.
Choose one that has a loose action or you will need a heaver weight.

redrok
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 04:50am 20 Nov 2017
Copy link to clipboard 
Print this post


Here is more reference data for you.

Single-axis Gyroscope Analog Gyro Module ENC-03RC

seeedstudio


Quazee137
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 05:05am 13 Dec 2017
Copy link to clipboard 
Print this post


Grogster

I was wondering how this is going.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 07:19am 13 Dec 2017
Copy link to clipboard 
Print this post

Thank you for your interest.

I have designed a new PCB that replaces the ball-switch with two small mercury switches secured to the PCB using silicone sealer at roughly 45' angles via slots in the PCB. Silicone sealer was chosen over glue, as it is flexible, and should allow for a little bit of 'Mercury Switch Suspension', for want of another term.

I have some 3mm and 5mm(diameter) mercury switches, and the board is designed to use the 5mm ones - slightly more mass(bigger blob of liquid mercury then the 3mm ones).

These switches are connected between a standard 10k/1k pull-up arrangement to the I/O pin(no more PULLUP option) and ground, so that when either mercury switch is tilted, the I/O pin is pulled to ground. At least with the two external pull-up resistors, I can now play with values if for whatever reason, 10k/1k does not work with the mercury switches - but I am hopeful that they will work just fine in this application.

The PCB's have been made, and I expect them in the next couple of days via DHL, and I plan to build a new prototype over the Christmas holidays.


Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 08:35am 13 Dec 2017
Copy link to clipboard 
Print this post

Grogs,
I assume you mean the glass tube mercury switches, I have some here somewhere that are round and will close or open (I can't remember) when tilted in any direction. They came out of column oil heaters in case they fell over.

Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 10:33am 13 Dec 2017
Copy link to clipboard 
Print this post

  Grogster said  Silicone sealer was chosen over glue, as it is flexible, and should allow for a little bit of 'Mercury Switch Suspension', for want of another term.


Good to see some old tech reliable concepts in use.

Hazardous stuff as we are all aware.

It's well known that it can escape all restraints & go in wild rampages over entire suburbs & r@93, plunder & pillage. Chase people down for miles, before ripping people's hearts out...

Dangerous stuff some of these elements...
In the wrong context.

Rant over....
Miss the day's where normal people could use the good stuff....


Phil.

PS,

An old MS sits in a display cabinet here....
Poised to track down & apprehend intruders...
Just need that bag of Sulfur as the "Antidote Agent" in the event of a mishap.

Long Day, Long Week,
just venting a little dry Outback Humour.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 07:21am 14 Dec 2017
Copy link to clipboard 
Print this post

...and consuming the outback lager?
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 10:29am 14 Dec 2017
Copy link to clipboard 
Print this post

This may have been it....





Edit:-

Don't worry, substance has been "Disposed" of.Edited by Phil23 2017-12-15
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:10am 15 Dec 2017
Copy link to clipboard 
Print this post

Hahaha!
Nice one.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 01:15am 13 Feb 2018
Copy link to clipboard 
Print this post

My new sensors from Digi-Key have arrived.

The first one is a left-right tilt switch in a single package. Here is a photo of it's guts:





This one is pendulum based, and there are actually three little pendulums inside there, stacked one on top of the other. I will hook up one later and test it out.

The next one is another ball-switch unit, but it is indeed gold-plated. Here is a photo of it's guts:





The gold-plated one will probably give the least trouble cos of the gold-plated contacts, ball and retaining cup. I will hook both of them up and have a play later tonight. As these ones are from a more reputable supplier, I hope to have less isses then I was having with the ones from China. Well, the ones from DigiKey are still made in China anyway, but I guess there is more quality control.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:45am 13 Feb 2018
Copy link to clipboard 
Print this post

Did you also order the optical ones that have a ball that blocks the light?

Microblocks. Build with logic.
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025