Regenerative brake control of dc motors using arduino

Hi, Can someone please help me with how to write a program on regenerative brake control of electric bicycle dc motor? I have two(2) inputs and two(2) outputs in the arduino. The two inputs are drive and brake signals. The 2 outputs are to control 2 mosfet switches. The program should work in a way that when one mosfet is on, the other must be off. Both mosfets cannot be on at the same time. Your reply will be very appreciated. Thank you.

I voted for Arduino. I hope that helps, though I can't really see how it will.

I don’t understand these polls. I can only ever see my vote, which was for program in this instance.

I don't understand these polls.

I figure that if people can't see the "Post new topic" button right next to the "Start new poll" button, that they aren't good readers, so I've quit trying to help pollers. (Unless the poll IS legitimate).

But, once you vote, the forum software shows the current status of the poll. At least, for me it does.

If you did vote, I can't see it. I see Total voters: 1.

If you did vote, I can't see it. I see Total voters: 1.

Oops. I forgot to push the submit button.

Ah. That's better. I like a balanced result.

buhari: Can someone please help me with how to write a program on regenerative brake control of electric bicycle dc motor?

Learn how to compile, load and run a sketch.

Learn to write a simple sketch that reads inputs.

Learn to write a simple sketch that sets outputs.

Write a sketch that sets the outputs according to the inputs using the logic you described above.

Learn how to design a circuit to drive your mosfets from the Arduino output. Implement two of those circuits and connect up to the output pins used by your sketch.

Et voila.

PS I voted for 'program'.

PS I voted for 'program'.

Did you submit your vote? I still only see two votes.

Apparently not - I might have ticked my choice and then clicked 'view results'.

Sheesh, there were only two buttons there. Trust me to pick the wrong one.

I voted for Arduino, not for the regenerative brakes, but because I can make blinky lights for my bike with it XD

Yeah, but you need a program to make it work.

This is the program I have created:

int drive = 10;         
int brake = 11;
int IN1 = 13;
int IN2 = 5;
int val = 0;
int val2 = 0;

void setup()  
  pinMode(IN1, INPUT);
  pinMode(drive, OUTPUT);
  pinMode(IN2, INPUT);
  pinMode (brake, OUTPUT); 

void loop()                                     
  val = digitalRead(IN1);
  val2 = digitalRead(IN2);
  if (val == HIGH && val2 == LOW)
    analogWrite(drive, 255);
    digitalWrite(brake, HIGH);
 if (val == LOW && val2 == HIGH)
     for(int r = 255; r >= 0; r--)     
     analogWrite(brake, r);                
     digitalWrite(drive, LOW);  
  else {
  digitalWrite(drive, LOW);
  digitalWrite(brake, LOW);

Moderator edit: And there’s the code between CODE TAGS.

The program should work this way:

  1. If ‘drive’ is enabled and ‘brake’ is disabled, motoring takes place with DC motor at constant speed.
  2. If ‘brake’ is enabled and ‘drive’ is disabled, regeneration takes place with DC motor’s speed reducing in steps.

The first (motoring) part works but the second(regeneration) doesn’t. Can anyone please help me. It’s my final year project. The circuit diagram is attached.


i am also doing a final year project on regenerative braking from a DC motor using ardunio, i am new to arduino and not that experienced in programming in general, any insight would be greatly appreciated, buhari i know what you are going through mate lol

buhari: the second(regeneration) doesn't.

What is wrong with it?

Wow that is one dangerous circuit, there is a dead short if both FETs are turned on. Turn on the top one for motor drive. Turn on the bottom one for breaking. Turn on both for smoke.