Getting starte: My first project: Cruise control for ebike

Hello,
I'm an absolute beginner trying to make my first project something useful.
The first thing I'd ask of you, is a shopping list, of what to buy to get started.

Here's the plan: I want to make a cruise control for my ebike.
The throttle works as a signal 0-5V.
At the push of a button I want the throttle signal to stay at the level it was at the moment I pushed the button.
When I push the button again I want the throttle to disengage.
Also, when I pull the brake lever (Reed switch with either an opener or closer attached) should kill the throttle and disengage the cruise control so it does not reengage, when the brake is released.

This is all I want to accomplish in a first step.

Later on, I would read out different sensors and display them on and Android phone... but that isfor a later time. If I can save money buying a set that will include things for the second project, I'd be up for that. Value for money above all :wink:

Thanks, guys.

You can potentially kill your self with any Arduino. Reading a switch state is easy. Using a PWM pin to output a psuedo 0 to 5V value is easy.

Whether the low current of that 0 to 5V value, and the choppiness of it, will be a problem is impossible to tell without knowing anything about your ebike.

The choppiness can be dealt with with a low pass filter. The low current can be dealt with with a transistor.

To me, cruise control means controlling the speed, not just maintaining constant throttle.

If constant throttle is all you want, you just need a potentiometer that stays where you put it, with some sort of latching relay to enable you to cut it in and out as you describe.

More useful I'd have thought was something that measured the road speed and applied power/braking to maintain it.

Don't worry, Paul, the kill switch is not essential. Other bikes don't have it at all and the brakes are strong enough to stop the bike even at full throttle.
The throttle will cut out about a second after you stop pedalling anyways because the signal from the crank'S PAS sensor is missing.
But I want a smoother solution to only pull on the brakes for a moment and kill the motor that way, also to just keep pedalling alone without the motor.

Yes, Peter, you are 100% correct. A readout of the speed and then cranking the throttle up slowly until that speed is reached would be perfect, but the problem is, how to control that. Because the controller would have to understand not only the current speed, but also the acceleration, so it accelerates at a more or less constant rate up to the target speed.

I would love to have readouts on an LCD or preferably my android device on about everything

  • battery temp
  • motor temp
  • speed
  • crank rpm
  • current
  • voltage
  • power
  • ambient temp

and switch controls from either setting a current (like with the poti) or a target speed (true cruise control)
with a display for target current and target speed.

2 reasons why, I don't want to go the poti route:

  1. I don't know how to make the motor stay off, after the brake as been engaged
  2. I would like to learn how to program an Arduino and play with electronics

I can build PCs and maintain networks but have no idea of programming and very limited soldering experience. I have a 7 year old, and I want to be able to teach him more in that area than my father could teach me (which is zilch)

I would love to have readouts on an LCD or preferably my android device on about everything

Your phone belongs in your pocket, not your hand, when riding. Having information displayed in your pocket seems silly.

My phone serves as a speedo on my bike, and it's mounted to the handle bar.
I'm - as a matter of course - not using it for calls or texting while riding.

After all, why carry an additional display, when I already have a perfectly good one.
If you can recommend a nice weather proof display, maybe with some buttons that I could use with the Arduino, I'd be all up for that.

After all, why carry an additional display, when I already have a perfectly good one.

OK. That's fine. I presume, then, since you are using it as a speedometer that you know how to get data into the phone, and how to manipulate that data to produce the visual effects that you want. Adding more data, and more manipulation to produce more effects, should be trivial.

If you can recommend a nice weather proof display,

Is your phone weatherproof?

PaulS:

After all, why carry an additional display, when I already have a perfectly good one.

OK. That's fine. I presume, then, since you are using it as a speedometer that you know how to get data into the phone, and how to manipulate that data to produce the visual effects that you want. Adding more data, and more manipulation to produce more effects, should be trivial.

It's not that simple. I have an app that can do those things. It uses the GPS signal and calculates those values. So unfortunately I cannot take credit for that.

If you can recommend a nice weather proof display,

Is your phone weatherproof?

No, it isn't, but I don't leave my phone mounted to my bike, wherever I go. Whereas if I had a dedicated display I would mount that to the handlebar permanently.
And yes, when it starts to rain, I'll put my phone in my bag so it doesn't get wet.

Deus_Ex_Machina:
A readout of the speed and then cranking the throttle up slowly until that speed is reached would be perfect, but the problem is, how to control that. Because the controller would have to understand not only the current speed, but also the acceleration, so it accelerates at a more or less constant rate up to the target speed.

That's easy enough to do, if your Arduino knows the current speed. Do you have any way of knowing the speed?

A readout of the speed and then cranking the throttle up slowly until that speed is reached would be perfect, but the problem is, how to control that.

Many ways to do that. PID would be an approach for example.

The key, seems to me, would be to find a way to interface with your bike: read off speed, and change throttle, at the minimum.

I can install a magnet in one of the spoks and maybe get a hal-sensor on the fork, hell, I could install multiple magnets in the spokes to make the readout more accurate.
Multiply the amount of peaks per minute with the circumference of the wheel, and we have the current speed.
That should be easy enough, if I know what sensor to buy.

Knowing the bike's speed is only half the equation. How do you effect the throttle?

The throttle is a 0V-5V signal, which I can input either with a twist grip or a thumb throttle.

Here's a link to technical info for the controller

So, where do I start guys to get the first bit working.
Let's start with the most simple function and take it from there.

I would start with the throttle. Get a sketch going that will generate a desired analog output based on a variable.

