Assignments
- Add an output device to a microcontroller board
- Program it to do something
Subject¶
For my final project I need to use a fan to regulate the soil moisture if it’s too wet (more than 90% ?). For our BadgeBot project we need to use 2 DC motor to rotate the eyes of our robot. So I want to make a board with one or two motor driver.
Fabrication process¶
Find DC motor:¶
In our FabLab we sometimes recover machines that no longer work including printers. We keep the functional components and make them available to the makers. That’s how I found 2 identical DC motors in our miracle box! I tested them with an electric load to know their consumption and choose the motor driver accordingly. Each does not consume more than 200mA (with 9V power supply).
I also try to use this mini DC gearbor motor. It consumes less than 200mA (with 9V power supply).
Check the Neil’s example:¶
hello.H-bridge.44 Neil uses only one external supply for the motor driver and for the ATTiny44. So he uses an 5V regulator (named “IC2 5V” on the board file).
Find the good voltage regulator:¶
I looked in the Fab component Eagle library to find the name of this component. From the footprint of the component I deduced that is SOT23 type.
Regulator SOT23 | Regulator SOT223 |
---|---|
Choose the components:¶
- Microcontroller: ATTiny44
- Motor driver: A4953ELJTR-T, the maximum output current is 2A so for the 2 DC motors (Imax= 400mA) it’s OK.
Maximum ratings | Pinout | Electrical diagram |
---|---|---|
- 5V regulator: NCP1117ST50T3GOSCT-ND, this one has a fixed output voltage (exists also with adjustable output voltage). This one is an SOT223 type and not SOT23.
Output voltage | Input voltage | Electrical diagram |
---|---|---|
- Capacitors: 10uF, 100uF, 0,1uF
- Resistors: 10kOhms
- AVRISP header 2x3
- Pin header 2x2 (x2)
Design on Eagle¶
Ground planes¶
For this board I used a function that I have never been try with Eagle, the ground plane. This avoids messing with the ground routing. After doing the schematic and the routing (leaving aside the ground):
Draw a polygon around the BOARD | Define it as GND signal |
---|---|
Define the option in the supply tab in the DRC menu | Use ratsnest tool |
---|---|
Final result¶
Eagle schematic | Eagle board | Bantam visualization |
---|---|---|
Soldering¶
The first board soldered | The final board soldered |
---|---|
Programming¶
A4953 operation¶
The A4953 H-bridge must be connected to 2 PWM pins of the microcontroller. The PWM is useful for varying the rotation speed of the motors. For my board I use PA7 and PB2. The The A4953 feeds the motors in 9V (VBB) and also receives the reference voltage of the microcontroller (VCC = 5V).
From the datasheet we can know how to set the pin’s state do drive the motor:
Thus it is possible to turn the motor in one direction or another, or to stop the rotation.
Problem met with my first board soldered¶
I tried to program my board a first time. It was a very simple program, it was supposed to run the engine and turn it off after 5 seconds. The program was uploaded well, but the engine was not running. After several checks I realized that I had not connected the LSS pin driver A4953 to the ground as indicated in the datasheet. So I soldered a jumper and my program worked normally. After that I fix this error on my Eagle schematic and soldered a new board.
First program: reverse direction¶
The program rotates the motor in one direction then reverses the direction every 4 seconds. For that I use the function millis which allows to let the microcontroller to do other operations, unlike the delay function. I use the digitalWrite function and set the pins in1 and in2 in opposite state.
#define in1 2 // IN1 #define in2 3 // IN2 const unsigned long duration = 4000; ///duration time before to change direction unsigned long previousMillis = 0; /// byte statePinIn1 = LOW; byte statePinIn2 = HIGH; void setup() { Serial.begin(9600); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); } void loop() { // If duration or more milliseconds have elapsed if (millis() - previousMillis >= duration) { // record the current value of millis previousMillis = millis(); // reverse the pin's state statePinIn1 = !statePinIn1; statePinIn2 = !statePinIn2; digitalWrite(in1, statePinIn1); digitalWrite(in2, statePinIn2); } }
Current peak
A current peak occurs when the motor reverses. To avoid it I have to test with a low state of the both pins to cut the rotation of the engine before to reverse.
Second program: acceleration¶
The program gradually increases the RPM.