DIY Adjustable Constant Load (Current & Power)

33,885

175

43

About: Awesome Electronics Tutorials, Projects and How To´s

In this project I will show you how I combined an Arduino Nano, a current sensor, an LCD, a rotary encoder and a couple of other complementary components in order to create an adjustable constant load. It features a constant current and power mode and can handle a maximum of 30V and 20A if your heatsink design can handle it. Let's get started!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Watch the Video!

The video gives you all the information you need to make your own adjustable constant load. During the next steps though, I will present you some additional information.

Step 2: Order the Components!

Step 3: Create the Circuit!

Here you can find the schematic as well as pictures of my finished circuit. Feel free to use it as a reference for your own circuit.

Step 4: Upload the Code!

Here you can download the code for the project. Upload it to the Arduino Nano through the Arduino IDE

Also make sure to download/include this library:

https://github.com/fdebrabander/Arduino-LiquidCrys...

Step 5: Finish the Project!

All that is left to do is mounting all the components inside your enclosure.

Step 6: Success!

You did it! You just created your own adjustable constant load!

Feel free to check out my YouTube channel for more awesome projects: http://www.youtube.com/user/greatscottlab

You can also follow me on Facebook, Twitter and Google+ for news about upcoming projects and behind the scenes information:

https://twitter.com/GreatScottLab

https://www.facebook.com/greatscottlab

3 People Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

43 Discussions

0
None
šušuluskZ

Question 4 months ago

Hi, I have built it and it works. But there is a problem, it ads about 200mA every time. My current sensor outputs at 0A about 2.1V, so I tried to change the zerocurrent from 514 to 430 but when I tried it, the load shorted, when I changed back to 514, it worked just like before. I thought that the 514 value is (1023/5*2,5) so I calculated (1023/5*2,5) but didnt work, can someone help me?

1 answer
0
None
maliŽ1šušuluskZ

Answer 3 days ago

I added this piece of code...
float zerocurrent = 514;
changed to
float zerocurrent;
At the end of setup section I added
zerocurrent=calibrate_sensor();
so the Sensor will be calibrated once at start od Code, and function to calibrate Current Sensor (without Currentflow)

int calibrate_sensor(){
uint16_t acc = 0;
for (int i = 0; i < 20; i++) { // take 20 samples, for better accuracy
acc += analogRead(currentsense);
}
int zero = acc / 20; // divide result with number of samples
return zero;
}
Also, on my Arduino Nano i noticed that the reference Voltage for analogRead depends on Power supply Voltage. I.e. if Arduino is powered from Computer USB, and shows one reading for the analog input, and when is powered width stable 5.2V (DIY DC-DC converter), it shows another measured Value for the same signal.
Because of that, I added another Function
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(20); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1125300L / result; // Back-calculate AVcc in mV
// Serial.println(result/1000.0);
return result;
}

and defined a variable
float refV;
and called it once in setup
refV = readVcc();
and changed the calculation for Current and Voltage from
curcurrent = ((curcurrentraw - zerocurrent) * (5000.00 / 1023.00) / 100.00);
to
curcurrent = ((curcurrentraw - zerocurrent) * (refV / 1023.00) / 100.00);
1
None
kiwidave72

Question 9 months ago

When looking at the code, i can’t see how you are setting the PWM out? You set it to an output on pin 9 and set it to low, but I can see anything else.

3 answers
0
None
maliŽ1JohnW669

Reply 3 days ago

Think the code for PWM iz wrong. On my Arduino Nano V3 I've tryed the code (modiffied for Nokia 5110 LCD) for now without load and MOSFET, just the code and Current sensor, and OCR1A register goes Skyhigh (to 65534) and counts in a loop. I.e. when register reaches 65534, it starts from beginning (0). I simulated Current flow with a small magnet near current sensor.

For 100% DutyCycle the Value of register is 2047.
I modified the Code for current- and power mode ,

if (curcurrent < current) {
OCR1A++; // increase value of register OCR1A
} else {
if(OCR1A>0){ // If value of register greater than 1
OCR1A = OCR1A - 1; // decrease it
} else { // and if value is smaller than 1
OCR1A=0; // hold it on 0, or it will go around to the max
} // value and count down
}
OCR1A=constrain(OCR1A,0,2047);// hold value of register between 0 and 2047
counter++;
IMG_20191011_002008.jpgIMG_20191011_002025.jpg
0
None
waileunkiwidave72

