Go Down

Topic: dual axis solar tracker + pro mini 3.3 volts + two dc motors + 4 photo resistors (Read 674 times) previous topic - next topic

knightridar

Poor choice of words meant that the power supply works better than the solar panel and voltage buck converter combination.

The power supply allows me to vary voltage between 0 to 30 volts and current between 0 to 5 amps.

Robin2

Still not nearly enough information.

For example you have described the limits of your power supply but you have not told us what settings you have it at when the project is working.

Post a clear diagram of the circuit for the system that works and another for the system that does not so we can easily compare them.

What sort of battery are you using with the solar panel?
And post a link to the datasheet for the buck converter.

And tell us everything else that might help us to help you.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

knightridar

Okay... it's working now.


I finally bought a 12 volt lead acid battery,

12 volts, 1.3Ah

https://grabcad.com/library/kt-1213-12-v-1-3-ah-agm-lead-acid-battery-1

I bought a solar charge controller to to charge the battery.
MODEL: LMS2430.
BRAND: HOMPIE (not sure if this is reseller or brand?)
12/24 V, 30 A (overkill for my 24 volt, 10 watt panel)

I have the battery hooked up to the charge controller and now I hooked up the LM2596 VOLTAGE BUCK CONVERTER to the battery. The voltage is dropped down from 12 volts to 6 volts to power my 6 volt motors. They are successfully moving.

When I tested my 6 volt motors with the power supply they run at 50 mA at no load (matches with motor data sheet description).

Here is a link to the buck converter I bought:
https://www.amazon.com/gp/product/B0140SW9D8/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

The website below provides more details for the specs of the buck converter:
https://www.importitall.co.za/Qunqi-LM2596-Buck-Converter-4040-to-1337V-Adjustable-StepDown-Power-Module-with-LED-Display-Voltmeter-ap-B0140SW9D8.html

I've also attached a pdf for the lm2596 chip but not the converter itself.

Here is my latest code for reference:

Code: [Select]

// Special thanks to Geo Bruce on instructables.com for his version of the code.
// Enable A and Enable B pins on  dual motors h-bridge must be connected to two pwm (pulse width modulation) pins on arduino uno/micro/pro mini: 3,5,6,9,10,11.
int enA = 3; int in1 = 4; int in2 = 5; // motor azimuth adjustment
int enB = 9; int in3 = 7; int in4 = 8; // motor elevation adjustment

void setup()
{
 Serial.begin(9600); // initialize the serial port
 pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(enB, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); // set all the motor control pins to outputs
}
void loop()
{
 // LIGHT SENSOR (in this case a Light Dependent Resistor) pin connections and analog pin on respective arduino board
 int br = analogRead(0); // BOTTOM RIGHT
 int tr = analogRead(1); // TOP RIGHT
 int tl = analogRead(2); // TOP LEFT
 int bl = analogRead(3); // BOTTOM LEFT
 int delaytime = analogRead(A6)*2; // control delay time in milliseconds of LIGHT SENSOR readings
 int tolerance = analogRead(A7)/4; // set range of tolerance between LIGHT SENSOR readings

//print LIGHT SENSOR values to serial monitor for debugging
 Serial.println(tl); Serial.println(bl); Serial.println(tr); Serial.println(br); Serial.println(delaytime); Serial.println("ms"); Serial.println(tolerance); Serial.println("photoresistor difference"); Serial.println();

  int count = 0; //start millisecond count of LIGHT SENSOR readings
  count++; //incremental count increase, continues to show LIGHT SENSOR results

  int avt = (tr + tl) / 2; // average value top
  int avd = (bl + br) / 2; // average value down
  int avl = (tl + bl) / 2; // average value left
  int avr = (tr + br) / 2; // average value right
 
  int dv = avt - avd; // average difference of top and bottom LIGHT SENSORS
  int dh = avl - avr;// average difference of left and right LIGHT SENSORS

if (-1*tolerance > dv || dv > tolerance) // check if the difference in top/bottom LIGHT SENSORS is greater than tolerance
{
  if (avt > avd) // if average LIGHT SENSOR values on top side are greater than on bottom side then elevation motor rotates CLOCKWISE
  {
  digitalWrite(in3, LOW);  digitalWrite(in4, HIGH); analogWrite(enB, 254); // set speed out of possible range 0~255
  Serial.println("ELEVATION MOTOR MOVES CLOCKWISE");
  Serial.println("   ");
  }
  else // if average LIGHT SENSOR values on bottom side are greater than on top side then elevation motor rotates COUNTERCLOCKWISE
  {
  digitalWrite(in3, HIGH);  digitalWrite(in4, LOW); analogWrite(enB, 254);
  Serial.println("ELEVATION MOTOR MOVES COUNTERCLOCKWISE");
  Serial.println("   ");
  }
}
  else if (-1*tolerance < dv || dv < tolerance) // if difference is smaller than tolerance, STOP elevation motor
  {
  digitalWrite(in3, LOW); digitalWrite(in4, LOW);
  Serial.println("ELEVATION MOTOR STOPS");
  Serial.println("   ");
  }

if (-1*tolerance > dh || dh > tolerance) // check if the difference in left and right LIGHT SENSORS is within tolerance range
{
  if (avl > avr) // if average LIGHT SENSOR values on left side are greater than right side, azimuth motor rotates CLOCKWISE
  {
  digitalWrite(in1, HIGH);  digitalWrite(in2, LOW); analogWrite(enA, 254);
  Serial.println("AZIMUTH MOTOR MOVES CLOCKWISE");
  Serial.println("   ");
  }
  else // if average LIGHT SENSOR values on right side are greater than on left side, azimuth motor rotates COUNTERCLOCKWISE
  {
  digitalWrite(in1, LOW);  digitalWrite(in2, HIGH); analogWrite(enA, 254);
  Serial.println("AZIMUTH MOTOR MOVES COUNTERCLOCKWISE");
  }
}
  else if (-1*tolerance < dh || dh < tolerance) //if difference is smaller than tolerance, STOP azimuth motor
  {
  digitalWrite(in1, LOW);  digitalWrite(in2, LOW);
  Serial.println("AZIMUTH MOTOR STOPS");
  Serial.println("   ");
  }
  delay(delaytime);
}



