Maker Pro
Maker Pro

Detecting horizontal position

hi everyone. I am working on a project where I need a LED to light up if the arm of the platform is horizontal. Due to space constraints I can not use an accelerometer. The sensor needs to be small and just give a high or low value at 180 degrees only with minimal error range, I am using an arduino nano as the microcontroler on the platform say at a distance of 4-5 inches. can somebody please suggest a sensor or positioning switch which I can use.
 

hevans1944

Hop - AC8NS
Did you try Google with this search string: tilt sensor? Lots of results here. I bought a bag of a hundred ball-in-cylinder tilt sensors from Amazon recently, with the idea of throwing together a "toilet seat up" warning for my wife. If the toilet seat is up, the ball makes contact between two leads which is the criterion for sounding an alarm.

The rest of my circuit is just bells and whistles to prolong battery life, i.e., a PIC microprocessor that stays in sleep mode until the tilt switch changes states. I discovered, after playing around with one of the tilt switches using my digital multimeter, that the switch is quite sensitive in the vertical position to off-axis alignment. So, for my application, it would be better to orient the switch so it is closed (internal ball is making connection between the two leads) when the toilet seat in down instead of when the seat is up. That way it would not be so tricky in alignment with the vertical when the seat is up. YMMV.
 
Thanks hevans.
Yes I have been looking at tilt switch . especially SW 520D. It comes both as a standalone and as a module where a potentiometer is added on the PCB to adjust the sensitivity. How ever I have a couple of questions.
1) would the performance be consistent over a long time.
2) Should I use the standalone type or the module.( keeping in mind the space constraints, standalone would be a better option.)
3) Can I install the tilt sensor at the tip and run 2 lead wires to the PCB with potentiometer?
4) Is there a method/code I can run on the arduino it self so as to ensure a higher sensitivity of the tilt switch.
 
I'd get the module, remove the sensor and install remotely with wiring back to the module.
Sensitivity is a module adjustment and even at that, limited to whatever Arduino considers as a high or a low.
You may find the mounting to actually be less than directly upright.
Also be aware it has a particular orientation.
Input is either on or off.
As for lifespan, a quick Google ( always useful I find) shows it to have 50K plus switchings.

Code etc. here....
 
Thanks bluejets and also for the vedio. The sensor in vedio can be adjusted really to a very small angle so I guess it works. I am a medical person and tinker around with electronics as a hobby so correct me if I am wrong. My understanding is that the actual sensor is just an on /off switch and it is the LM393 that acts as an amplifier and the potentiometer adjusts the resistance or in a way controls the amplification.
Just for curiosity sake.
If SW 520D is just a switch , is it possible to attach two SW 520 D switches on series at right angle to each other so as to convert the module into a dual axis switch.
 

hevans1944

Hop - AC8NS
Thanks hevans.
Yes I have been looking at tilt switch . especially SW 520D. It comes both as a standalone and as a module where a potentiometer is added on the PCB to adjust the sensitivity. How ever I have a couple of questions.
1) would the performance be consistent over a long time.
2) Should I use the standalone type or the module.( keeping in mind the space constraints, standalone would be a better option.)
3) Can I install the tilt sensor at the tip and run 2 lead wires to the PCB with potentiometer?
4) Is there a method/code I can run on the arduino it self so as to ensure a higher sensitivity of the tilt switch.
1) Only time will tell.
2)Follow @Bluejets advice and separate sensor from module.
3)Probably; try it and see if it still works.
4)No; a switch (by definition) is a binary device, either open or closed.

More information here on the SW520D "ball in cylinder" tilt switch/sensor.
There are tilt sensors that provide an analog signal output that is a function of device orientation, some on a single axis, others on two or more. The latter are generally based on MEMS accelerometers, sometimes with on-chip signal conditioning. Your late-model smart cell phone uses these, only partially accounting for the exorbitant expense of new smart phones. I DO NOT recommend trying to hack a cell phone. If you need a feedback signal that is a linear function of position on one or more axes, you need to do your homework to find out what is currently available at a price you can afford.
 
If SW 520D is just a switch , is it possible to attach two SW 520 D switches on series at right angle to each other so as to convert the module into a dual axis switch.

Series connection would require both to close to get a circuit.

Parallel connection will give an OR contact. (one OR the other).
Problem is, one cannot differentiate in logic as to which is which.
Alternative is, if used as 2 inputs to a microcontroller, such as say an Arduino,then you can OR the connection in code and also detect which is which.
 
