Eindschakelaars werken niet

Projecten die niet passen in bovenstaande onderwerpen
Gebruikers-avatar
Berichten: 241
Geregistreerd: 22 Jan 2013, 16:40

Re: Eindschakelaars werken niet

Berichtdoor zuid » 10 Mei 2018, 18:10

Ik heb nog even de pagina's van de site doorgelezen waar volgens mij ook je plaatjes vandaan komen:
https://howtomechatronics.com/tutorials ... -h-bridge/

Daar viel mij de volgende tekst op:
"Next are the logic control inputs. The Enable A and Enable B pins are used for enabling and controlling the speed of the motor. If a jumper is present on this pin, the motor will be enabled and work at maximum speed, and if we remove the jumper we can connect a PWM input to this pin and in that way control the speed of the motor. If we connect this pin to a Ground the motor will be disabled."

Als ik het goed begrijp dan heb je geen verbinding tussen de Arduino en de PWM poorten nodig als de jumper op het L298N board aanwezig zijn.
(zou je weer twee poorten op de Arduino over hebben :) )

Duidelijker hierover is de site:
http://www.instructables.com/id/Arduino ... -Controll/

Het zou kunnen dat de L298N het niet begrijpt als er 5 volt op de enableA staat en de jumper is er ook.
m.v.g.
Nico

Advertisement

Gebruikers-avatar
Berichten: 256
Geregistreerd: 05 Apr 2018, 00:44
Woonplaats: ALKMAAR

Re: Eindschakelaars werken niet

Berichtdoor Gompy » 10 Mei 2018, 18:28

Deze stukjes code moet ik nog wijzigen
digitalWrite(enA, HIGH);
en
digitalWrite(enB, HIGH);

enA en enB komen dan te vervallen en voor motor stop komt dan te staan.
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
en
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);

En heb dan inderdaad weer 2 poortjes vrij......als ik het tenminste goed gelezen heb.

De code is nog lang niet klaar, ik ben nog aan het leren.

Mvg, Rob

Gebruikers-avatar
Berichten: 256
Geregistreerd: 05 Apr 2018, 00:44
Woonplaats: ALKMAAR

Re: Eindschakelaars werken niet

Berichtdoor Gompy » 10 Mei 2018, 22:47

Sketch aangepast zonder enA en enB en werkt naar behoren.
Voorlopig heb ik even voor de diode oplossing gekozen als eindafschakeling, maar wil toch voor de softwarematige uitvoering gaan.
Dit omdat ik anders behoorlijk grote microswitchen en dikke draden zou moeten gebruiken ivm de stromen door de motoren.

Ik begrijp nog niet goed hoe de IF, ELSE en de IF ELSE werk....wel dat ze in in deze volgorde moeten werken, maar kan ik meerdere IF(en), ELSE(n) en ELSE IF(en) gebruiken ?
Kan ik bv onder deze regel

else if (-1*tolerance < dh || dh < tolerance) //if difference is smaller than tolerance, STOP azimuth motor

Nog een else if gebruiken zoals

else if (switch1 == LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
Serial.println("ELEVATION MOTOR");
Serial.println(" END ");

Code: Alles selecteren
// motor azimuth adjustment
int in1 = 9;
int in2 = 10;
// motor elevation adjustment
int in3 = 11;
int in4 = 12;

void setup()
{
 
 Serial.begin(9600); // initialize the serial port

}
void loop()
{
// LIGHT SENSORS
 int tr = analogRead(0); // LDR top right / brown
 int br = analogRead(1); // LDR bottom right / green
 int tl = analogRead(2); // LDR top left / yellow
 int bl = analogRead(3); // LDR bottom left / orange
 
// control delay time in milliseconds of LIGHT SENSOR readings
 int delaytime = analogRead(A7)*2;
// set range of tolerance between LIGHT SENSOR readings - Arduino LED indicate time
 int tolerance = analogRead(A6)/4;

//print LIGHT SENSOR values to serial monitor for debugging
 //print LIGHT SENSOR values to serial monitor for debugging
 Serial.println("--------------------");
 Serial.println(tl);
 Serial.println(bl);
 Serial.println(tr);
 Serial.println(bl);
 Serial.println();

 Serial.print("Delaytime\t");
 Serial.print(delaytime);
 Serial.println();
 Serial.print("Tolerance\t");
 Serial.print(tolerance);
 Serial.println();
 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
  {

// set motor Elevation enable
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  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);
  Serial.println("ELEVATION MOTOR MOVES COUNTERCLOCKWISE");
  Serial.println("   ");

  }
}
  else if (-1*tolerance < dv || dv < tolerance) // if difference is smaller than tolerance, STOP elevation motor
  {

// set motor Elevation stop
  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
  {

// set motor Azimuth enable
  digitalWrite(in1, HIGH);
  digitalWrite(in2, 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(in1, LOW);
  digitalWrite(in2, HIGH);
  Serial.println("AZIMUTH MOTOR MOVES COUNTERCLOCKWISE");
  Serial.println("   ");

  }
}
  else if (-1*tolerance < dh || dh < tolerance) //if difference is smaller than tolerance, STOP azimuth motor
  {
// set motor Azimuth enabl
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  Serial.println("AZIMUTH MOTOR STOPS");
  Serial.println("   ");
  }
  delay(delaytime);
}


Mvg, Rob

Vorige

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 12 gasten