From there, I would implement the pid or whatever control scheme you wish. This will drive the throttle variable based on speed target and actual speed.

Then I will write a piece to actually measure the speed.

From there, the display and input routines.

I would start with the throttle.

I disagree. I think you should start with the parts that won't kill you. Learn how to access the bikes speed, the switch input, the brake lever input, etc. BEFORE you try to actually control the speed of the bike.

Lest you think I'm being overly harsh, please realize that I have ridden motorcycles over 500,000 miles. My current two bikes and the 2 of the 4 I no longer own have all had cruise control from the factory. I have ridden less than 10 miles with cruise control engaged in all those miles. There are just too many things that can go wrong when YOU are not operating the throttle, even when it is fast and easy to override the cruise control.

The big problem with cruise control on a bike is that it lets you do other things while the computer is controlling the speed, when what you should be doing is devoting your full time and attention to operating the vehicle.

Those 10 miles? Less than a tenth of a mile at a time, while I adjusted a vent or a mirror on the right side.

Thank you guys for your answers.

As much as I would love to play around with the throttle right away, I agree, that the first thing would be to get a readout on sensors and display them. Then I could expand on the parameters I can manage. And once I have the parameters I need to change something else, we'll approach that.
Henry, I'd be happy to accept any help in programming so I can take a first look at what code actually looks like and see someting very basic that actually works before I try to expand on it.

Could you guys give me a shopping list of what to get?
Maybe we could start with the basic hardware for the Arduino (I don't even know which one or which kit to get)
a display (if android readouts are too difficult for the beginning)
and some sensors (temperature, hal sensors for speed and crank cadence, maybe a photo sensor to automatically switch on the backlight when it's too dark)

Maybe we could start with the basic hardware for the Arduino (I don't even know which one or which kit to get)

There are not that many things you need to be monitoring. I'd start with a UNO. It has 20 IO pins, which should be plenty to get started with, and is not too big or expensive.

a display (if android readouts are too difficult for the beginning)

There are two basic types - character based and graphic based. If you want to just show numbers, character based is fine. If you want to draw pictures, you need a graphic based model.

There are serial displays, which use just one pin, SPI models that connect to the SPI pins (11, 12, and 13 on a UNO), and those that use more pins. Price is generally inversely proportional to the number of pins used.

and some sensors (temperature, hal sensors for speed and crank cadence, maybe a photo sensor to automatically switch on the backlight when it's too dark)

Some of these (the photo sensor is a nice idea) may or may not already be present on your bike. (Perhaps you could tell us about it.)

I think that you'll be happier, in the long run, learning about the Arduino and how to connect it to the bike, of you start with safer projects. Take care, whatever you do.

Well, the cruise control is the thing I set out to accomplish and that is the mid term goal.
I understand that there are other smaller goals that need to come first.

As it stands now, I have no sensors on the bike.
The motor and the controler are still underway. The bike is still a regular 28" trekking bike with only non electric gadgets, apart from an insane 30W LED, which I'l exchange for a more reasonable bike light.
So, we're actually starting from scratch.

The controller used in the bike, will be a KU63 as sold by BMS battery. I posted a link of a description.
To start out, the conversion of the bike will be the installation of a 12s 5Ah LiPo battery pack, a fuse, the KU63 controller, a Cute Q100 motor in the front wheel (with hall sensors connected to the controller), a thumb throttle as the only throttle input and two Magura reed switches for the brake as kill switches for the throttle. So once I move any of the brake levers, the power to the engine will be cut...
So far so good.

What I would like to measure and implement:

  • Temperatures (ambient, motor, battery, controller)
  • Cadence (front wheel and crank)
  • foto sensor (for backlight on the display and later the bike light. My rear light already has such a sensor and a motion sensor that switches on the rear light when the bike moves and it's dark, so maybe we could hook it up to, so the flow of current is measure and once the light is on, and the current increases, we know it's dark or we just implement a foto sensor)
  • voltage from battery
  • current through the controller
  • Voltage and current USB port (I bought a DCDC stepdown converter to get 5V 3A from the 12s batteries to power my phone)
  • compass
  • calculate trip time (moving time)
  • average speed
  • distance
  • barometric sensor (elevation)
  • Ah consumption per km

I've drawn up a little picture in powerpoint of what I would like the interface to look like in the end

I am envisioning that the 9 fields are customizable.
In the settings you should be able so select which values the specific fields cycle through if you click them, say the "voltage" on the bottom right, could cycle through USB voltage, battery voltage, average curren and ambient temperature, while the one to its left would cycle only through current (now) and maximum current.
You can select any option for any field, making it completely modular for anyone to set up as they wish with all the sensors and values they have connected. Fields that have only one fixed setting like speed, could but used as switches when clicked, such as cruise control (which would make sense with the speed) The the speed would show the current speed and the target speed in a little corner.

As you can see, it's not the lack of ideas, that's stopping me, it's just that I lack the skills to implement it. A rugged 5" android device could be the killer device for any bicycle geek.

But let's start small.

http://www.ebay.de/itm/Arduino-Uno-R3-ATmega328-Microcontroller-Entwicklungsboard-USB-Cable-/230828847676?pt=Wissenschaftliche_Geräte&hash=item35be78b23c

Is this, what I should buy? With all the sensors and android interface that I will definitely want, is this the right one, or should I maybe get a set or some other things aswell. I'd rather have everything I need to start out and not start buying more stuff in 2 weeks. I don't know, maybe there is a set of sensors. Can this Uno handle all the sensors and outputs that I want to do, or would I need something bigger for that?