Hi Tom.
With the L298N Motor Driver Controller Board, you can control the speed with the PWM setup.
I'm afraid it would be very easier using a servo motor.
Because I'm using it with a LEGO setup, It is easier to integrate.
I am using the Lego Technic, Gear 24 Tooth Clutch, to protect the beam from over torquing.
I will add a pic with the boom gate and gear setup when I get home.
Regarding the four connectors, There are only two wires going to the motor. Did some reading and opened the plastic casing myself to confirm.
Got this video on YouTube. But I'm afraid coding part is my problem. I have done the odd Arduino code with turning on a light. Creating a traffic light, but I'm afraid this I have not grasped.
My experience is newby. I'm afraid I'm very new to this. I read up on some of the Arduino projects and then try it.
This is my code for my current railroad crossing with a button to turn on/off some led lights I have in some of the buildings:
Below is the red lights flashing, buzzer sounding, and the signal changing from green to red for a specific train track. I also have four Infrared Obstacle Avoidance Sensors. I have a dual train track line.
int buzzer = 22;
int red1 = 23;
int red2 = 24;
const int crosssensWPin = 25;
const int crosssensOPin = 26;
const int crosssensYPin = 27;
const int crosssensGPin = 28;
int gsig1 = 29;
int rsig1 = 30;
int gsig2 = 31;
int rsig2 = 32;
int sigboxled = 33;
int lightg1 = 34;
int lightg2 = 35;
int but1 = 36;
int crosssensW = HIGH;
int crosssensO = HIGH;
int crosssensY = HIGH;
int crosssensG = HIGH;
byte lastButState;
byte ledgrp1 = LOW;
void setup() {
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(crosssensWPin, INPUT);
pinMode(crosssensOPin, INPUT);
pinMode(crosssensYPin, INPUT);
pinMode(crosssensGPin, INPUT);
pinMode(gsig1, OUTPUT);
pinMode(rsig1, OUTPUT);
pinMode(gsig2, OUTPUT);
pinMode(rsig2, OUTPUT);
pinMode(sigboxled, OUTPUT);
pinMode(lightg1, OUTPUT);
pinMode(lightg2, OUTPUT);
lastButState = digitalRead(but1);
Serial.begin(9600);
}
void loop() {
Train_Crossing();
Train_Signal1();
Train_Signal2();
BUTTON1();
}
void Train_Crossing() {
crosssensW = digitalRead(crosssensWPin);
crosssensO = digitalRead(crosssensOPin);
crosssensY = digitalRead(crosssensYPin);
crosssensG = digitalRead(crosssensGPin);
if (crosssensW == LOW)
{
Serial.println("Train1!!, Train1!!");
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
delay(200);
tone(buzzer,4000);
delay(30);
noTone(buzzer);
delay(30);
digitalWrite(red1, LOW);
digitalWrite(red2, HIGH);
delay(200);
tone(buzzer,4000);
delay(25);
noTone(buzzer);
delay(25);
}
else
{
//Serial.println("clear");
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
noTone(buzzer);
}
if (crosssensO == HIGH)
{
//Serial.println("clear");
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
noTone(buzzer);
}
else
{
Serial.println("Train2!!, Train2!!");
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
delay(200);
tone(buzzer,4000);
delay(30);
noTone(buzzer);
delay(30);
digitalWrite(red1, LOW);
digitalWrite(red2, HIGH);
delay(200);
tone(buzzer,4000);
delay(25);
noTone(buzzer);
delay(25);
}
if (crosssensY == HIGH)
{
//Serial.println("clear");
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
noTone(buzzer);
}
else
{
Serial.println("Train3!!, Train3!!");
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
delay(200);
tone(buzzer,4000);
delay(30);
noTone(buzzer);
delay(30);
digitalWrite(red1, LOW);
digitalWrite(red2, HIGH);
delay(200);
tone(buzzer,4000);
delay(25);
noTone(buzzer);
delay(25);
}
if (crosssensG == HIGH)
{
//Serial.println("clear");
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
noTone(buzzer);
}
else
{
Serial.println("Train4!!, Train4!!");
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
delay(200);
tone(buzzer,4000);
delay(30);
noTone(buzzer);
delay(30);
digitalWrite(red1, LOW);
digitalWrite(red2, HIGH);
delay(200);
tone(buzzer,4000);
delay(25);
noTone(buzzer);
delay(25);
}
}
void Train_Signal1() {
crosssensW = digitalRead(crosssensWPin);
static unsigned long lastRecordedTime = 0;
if (crosssensW == LOW)
{
digitalWrite(gsig1, LOW);
digitalWrite(rsig1, HIGH);
lastRecordedTime = millis();
}
else
if (millis() - lastRecordedTime > 6000)
{
digitalWrite(gsig1, HIGH);
digitalWrite(rsig1, LOW);
}
}
void Train_Signal2() {
crosssensY = digitalRead(crosssensYPin);
static unsigned long lastRecordedTime = 0;
if (crosssensY == LOW)
{
digitalWrite(gsig2, LOW);
digitalWrite(rsig2, HIGH);
lastRecordedTime = millis();
}
else
if (millis() - lastRecordedTime > 6000)
{
digitalWrite(gsig2, HIGH);
digitalWrite(rsig2, LOW);
}
}
void BUTTON1() {
byte butState1 = digitalRead(but1);
if (butState1 != lastButState) {
lastButState = butState1;
if (butState1 == LOW) {
if (ledgrp1 == HIGH) {
ledgrp1 = LOW;
}
else {
ledgrp1 = HIGH;
}
digitalWrite(sigboxled, ledgrp1);
digitalWrite(lightg1, ledgrp1);
digitalWrite(lightg2, ledgrp1);
}
}
}
PICS:
I hope that I have not confused you to much. I'm very new to this.
Thanks
Pieter