Ok...
This has been answered NUMEROUS times..
Make sure you have a front white light, rear red light, pedals and have it under 50cc and go to the DMV and have it registered (it MUST be) as a home made moped. (say nothing about a bicycle with a motor, it's a home made moped).
You may NOT ride it on the sidewalk under motor power (engine MUST be off).
You need a Drivers license to ride one.
With all that being said, in some towns, the police won't care.
In some towns, they'll just yell at you.
In some towns, they stop you every other day.
In some towns, they'll give you a summons for unregistered motor vehicle.
(If you don't have a license, they will ticket you for unlicensed driver, as well)
If it doesn't have operable pedals, (depending on size of engine) it's considered a scooter or motorcycle.
That's all there is to it.
If you really want EVERY STATUTE that I'm using as the basis of this discussion, let me know and I will (AGAIN) lay them all out for all to see.
IF you have an electric bicycle (with operable pedals) and it's not capable of achieving speeds greater than 20mph, then it's still considered just a bicycle.