How To Make Motor Direction Controller | Using Bc547
Working on an autonomous robot, I needed to be able to simultaneously control two DC motors' movements.
I already designed a system in july 2016 that runs rather well but I needed to improve speed measurement precision.
To do so I restarted from scratch and it was a good opportunity to publish this instructable.
This system relies on:
some mechanical components
a simple electronic circuit
some Arduino software tools.
All that is detailed further in this instructable.
A wheel with some holes is set on the rotation axis
A LED provides an infrared light that goes through holes each time the LED is in front of a hole
An infrared receiver provides an electrical signal that depends on the light received
A microcontroler monitors the electrical signal, counts the number of holes detected, compute the instantaneous speed and adjust the motor input voltage to fit with the expectations
This instructable demonstrates how to implement the system for only one motor.
Actually robots require more than one motor. That's why I developed software that can deal with up to four motors simultaneously. And that's also the reason I chose a microcontroler more powerfull than a UNO and I chose an ATMega 2560
Let's Start With the Electronic
Power supply
Motor needs a dedicated power supply.
Power supply is delivered thru a motor controller (L298N in this case). For this model I chose a motor that needs a 12v power.
(if you need higher voltage take care to the motor driver specification for L298N you need to remove a jumper)
As I needed others 5v power supply for my robot, I do not use the Arduino 5v output to power the infrared LEDs.
As the robot runs on batteries I wanted to be able to power on/off the LEDs to save current. That's the job of the 2N222A transitor.
ATmega power supply is provided by the USB host connection
Holes detection
Relies on the fact that a LED IR receiver (photodiode) resistance reduces when it receives light.
Before starting motor the LEDs are powered on.
The emitter current goes through a resistor to protect it.
The value of the resistor needs to be adjusted depending on the LED characteritics and the distance between emitter and receiver.
The receiver current goes through a resistor that will be used to detect voltage variations due to LED resistance variations.
A BC547 transistor is used to amplify the voltage changes to deliver to the Arduino.
The software monitors the voltage to detect holes.
Above in blue the signal before amplification, in red after amplification.
The schematic is available above as a fritzing file.
After you have done as the schematic, check manually that you get a good signal.
Take care the photodiode must be connected in reverse polarity
If having some oscilloscope it is useful to connect yellow and pink wire as above (orange wire later to be used as trigger)
Else you can use an arduino sketch and serial plotter to visualize the signals
Parts supply details
1 x ATmega2560 (you can find for less than $15)
1 x breadboard (you can find 3 for $10)
1 x LED IR emitter & 1 x LED IR receiver - (you can easily find both on the WEB ($10 for 50 of each))
1 x 2N222A transitor (less than $5 for 100)
1 x BC547 transitor (less than $5 for 100)
1 x L298N motor controller (you can get 5 for $15)
2 x 220 ohms resistors
1 x 1k ohms resistor
1 x 10k ohms resistor
1 x 12v DC motor It can easily be found inside an old equipment (toy, printer...) or bought on the WEB for a few dollars
1 x 5v power supply
1 x 12v power supply
some wires
The wire between GPIO 3 and 7 is mandatory to get encoders interruptions
Motor is driven thru a L298N controller with 3 GPIOs (ENA (must be PWM), IN1 and IN2) to control rotation sens and torque
To develop and test the system I needed a mechanical prototype.
I did it with a 3d printer. The parts have been designed for an axis of 5mn diameter and a motor of 25mn diameter.
Some Details About the Example
There are 2 flags you can define before compiling
debugOn will provide details during the run
plotterOn will provide a graph showing how the actual speed fits with the target
10 commands to start and stop the motor, increase and decrease the speed and turns number requirement, change the sens rotation (clock, counterclock) and for braking or not at the end of the rotation
By default the system will do 50 turns at 3.00 RPS and the encoder has 12 holes
Use serial input to enter commands
Enter 5 times s+ to increase the speed to 3.5 RPS (350/100)
Enter start and wait
At the end you will see on the serial link the total number of holes detected in this case 610
600 = 12*50 that are required
10 due to inertia overflow
In this case the effective speed was 3.45
Let's have a look at the oscillospe picture:
trigger signal is set down exactly when the motor is powered.
Nevertheless as the wheel control remains active for 1 second, it detects the 10 more holes. The oscilloscope confirms the actual overflow (look at the mark on the wheel at the video).
How To Make Motor Direction Controller | Using Bc547
Working on an autonomous robot, I needed to be able to simultaneously control two DC motors' movements.
I already designed a system in july 2016 that runs rather well but I needed to improve speed measurement precision.
To do so I restarted from scratch and it was a good opportunity to publish this instructable.
This system relies on:
some mechanical components
a simple electronic circuit
some Arduino software tools.
All that is detailed further in this instructable.
A wheel with some holes is set on the rotation axis
A LED provides an infrared light that goes through holes each time the LED is in front of a hole
An infrared receiver provides an electrical signal that depends on the light received
A microcontroler monitors the electrical signal, counts the number of holes detected, compute the instantaneous speed and adjust the motor input voltage to fit with the expectations
This instructable demonstrates how to implement the system for only one motor.
Actually robots require more than one motor. That's why I developed software that can deal with up to four motors simultaneously. And that's also the reason I chose a microcontroler more powerfull than a UNO and I chose an ATMega 2560
Let's Start With the Electronic
Power supply
Motor needs a dedicated power supply.
Power supply is delivered thru a motor controller (L298N in this case). For this model I chose a motor that needs a 12v power.
(if you need higher voltage take care to the motor driver specification for L298N you need to remove a jumper)
As I needed others 5v power supply for my robot, I do not use the Arduino 5v output to power the infrared LEDs.
As the robot runs on batteries I wanted to be able to power on/off the LEDs to save current. That's the job of the 2N222A transitor.
ATmega power supply is provided by the USB host connection
Holes detection
Relies on the fact that a LED IR receiver (photodiode) resistance reduces when it receives light.
Before starting motor the LEDs are powered on.
The emitter current goes through a resistor to protect it.
The value of the resistor needs to be adjusted depending on the LED characteritics and the distance between emitter and receiver.
The receiver current goes through a resistor that will be used to detect voltage variations due to LED resistance variations.
A BC547 transistor is used to amplify the voltage changes to deliver to the Arduino.
The software monitors the voltage to detect holes.
Above in blue the signal before amplification, in red after amplification.
The schematic is available above as a fritzing file.
After you have done as the schematic, check manually that you get a good signal.
Take care the photodiode must be connected in reverse polarity
If having some oscilloscope it is useful to connect yellow and pink wire as above (orange wire later to be used as trigger)
Else you can use an arduino sketch and serial plotter to visualize the signals
Parts supply details
1 x ATmega2560 (you can find for less than $15)
1 x breadboard (you can find 3 for $10)
1 x LED IR emitter & 1 x LED IR receiver - (you can easily find both on the WEB ($10 for 50 of each))
1 x 2N222A transitor (less than $5 for 100)
1 x BC547 transitor (less than $5 for 100)
1 x L298N motor controller (you can get 5 for $15)
2 x 220 ohms resistors
1 x 1k ohms resistor
1 x 10k ohms resistor
1 x 12v DC motor It can easily be found inside an old equipment (toy, printer...) or bought on the WEB for a few dollars
1 x 5v power supply
1 x 12v power supply
some wires
The wire between GPIO 3 and 7 is mandatory to get encoders interruptions
Motor is driven thru a L298N controller with 3 GPIOs (ENA (must be PWM), IN1 and IN2) to control rotation sens and torque
To develop and test the system I needed a mechanical prototype.
I did it with a 3d printer. The parts have been designed for an axis of 5mn diameter and a motor of 25mn diameter.
Some Details About the Example
There are 2 flags you can define before compiling
debugOn will provide details during the run
plotterOn will provide a graph showing how the actual speed fits with the target
10 commands to start and stop the motor, increase and decrease the speed and turns number requirement, change the sens rotation (clock, counterclock) and for braking or not at the end of the rotation
By default the system will do 50 turns at 3.00 RPS and the encoder has 12 holes
Use serial input to enter commands
Enter 5 times s+ to increase the speed to 3.5 RPS (350/100)
Enter start and wait
At the end you will see on the serial link the total number of holes detected in this case 610
600 = 12*50 that are required
10 due to inertia overflow
In this case the effective speed was 3.45
Let's have a look at the oscillospe picture:
trigger signal is set down exactly when the motor is powered.
Nevertheless as the wheel control remains active for 1 second, it detects the 10 more holes. The oscilloscope confirms the actual overflow (look at the mark on the wheel at the video).
No comments:
Post a Comment