Thanks!

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

knightridar

I just wanted to give anybody that may be interested an update.

I WAS ABLE TO GET IT TO WORK WITHOUT BATTERIES AGAIN!

;D

A few things I've changed:

1. I'm using a BTS7960 43A H-bridge High-power Motor Driver module
  (One for each motor, the L-298 H-bridges are known to inefficient and have voltage drop issues)

2. My PWM settings are maxed out at 255 now.

3. I'm not sure if this could have been an issue but there are more pins with this driver vs the L298 and
  there are enable pins for each direction of rotation, I'm wondering if these enable commands may
  have needed to be changed in my previous code using the L298 motor drivers.


Positive outcomes:

1.I'm using new motor drivers that can support up to 43 Amps.

2. I don't need to complete a ground connnection from these drivers to the arduino because they have an
  independent MCU. (One less wired connection that I have to make.)

https://www.aliexpress.com/item/Double-BTS7960-43A-H-bridge-High-power-Motor-Driver-module-smart-car/32819713287.html?spm=2114.search0104.3.16.Aeze26&ws_ab_test=searchweb0_0,searchweb201602_3_10152_10065_10151_10068_10130_10084_10083_10080_10082_10081_10110_10178_10137_10111_10060_10112_10113_10155_10114_5360015_10154_438_10056_10055_10054_10182_10059_100031_10099_10078_10079_10103_10073_10102_10189_10052_10053_10142_10107_10050_10051,searchweb201603_1,ppcSwitch_2&btsid=38950507-5a4b-4484-b927-b6aca95b799f&algo_expid=fe72560b-bae7-4787-858d-8ec79aa9426b-2&algo_pvid=fe72560b-bae7-4787-858d-8ec79aa9426b

I am using a small 5V solar panel to power the arduino.
I tried both my small 6V and 12V panels for my 6V motors and 12V motors.
Things move for sure.
Adding a battery would help for cloudy days.
I can tell the motors are not always running at their max torque/speed settings on cloudy days.

Here is my updated code:

Code: [Select]

// Special thanks to Geo Bruce on instructables.com for his version of the code.
// AZIMUTH and ELEVATION PWM pins on each h-bridge must be connected to FOUR PWM (pulse width modulation) pins on arduino. For uno/micro/pro mini they are: 3,5,6,9,10,11.
int AREN = 2; int ARPWM = 3; int ALEN = 4; int ALPWM = 5; // motor azimuth adjustment
int EREN = 7; int ERPWM = 6; int ELEN = 8; int ELPWM = 9; // motor elevation adjustment

