LEGO DC motor with H-Bridge motor driver 90 degree turn

Hi.

I'm trying to use a H-Bridge motor driver to turn two LEGO Power Functions M-Motor.

I started to play with the Arduino boards, but still very new to it.

My aim is to automate my railroad crossing.
I have the lights and buzzer working. I'm just trying to add the boom gates.

The Lego Power Functions M-Motor, has a DC motor inside it. I would like to use the LEGO motor.

Could someone guide me on how to use the motor in regards to turning it 90 degrees?
I would like to simulate gates opening and closing when the sensor is triggered.

Thanks

Hi, @icedude
Welcome to the forum.

A DC motor like that would need a gearbox to slow it down to do a controlled 1/4 of a turn.

You would be better to use a servo to do that job.

Have you found any information on how to use the 8883 motor as it looks like it is not designed for speed control.
Do you now how to use the four connections that are in the connector?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :grinning: :+1: :coffee::australia:

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

Hello icedude

Welcome to the worldbest Arduino Forum ever.

Take a view here to get some additonal Lego ideas:

Hi paulpaulson.

Please forgive me, I'm trying to keep the motors and build close to Lego parts.

If it comes to last resort, I will have to give in, but till then, I would still like to try the Lego motors first.

Thanks for the advice. Will dig into the info received and try my best.

Thanks

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.