hi all,
i have an Arduino Nano working for a model railway barier, it resides
at the model railway place for default,
but for programming i have a board near the personal-computer (PC).
the Ard.Nano drives two servos if placed at model railway,
but at PC there are LED's instead.
if i place the Ard.Nano at PC, getting supply voltage from the PC USB-Port ,
it seems all works fine.
the finger feeled temperatur of the chip is not significant higher than
room temperature.
In real-working situation at model railway Ard.Nano is supplied with exactly 5V from an L200-regulator which gets ca 15V from separate DC-Supplier.
Now Ard.Nano gets higher temparature - i can not leave finger on it because it is really hot . So i switched off supply to beware from overheating.
the control current from pin 5 of Ard. to servo's control wire(mostly white) is at 0,2 mA; is this too much ?
should i use opto-coupling devices to protect Ard. ?
at least, Ard. does Not work well in the model railway situation..
it does unmotivied actions with the servos...
here's the code ( comments in my mother tounge german, sorry)
//- sk_test_schranke_4 08.112021
#include <Servo.h>
#define FALSEVAL 1
#define TRUEVAL 0
#define STAT_OPEN 1
#define STAT_CLOSED 0
#define RESET 1
#define LED_RED 2
#define LED_YELLOW 3
#define LED_GREEN 4
#define MAXPOS 135
#define STARTPOS 45
#define STEPP 5
#define LOOP_DELAY 30
#define SHOW_DELAY 1000
#define PASSING_TRAIN 5000 //- Zug passiert Schrankenblock
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
//- gemaess INPUT_PULLUP - Definition ist 0=Event am Geber= True,
//- also 'umgedrehte' Logik-Werte , das wird dann halt hier durchgezogen..
//- nach Info von AZ-Delivery sind die PWM-faehigen PINS vom Ardi.Nano :
//- 5,6,9 - deswegen wurden die Geber (Reflexlichtschranken)
//- gegenueber Sketch-Version2 auf 7,8 gelegt !
int geber1 = 7;
int geber2 = 8;
int s_status = STAT_OPEN;
int val_g1 = FALSEVAL;
int val_g2 = FALSEVAL;
int alarm = FALSEVAL;
int g1_event = FALSEVAL;
int g2_event = FALSEVAL;
int count_g1 = 0;
int count_g2 = 0;
void setup()
{
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(LED_RED, OUTPUT);
pinMode(LED_YELLOW, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
//- die Geber sind erstmal Taster, Nicht Schalter !
pinMode(geber1, INPUT_PULLUP); // sets the digital pin 13 as output
pinMode(geber2, INPUT_PULLUP); // sets the digital pin 7 as input
myservo1.attach(5);
myservo1.attach(6);
}
void loop()
{
show_vals();
digitalWrite(LED_GREEN, HIGH); //- Autos koennen passieren
g1_event = digitalRead(geber1);
if(g1_event == TRUEVAL)
count_g1++;
g2_event = digitalRead(geber2);
if(g2_event == TRUEVAL)
count_g2++;
show_vals();
if (
( (count_g1 > 0 && count_g2 == 0) ||
(count_g2 > 0 && count_g1 == 0) )
&&
s_status == STAT_OPEN
)
{
schranke_schliessen();
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, HIGH);
delay(LOOP_DELAY);
}
//if(s_status == STAT_CLOSED)
//delay(PASSING_TRAIN);
if (
( (count_g1 > 0 && (count_g1 == count_g2)) ||
(count_g2 > 0 && (count_g1 == count_g2))
)
&&
s_status == STAT_CLOSED
)
{
schranke_oeffnen();
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH);
count_g1 = 0;
count_g2 = 0;
} //- end g1+g2
} //- end-loop
void schranke_schliessen()
{
if (s_status == STAT_OPEN)
{
for (int pos = STARTPOS; pos <= MAXPOS; pos += STEPP)
{ // goes from STARTPOS degrees to MAXPOS degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos);
delay(LOOP_DELAY); // waits 15ms for the servo to reach the position
}
Serial.println(" schranke geschlossen ");
s_status = STAT_CLOSED;
}
}
void schranke_oeffnen()
{
if (s_status == STAT_CLOSED)
{
for (int pos = MAXPOS; pos >= STARTPOS; pos -= STEPP)
{ // goes from MAXPOS degrees to STARTPOS degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos);
delay(LOOP_DELAY); // waits 15ms for the servo to reach the position
}
Serial.println(" schranke offen ");
s_status = STAT_OPEN;
}
}
void show_vals()
{
//- der print-Befehl ist Nicht identisch mit dem von Standard-C oder Standard-Java !
//- 2. Parameter ist hier für das Ausgabeformat, nicht für nen numerischen Wert zur Ausgabe !
Serial.print(" g1_count : ");
Serial.print(count_g1);
Serial.print(" g2_count : ");
Serial.print(count_g2);
Serial.print(" Status : ");
Serial.print(s_status);
Serial.print(" alarm : ");
Serial.println(alarm);
delay(SHOW_DELAY);
}