Answer 5 months ago

yes, I too cannot see the code that made adjustment to current, other than to the screen

0
None
sk8nfooldavorin.perkovic

Reply 1 year ago

Yes - Vcc is red and GND is black. That's not what I asked. Where are the binding posts in the schematic?

0
None
davorin.perkovicChristianR154

Reply 9 months ago

Pozdrav, Kristijane. Vidim !

Mosfet se kontrolira PWM signalom na pinu D9:

#define pwm 9 // Pin D9
.....
....
....
void setup() {
...
digitalWrite(pwm, LOW); // Isključi mosfet
...
// Postavljanje generiranja PWM signala
TCCR1A = 0;
TCCR1A = (1 << COM1A1) | (1 << WGM11);
TCCR1B = 0;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
ICR1 = 2047;
OCR1A = 0;
...
}

void loop() {
...
...
// Kontrola mosfeta kada treba mijenjati struju
if (curcurrent < current) {
OCR1A++; // Povećaj širinu PWM signala koji ide na mosfet
}
else {
OCR1A = OCR1A - 1; // Smanji širinu PWM signala koji ide na mosfet
}
...
...
...
}

https://en.wikipedia.org/wiki/Pulse-width_modulation
https://sites.google.com/site/qeewiki/books/avr-guide/pwm-on-the-atmega328

0
None
maliŽ1davorin.perkovic

Reply 3 days ago

Ali ovaj kod ne valja, jer nigdje ne ograniči maksimalnu vrijednost registra, pa on broji do 65535, pa opet krene od nule, u krug.
Isprobao sam na svojem Arduino Nano V3, "na suho" bez baterije i MOSFET-a, samo sa Senzorom struje i malim magnetom koji je simulirao protok struje. I ako struja pada i registar dođe do 0, opet krene od 65534 (što bi bilo 3200% duty cycle). I ako registar dođe do, recimo 10000, i tada se struja pojača, krene brojati unatrag, ali PWM smanji Duty Cycle tek kada register dođe do 2047 i tek ga data počne smanjivati (to potraje dvije-tri sekunde). Da sam probao sa baterijom i MOSFETom, bilo bi dima :D
Nakon modifikacije koda je sve u redu
if (curcurrent < current) {
OCR1A++; // increase value of register OCR1A
} else {
if(OCR1A>0){ // If value of register greater than 1
OCR1A = OCR1A - 1; // decrease it
} else { // and if value is smaller than 1
OCR1A=0; // hold it on 0, or it will go around to the max
} // value and count down
}
OCR1A=constrain(OCR1A,0,2047);// hold value of register between 0 and 2047
counter++;
0
None
davorin.perkovicsk8nfool

Reply 9 months ago

The PWM signal is converted to analog voltage by a low pass filter (R1 C3) and brought to Q1's gate . Depending on that voltage, Q1 conducts more or less current, that means it acts as a variable resistor (i.e. load)

0
None
Sals61

20 days ago on Step 6

Greetings to all users
Hi my name is Stefano from Italy. I follow the channel of Great Scott by youtube. Very very nice.
Congratulations for the preparation and explanations.

0
None
FabioC129

4 months ago

Can I add a second IRFZ44N to distribuite the power disipattion and connect it to the second output of the mosfet driver? Do I need equalizer resistors for that task? Thanks

0
None
Arisma

5 months ago

Excellent instructable my friend!!! I built it and it is working excellent! I have also designed and 3D printed a case for it. If you or anyone else is interested, I can sent you the stl. It is a huge tool for me that helps to discharge my LiPo batteries (alongside with a low voltage beeper) when the weather is bad to fly...
Allow me to make a modification. You can add a 1K resistor connected from arduino's D9 to GND, because if you have connected a battery (especially a LiPo one) with a lot of Amperes (or a big load) before Arduino boots, the load hits maximum, and the fuses are burnt instantly.
Keep up the good work! ;)

1 reply
0
None
darkathArisma

Reply 5 months ago

Could I ahve that stl please?