Help with simple project


I am new to anything like this and was hoping i could get some help with a project im working on. I want to build a setup for a motorcycle that would turn on lights depending on lean angle (lets say 22.5 degrees in either direction for an example). With some of the research i have been doing i think the arduino 101 would be the board i would want since it has built in accelerometer and gyro but i could be completely wrong. any help i could get with what i would need for parts, coding and anything else would be greatly appreciated. i know this is probably a very simple setup to a lot of you but i am lost


I don't think this is at all simple. The bike may not only be leaning, but accelerating or braking, and going up or down hills , cornering either way , the road may not be level, and the bike may be hitting potholes..

Anybody done this? It sounds harder than an artificial horizon / turn and slip indicator for an aircraft, which I'm working on....



I don’t want to be discouraging in the long run, but this is not at all a “simple setup”.

It might surprise you that in fact, it is an extremely challenging project to use a sensor to detect the lean angle of a motorcycle.

It is a project that simply cannot be undertaken by beginners. This has to do with the physics of motion and the problems associated with the available sensors.

Fortunately or unfortunately, it is also a popular subject and if you google the topic, i.e. “detect motorcycle lean angle” you will discover the long discussion threads about the various problems people have encountered.

Use a flight controller from a quadcopter. (CHEAP) These all have serial outputs for a master PC to set up defaults. Use this serial port to another Arduino, decode the lean and map that to your lights. Done.

-jim lee

Use a flight controller from a quadcopter. (CHEAP) These all have serial outputs for a master PC to set up defaults. Use this serial port to another Arduino, decode the lean and map that to your lights. Done.

Can that work with a bike?

I thought the problem with bikes is that the sensors always think they are upright because all the forces must necessarily pass through the contact patch between wheel and ground? When the sensor leans over so does the line of force it is trying to detect.


Sure, its the same issues with the quadcopter. And the quad has nothing else to rely on so the system works pretty well. A flip 1.5 controller talks to processing out of the box and typically runs about $15. If you can still find one. They are kinda’ last year’s tech.

-jim lee

A lot of motorcycles use a crude lean sensor as a safety switch to shut off the engine if you crash it.
Most I have seen are usually a steel bearing that ride in a U shaped channel. On each leg of the U there is a contact. Lean the bike to far, the bearing runs to one side of the U, hits the contact and shuts off the bike.
You have to lean the bike over pretty far for this to happen, but you could probably modify one to make contact at the angle you need, or it probably wouldn't be to hard to make your own sensor.
Here is the type of switch I am referring to.

A ball-bearing sensor will NOT detect lean while the bike is moving. I suspect that is one of the reasons it is used - you would not want the engine to shut off in the middle of a tight corner.

Thinking some more about the quadcopter sensor (just idle curiosity) i wonder if it detects an increased "gravity" and interprets that as an angle of tilt?

There is a story in the book "Wide Body" (about the Boeing 747) in which the test pilot barrel-rolled a 707 above an audience. The company boss was furious. The test pilot said something like "The plane didn't know - it always had 1g positive force". If one could afford it it would be interesting to see if one could fool the quadcopter sensor :slight_smile:


The flight controllers use accelerometers along with gyros. I've read that the napkin math is : get your angle to earth by reading the gyro fast and the accell. slow to dampen/correct out the drift.

A test would be very inexpensive. All you need is a laptop and a Quad controller mounted on the bike. They all show you your yaw,tilt & roll on the screen.

-jim lee

X2 for Robins comments. As a further addition to the aircraft comments it is a very similar set of circumstances that bring some pilots ( and sadly their passengers)to an early end. Re not believing certain instrument readings. As a bike rider for over 50 years, any switch that cut the engine because of some crazy lean switch would see that swiftly chucked out.

A test would be very inexpensive.

I was worried about the cost of a quadcopter crash :slight_smile:

It would be no fun doing the test with a PC!


If a roadway or racetrack curve is perfectly banked (matched to the motorbike speed), the motorbike can be perpendicular to the road while rounding a corner.

What would you call the "lean angle" in that case?

the motorbike can be perpendicular to the road while rounding a corner.

The wall-of-death is the extreme example.


It is actually very complex due to how any bicycle type vehicle is controlled. Simple test to see what you are facing - hang a small weight from something on the motorcycle (windshield etc. by a string). Now notice how it hangs as you make turns while moving at any speed. Same issue in an airplane - a coordinated turn results in keeping the “bubble” centered in the turn and bank indicator (and essentially, anybody without a visual frame of reference outside can not tell you are in a turn). Often the cause of small airplane crashes in bad weather - the pilot is not instrument rated and gets into a situation where they can’t see the horizon - they end up flying by what “feels” right but in reality they may be in a descending turn (but it feels “straight and level” to them). Same thing on a motorcycle (or bicycle) - in a turn when you are moving at any speed, you feel “upright” for lack of a better term - you don’t tend to slide off either side. It takes a gyroscope (which then has it’s own frame of reference) to determine “lean”.

It takes a gyroscope (which then has it's own frame of reference) to determine "lean".

Which is what @jimLee has been saying.