Let's make an #e-bike out of garbage. You will need.

* One dumpster bike (free)
* One cargo rack (free)
* One hub motor (dumpster dived, but about $200 new)
* One motor controller (about $20-$50 new)
* A battery (recycled, but about $100 new)

I'm going to rewire some used 12v lithium batteries to make a 36v battery with a smart battery management system (monitor charge from your phone).

I started by installing the front wheel, installing the cargo rack, mocking up where I'll mount the battery, controller and throttle.

Next I'll wire the key components, get the wheel turning, then look at which of the other wires need to be connected. (Some brake cutoffs, pedal sensor, maybe a key lock to see if a wild @alice appears).

This happens to be a folding bike, because that's what was at the front of the bike pile.

Ookay, part 2 of "dumpster e-bike", getting the motor running.

First, make sure you have the wheel the right way around. That's probably power cable on the right hand side. A hub motor has a clutch inside and only motorises one way.

Invert the bike, then hook up the three motor wires to the motor, connect the 5-wire hall sensor plug if you have one, and then join the "self learning" wire. Connect the battery and the wheel should turn slowly. Give it ten seconds or so, then power down.

Disconnect the "self learn" wires, and add a throttle. Reconnect the battery. Give the throttle a gentle turn (I've used a potentiometer for initial testing as then I don't have to fight against a spring). The motor should turn.

Spin your pedals and observe the back wheel. If the front wheel is turning the wrong way, swap any two of the motor wires and it should go the other way. Try another two wires if not.

Arguably, your bike is now rideable. But don't.

Things left to do are

* Mount the battery securely
* Mount the motor controller securely in a weatherproof cover (you can buy zip-up pouches for this purpose)
* Fit some brake cut-out switches
* Look through all the other wires on the motor controller and see if any of them look like fun.
* Maybe fit a speedometer.

Here's the motor running. Super quiet, the ventilation fan in the roof is louder.

This is my "daily driver" e-bike. Purchased for $200 as "battery does not charge", the battery was fine, but the controller was blown. The bike is so old it was clearly designed for lead batteries, the the lithium battery only fills one third of the otherwise empty battery. box. I ripped off all the plastic fairings, and sourced a new controller and throttle as a set. I fitted an anti-theft handlebar basket (should be a pink one for maximum effectiveness) and it just goes.

Electronics: https://s.click.aliexpress.com/e/_c2QulvH3 or https://www.aliexpress.com/item/1005008500641642.html
Waterproof cover for electronics: https://www.aliexpress.com/item/1005005475025309.html

@Unixbigot youvcould propably even get more range with some drop-in #LiFePO4 cells designed to replace lead-acid batteries...
@kkarhan yeah when the battery that came with this bike expires I'll build a bigger pack that fills the whole box. It comfortably gets me to work and back on a single charge for now. Today I've been testing a boost regulator to charge my 36v battery from a 100W solar panel.

@Unixbigot makes sense.