-
~ hard- & softwareupdate ~
04/01/2017 at 17:07 • 2 commentsToday I added two transistors to my prototyping-shield. Their purpose is to cut down the energy-consumption of the servo and the DC-motor, if their are not in use.
In order to get faster and better results I also did some coding.
Special thanks goes out to @Stefan-Xp who gave me a few really good advices. I hope the programming got a little bit better. :D
Here you can see the result:
#include <Servo.h> Servo xServo; int positionServo = 90; // Anfangsposition und Speicher für Gradstellung des Servos / startposition //Pin-Belegung int const DCMotorNegative = 8; int const DCMotorPositive = 7; int const endPosition1 = 6; int const endPosition2 = 5; int const movingOFF = 4; int const powerServo = 3; int const powerDCmotor = 2; // Sensorwerte / values of the sensors int valueLDR1 = 0; int valueLDR2 = 0; int valueLDR3 = 0; int valueLDR4 = 0; int valueTiltSwitch = 0; // Präzision der Motoren / accuracy of the motors int DCaccuracy = 5; int servoAccuracy = 8; //Endpositionstaster-Speicher / endposition memory int endPositionState1 = LOW; int endPositionState2 = LOW; int lastEndPositionState1 = LOW; // the previous reading from the input pin int lastEndPositionState2 = LOW; // the previous reading from the input pin // Zeitkonstanten/ timevalues long lastAdjustmentTime = 0; long sleepTime = 60000; long activeTime = 80000; long lastDebounceTime1 = 0; // the last time the output pin was toggled long lastDebounceTime2 = 0; // the last time the output pin was toggled long debounceDelay = 30; // the debounce time; increase if the output flickers //Prädeklaration void turnServo (); void endPositionReading (); void turnDC (); void setup() { Serial.begin(9600); xServo.attach(9); xServo.write(positionServo); pinMode(A0, INPUT); pinMode(A1, INPUT); pinMode(A2, INPUT); pinMode(A3, INPUT); pinMode(A4, INPUT); pinMode(A5, INPUT); pinMode(powerDCmotor, OUTPUT); pinMode(powerServo, OUTPUT); pinMode(movingOFF, INPUT_PULLUP); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(12, INPUT); pinMode(13, INPUT); pinMode(DCMotorPositive, OUTPUT); // Pin 7 pinMode(DCMotorNegative, OUTPUT); // Pin 8 pinMode(endPosition1, INPUT); // Pin 6 pinMode(endPosition2, INPUT); // Pin 5 void endPositionReading (); digitalWrite(powerServo, LOW); // schaltet Spannung ab / cuts down power digitalWrite (powerDCmotor, LOW); } void loop() { // 60s Schlafzustand, 20s aktiv/ 60s sleeping time, 20s active lastAdjustmentTime = millis(); if ( (millis() - lastAdjustmentTime) > sleepTime ) { while ( (millis() - lastAdjustmentTime) < activeTime ) { // Anhalten der Bewegung, Messen der Kondensatorspannung / stopping movement, measure capacitor-voltage while ( digitalRead(movingOFF) == LOW ) { delay(1000); float voltage = 0; voltage = analogRead(A0); voltage = map(voltage, 0, 1023, 0, 5000); voltage = voltage / 87 ; Serial.print ("Spannung: "); Serial.print (voltage); Serial.println (" V"); } //Auslesen der LDRs und des Kipptasters / reading of the LDRs and of the tilt switch valueLDR1 = analogRead (A1); valueLDR2 = analogRead (A2); valueLDR3 = analogRead (A3); valueLDR4 = analogRead (A4); valueTiltSwitch = analogRead (A5); turnDC (); turnServo (); delay(25); } } } void turnDC () { //Vergleichen von LDR2 und LDR4, je nachdem dann folgt Bewegung / comparing LDR2 and LDR4 if ( (valueLDR2 - valueLDR4) > DCaccuracy ) { digitalWrite (powerDCmotor, HIGH); endPositionReading (); if ( endPositionState2 == HIGH) { digitalWrite(DCMotorPositive, HIGH); delay (10); digitalWrite(DCMotorPositive, LOW); } digitalWrite (powerDCmotor, LOW); } if ( (valueLDR2 - valueLDR4) < - DCaccuracy ) { digitalWrite (powerDCmotor, HIGH); endPositionReading (); if ( endPositionState1 == HIGH) { digitalWrite(DCMotorNegative, HIGH); delay (10); digitalWrite(DCMotorNegative, LOW); } digitalWrite (powerDCmotor, LOW); } } void turnServo () { int OldPositionServo; OldPositionServo = positionServo; //Vergleichen von LDR1 und LDR3/ comparing LDR1 and LDR3, if ( positionServo > 0 && ((valueLDR1 - valueLDR3) > servoAccuracy) && valueTiltSwitch < 100) { positionServo = positionServo - 1 ; DCaccuracy = 5; } //Erhöhen der Genauigkeit des DC-Motors, wenn Servo bei 0° / increasing dc-motor accuracy when reaching 0° if ( positionServo == 0 && ((valueLDR1 - valueLDR3) > servoAccuracy)) { DCaccuracy = 1; } if ( positionServo < 180 && ((valueLDR1 - valueLDR3 ) > servoAccuracy) && valueTiltSwitch > 1000) { positionServo = positionServo + 1 ; DCaccuracy = 5; } // Erhöhen der Genauigkeit des DC-Motors, wenn Servo bei 180° / increasing accuracy of the dc-motor when reaching 180° if ( positionServo == 180 && ((valueLDR1 - valueLDR3 ) > servoAccuracy)) { DCaccuracy = 1; } if ( positionServo < 180 && ((valueLDR1 - valueLDR3) < - servoAccuracy) && valueTiltSwitch < 100) { positionServo = positionServo + 1 ; DCaccuracy = 5; } if ( positionServo > 0 && ((valueLDR1 - valueLDR3) < -servoAccuracy) && valueTiltSwitch > 1000) { positionServo = positionServo - 1 ; DCaccuracy = 5; } if ( OldPositionServo != positionServo ) { digitalWrite (powerServo, HIGH); //Serial.print ("positionServo: "); //Serial.println (positionServo); xServo.write(positionServo); digitalWrite (powerServo, LOW); } } void endPositionReading () { int reading1 = digitalRead(endPosition1); int reading2 = digitalRead(endPosition2); //Entprellen Endpositionstaster 1 if (reading1 != lastEndPositionState1) { lastDebounceTime1 = millis(); } if ((millis() - lastDebounceTime1) > debounceDelay) { if (reading1 != endPositionState1) { endPositionState1 = reading1; } } //Entprellen Positionstaster 2 if (reading2 != lastEndPositionState2) { lastDebounceTime2 = millis(); } if ((millis() - lastDebounceTime2) > debounceDelay) { if (reading2 != endPositionState2) { endPositionState2 = reading2; } } lastEndPositionState1 = reading1; lastEndPositionState2 = reading2; //Anpassen der Servo-Genauigkeit / increasing servo accuracy when reaching endposition switch if ( endPositionState1 == LOW || endPositionState2 == LOW ) { servoAccuracy = 1; } else { servoAccuracy = 8; } }
-
~ code of my project ~
03/30/2017 at 17:20 • 3 commentsIf you have any improvements to my code please tell me !! :) I`m still quite a noob in programming so it would be great if you guys could help me and tell me what i can do better or i did wrong!!
Best regards!!
Down there you can see my "code":
#include <Servo.h> Servo xServo; int positionServo = 90; // Anfangsposition und Speicher für Gradstellung des Servos / startposition int const DCMotorNegative = 8; int const DCMotorPositive = 7; int const endPosition1 = 6; int const endPosition2 = 5; int const movingOFF = 4; int DCaccuracy = 5; int servoAccuracy = 8; int endPositionState1 = LOW; int endPositionState2 = LOW; int lastEndPositionState1 = LOW; // the previous reading from the input pin int lastEndPositionState2 = LOW; // the previous reading from the input pin long lastDebounceTime1 = 0; // the last time the output pin was toggled long lastDebounceTime2 = 0; // the last time the output pin was toggled long debounceDelay = 30; // the debounce time; increase if the output flickers //Prädeklaration void servoTurning (); void endPositionReading (); void DCTurning (); void setup() { Serial.begin(9600); xServo.attach(9); xServo.write(positionServo); pinMode(A0, INPUT); pinMode(A1, INPUT); pinMode(A2, INPUT); pinMode(A3, INPUT); pinMode(A4, INPUT); pinMode(A5, INPUT); pinMode(2, INPUT); pinMode(3, INPUT); pinMode(movingOFF, INPUT_PULLUP); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(12, INPUT); pinMode(13, INPUT); pinMode(DCMotorPositive, OUTPUT); // Pin 7 pinMode(DCMotorNegative, OUTPUT); // Pin 8 pinMode(endPosition1, INPUT); // Pin 6 pinMode(endPosition2, INPUT); // Pin 5 void endPositionReading (); } void loop() { // when D4 is LOW (Switch) all movings stop and the voltages of the caps get measured while ( digitalRead(movingOFF) == LOW ) { delay(1000); float voltage = 0; voltage = analogRead(A0); voltage = map(voltage, 0, 1023, 0, 5000); voltage = voltage / 87 ; Serial.print ("Spannung: "); Serial.print (voltage); Serial.println (" V"); } int WertA1 = analogRead(A1); // Auslesen der / reading of LDRs A1-A4 int WertA2 = analogRead(A2); int WertA3 = analogRead(A3); int WertA4 = analogRead(A4); // int WertA5 = analogRead(A5); if ( abs(WertA2 - WertA3) < abs(WertA1 - WertA4) ) { servoTurning (); DCTurning (); } else if ( abs (WertA2 - WertA3) > abs (WertA1 - WertA4)) { DCTurning (); servoTurning (); } // if ( WertA5 != analogRead(A5)) { // Serial.println (analogRead(A5)); // } delay(25); } void DCTurning () { // Auslesen der LDRs A2, A4 / reading of A2 and A4 int WertA2 = analogRead(A2); int WertA4 = analogRead(A4); //wenn die Differenz von A2 und A4 größer als der spezifische Toleranzbereich ist und der Endpositionsschalter nicht betätigt wurde, dann bewegt sich der Motor in die jeweilige Richtung / comparing A2 and A4 if ( (WertA2 - WertA4) > DCaccuracy ) { endPositionReading (); if ( endPositionState2 == HIGH) { digitalWrite(DCMotorPositive, HIGH); delay (10); digitalWrite(DCMotorPositive, LOW); } } if ( (WertA2 - WertA4) < - DCaccuracy ) { endPositionReading (); if ( endPositionState1 == HIGH) { digitalWrite(DCMotorNegative, HIGH); delay (10); digitalWrite(DCMotorNegative, LOW); } } } void servoTurning () { int OldPositionServo; OldPositionServo = positionServo; int WertA1 = analogRead(A1); // Auslesen der LDRs / reading of A1, A3, A5 int WertA3 = analogRead(A3); int WertA5 = analogRead(A5); //Serial.print ("A1 "); //Serial.println (WertA1); //Serial.print ("A2 "); //Serial.println (WertA2); //Serial.print ("A3 "); //Serial.println (WertA3); //Serial.print ("A4 "); //Serial.println (WertA4); //Serial.println (); //Vergleicht die LDrs A1 und A3, je nach Wert wird die Gradzahl erhöht oder erniedrigt / comparing A1 and A3 if ( positionServo > 0 && ((WertA1 - WertA3) > servoAccuracy) && WertA5 < 100) { positionServo = positionServo - 1 ; DCaccuracy = 5; } //Erhöhen der Genauigkeit des DC-Motors, wenn Servo bei 0° / increasing dc-motor accuracy when reaching 0° if ( positionServo == 0 && ((WertA1 - WertA3) > servoAccuracy)) { DCaccuracy = 1; } if ( positionServo < 180 && ((WertA1 - WertA3 ) > servoAccuracy) && WertA5 > 1000) { positionServo = positionServo + 1 ; DCaccuracy = 5; } // //Erhöhen der Genauigkeit des DC-Motors, wenn Servo bei 180° / increasing accuracy of the dc-motor when reaching 180° if ( positionServo == 180 && ((WertA1 - WertA3 ) > servoAccuracy)) { DCaccuracy = 1; } if ( positionServo < 180 && ((WertA1 - WertA3) < - servoAccuracy) && WertA5 < 100) { positionServo = positionServo + 1 ; DCaccuracy = 5; } if ( positionServo > 0 && ((WertA1 - WertA3) < -servoAccuracy) && WertA5 > 1000) { positionServo = positionServo - 1 ; DCaccuracy = 5; } if ( OldPositionServo != positionServo ) { //Serial.print ("positionServo: "); //Serial.println (positionServo); xServo.write(positionServo); } } void endPositionReading () { // read the state of the switch into a local variable: int reading1 = digitalRead(endPosition1); int reading2 = digitalRead(endPosition2); //Entprellen Endpositionstaster 1 // If the switch changed, due to noise or pressing: if (reading1 != lastEndPositionState1) { // reset the debouncing timer lastDebounceTime1 = millis(); } if ((millis() - lastDebounceTime1) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading1 != endPositionState1) { endPositionState1 = reading1; } } //Entprellen Positionstaster 2 // If the switch changed, due to noise or pressing: if (reading2 != lastEndPositionState2) { // reset the debouncing timer lastDebounceTime2 = millis(); } if ((millis() - lastDebounceTime2) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading2 != endPositionState2) { endPositionState2 = reading2; } } // save the reading. Next time through the loop, // it'll be the lastButtonState: lastEndPositionState1 = reading1; lastEndPositionState2 = reading2; //Anpassen der Servo-Genauigkeit bei Anschlag der Endpositionstaster / increasing servo accuracy when reaching endposition switch if ( endPositionState1 == LOW || endPositionState2 == LOW ) { servoAccuracy = 1; } else { servoAccuracy = 8; } }
-
~ e-plan for the whole device ~
03/30/2017 at 17:01 • 4 comments -
~plan for the protoptyping-shield~
03/29/2017 at 16:17 • 0 commentsThis is the Fritzing-plan for my prototyping-shield I used. :)
-
~ better results with LDR-shields ~
03/27/2017 at 04:53 • 6 comments -
~a look in the inside~
03/26/2017 at 16:45 • 0 comments -
~little space, big caps~
03/26/2017 at 08:53 • 0 comments -
~ first test in the "wilderness" ~
03/24/2017 at 17:42 • 0 commentsToday it was quite sunny and i had some free time so i decided it's time for some test. The panel began to spot the sun and the supercaps, i added for temporary storage, started to charge up. Now it's time to find a good place, where I can fixate the capacitors.
Have a nice weekend !! :)
-
~ first "LDR"-drive ~
03/22/2017 at 14:56 • 0 commentsAll wired up and the x-axis is moving !! :)
-
~did a little bit oft wireing ~
03/21/2017 at 16:07 • 0 comments