void setup()
{
 Serial.begin(9600); // initialize the serial port
 pinMode(AREN, OUTPUT); pinMode(ARPWM, OUTPUT); pinMode(ALEN, OUTPUT); pinMode(ALPWM, OUTPUT);  // set all the motor control pins to outputs
 pinMode(EREN, OUTPUT); pinMode(ERPWM, OUTPUT); pinMode(ELEN, OUTPUT); pinMode(ELPWM, OUTPUT);
}
void loop()
{
 // LIGHT SENSOR (in this case a Light Dependent Resistor) pin connections and analog pin on respective arduino board
 int tr = analogRead(0); // top right
 int br = analogRead(1); // bottom right
 int tl = analogRead(2); // top left
 int bl = analogRead(3); // bottom left
 int delaytime = analogRead(A6)*2; // control delay time in milliseconds of LIGHT SENSOR readings
 int tolerance = analogRead(A7)/4; // set range of tolerance between LIGHT SENSOR readings

//print LIGHT SENSOR values to serial monitor for debugging
 Serial.println(tl); Serial.println(bl); Serial.println(tr); Serial.println(br); Serial.println(delaytime); Serial.println("ms"); Serial.println(tolerance); Serial.println("photoresistor difference"); Serial.println();

  int count = 0; //start millisecond count of LIGHT SENSOR readings
  count++; //incremental count increase, continues to show LIGHT SENSOR results

  int avt = (tr + tl) / 2; // average value top
  int avd = (bl + br) / 2; // average value down
  int avl = (tl + bl) / 2; // average value left
  int avr = (tr + br) / 2; // average value right
  
  int dv = avt - avd; // average difference of top and bottom LIGHT SENSORS
  int dh = avl - avr;// average difference of left and right LIGHT SENSORS

if (-1*tolerance > dh || dh > tolerance) // check if the difference in left and right LIGHT SENSORS is within tolerance range
{
  if (avl > avr) // if average LIGHT SENSOR values on left side are greater than right side, azimuth motor rotates CLOCKWISE
  {
  digitalWrite(AREN, HIGH); analogWrite(ARPWM, 255); // set speed out of possible range 0~255
  digitalWrite(ALEN, HIGH);  digitalWrite (ALPWM, LOW);
  Serial.println("AZIMUTH MOTOR MOVES CLOCKWISE");
  Serial.println("   ");
  }
  else // if average LIGHT SENSOR values on right side are greater than on left side, azimuth motor rotates COUNTERCLOCKWISE
  {
  digitalWrite(ALEN, HIGH); analogWrite(ALPWM, 255);
  digitalWrite(AREN, HIGH); digitalWrite(ARPWM, LOW);
  Serial.println("AZIMUTH MOTOR MOVES COUNTERCLOCKWISE");
  Serial.println("   ");
  }
}
  else if (-1*tolerance < dh || dh < tolerance) //if difference is smaller than tolerance, STOP azimuth motor
  {
  digitalWrite(AREN, LOW);  digitalWrite(ALEN, LOW);
  Serial.println("AZIMUTH MOTOR STOPS");
  Serial.println("   ");
  }

if (-1*tolerance > dv || dv > tolerance) // check if the difference in top/bottom LIGHT SENSORS is greater than tolerance
{
  if (avt > avd) // if average LIGHT SENSOR values on top side are greater than on bottom side then elevation motor rotates CLOCKWISE
  {
  digitalWrite(EREN, HIGH); analogWrite(ERPWM, 255);
  digitalWrite(ELEN, HIGH); digitalWrite(ELPWM, LOW);  
  Serial.println("ELEVATION MOTOR MOVES CLOCKWISE");
  Serial.println("   ");  
  }
  else // if average LIGHT SENSOR values on bottom side are greater than on top side then elevation motor rotates COUNTERCLOCKWISE
  {
  digitalWrite(ELEN, HIGH); analogWrite(ELPWM, 255);
  digitalWrite(EREN, HIGH); digitalWrite(ERPWM, LOW);
  Serial.println("ELEVATION MOTOR MOVES COUNTERCLOCKWISE");
  Serial.println("   ");
  }
}
  else if (-1*tolerance < dv || dv < tolerance) // if difference is smaller than tolerance, STOP elevation motor
  {
  digitalWrite(EREN, LOW);  digitalWrite(ELEN, LOW);
  Serial.println("ELEVATION MOTOR STOPS");
  Serial.println("   ");
  }
  delay(delaytime);
}





Robin2

Jeez.  I have just realized that you have the exact same project in two different Threads (the other one) and I have been wasting my time dealing with both of them.

Don't double post again.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up