Yes that is what I was thinking a series connection will make it kind of a dual axis switch i.e the switch will work only if both X and Y axis are at 180 degrees . It may not be the best but it might work. By the way do you know of any IMU which can be installed in such a small space say not more than 1cm square. I have seen a couple of IMU from espon and also one from Mouser BMI 160 with I2C and SPI interface but don't know whether it is compatible with arduino or not and whether they can be installed independently with wire leads to the arduino.
 
Yes that is what I was thinking a series connection will make it kind of a dual axis switch i.e the switch will work only if both X and Y axis are at 180 degrees .

Ah, ok....

Worked mostly with Arduino as it is relatively straightforward with heaps of contribution to go to if ever in a pickle.
Also did a bit with Picaxe but it was rather limited in what it was capable of.
Then there were some with 8 pin microchip pic12F683 when we were doing the ignition systems but other than that , not much help there.

Have to convert when you talk cm. As a construction electrical contractor I'm used to working in mm.
Arduino pro mini modules are around 30mm long and 20mm wide. Use a usb to ttl adaptor to program. Cheap and quick.
Then there are the ATtiny85 and although compatible with Arduino they are a bit different to program and I've had a few hiccups that were difficult to nail down as they are nowhere near as popular.
 

bertus

Moderator
Hello,

We still have not seen a drawing of the set-up.
Can you have a sensor next to the rod?
Then you could use an optical reflective sensor:
https://uk.farnell.com/on-semiconductor/qre1113gr/opto-switch-reflective/dp/1471020
When there is a reflective line on the rod, the sensor could detect the position.
When you have room for two of those sensors, you can even tell of the rod is to high or to low with a pattern like this on the rod:

high_low_pattern.png

When both sensors are activated the level is OK.

Bertus
 
Yes that is what I was thinking a series connection will make it kind of a dual axis switch i.e the switch will work only if both X and Y axis are at 180 degrees . It may not be the best but it might work. By the way do you know of any IMU which can be installed in such a small space say not more than 1cm square. I have seen a couple of IMU from espon and also one from Mouser BMI 160 with I2C and SPI interface but don't know whether it is compatible with arduino or not and whether they can be installed independently with wire leads to the arduino.

Revisited a few details on the little ATtiny85 and it might just satisfy your requirements.
Found a video(rather than explain everything here) where the bloke uses a Arduino UNO for programming.
Essentially same programming arrangement for the code, just need to rename i/o's to suit the little fella.

 

hevans1944

Hop - AC8NS
Thanks for the video @Bluejets! What a neat way to program the ATtiny85/45 microprocessor! Just about everyone who plays with micros has an Arduino UNO on hand and a solderless breadboard, so no need to buy a PIC programming pod like I use for Microchip PIC micros. After I download the datasheet for the ATtiny, I might just order a few to see how they compare with the PICs.
 
Thanks Bluejets. ATtiny really looks promising in reducing the size . Ok here is the diagram of what I am trying to make
Here is what I want to do.
Rad the position of the base plate in X,Y,Z axis when the rod is horizontal to the floor. I have the arduino with a IMU and OLED screen which displays the position of the base plate . I want to freeze the display when the rod becomes horizontal to the floor . I plan to use the tilt switch as a switch which causes the display showing the position of the platform(C) to freeze when the rod is horizontal. something like a push button .
I need help regarding what is the code for freezing the display, and also how can I use the tilt switch .
 

Attachments

  • upload_2020-4-22_19-36-1.png
    upload_2020-4-22_19-36-1.png
    20.3 KB · Views: 7
Why would you want to freeze the display?
Any further movement would not show...o_O
There are other ways such as sound an alarm or set a flag for some other hardware.

Only thing I can offer without seeing any of your code is, if you have an update on your display, as you should for good practice, then just stop the update when certain condition is met.
 

hevans1944

Hop - AC8NS
Here is what I want to do.
Rad <sic> the position of the base plate in X,Y,Z axis when the rod is horizontal to the floor.
I am gonna make a leap of faith here and assume you meant to write "Read the position..." But we still don't know WTF you are trying to DO with your base plate with a hinged rod attached to it. Can you enlighten us with an explanation, or is this some sort of secret you are withholding for whatever reason?
 
Top