In order to control the circuit presented on Day 23 with the Raspberry Pi, I used the L293D motor driver.
The relay requires 40 mA and the GPIO can provide up to 16 mA. Using the L293D motor is a little overkill since it can handle up to 600 mA. I believe that the ideal solution would be using a transistor as shown in this article but I don’t have one now.
It is extremely important to use the protection diode in the proper position. I have been told that the 1N4148 is more suitable for this because it has a better response time. By now, I only have a 1N4001. I have read in some blogs people saying they use the 1N4001 without problems, so I gave it a chance.
I used the GPIO #17 pin to activate the relay through the L293D. I connected +5V from a external power source to the line in the top of the image and its ground to the line in the bottom of the image.
As usual, I used my PiEater library to control the GPIO from my desktop computer. Since this is just a quick test, I added a new check box in my previous Truck Driver program:
The MC-1, abbreviation for Monster Car 1, is based on parts of a car that once was remote controlled. My wife chose this name because she thinks it is ugly as a monster.
The front wheels are turned by a solenoid. Since the current provided by the L293D is limited, I created this workaround. When the servo moves, it causes the paper clips to close an electric circuit and activate the solenoid.
I have created a standard for the wiring–The connectors that provide power are females and the one that receive power are males. Hence, I don’t have energized male connectors touching each other causing short-circuits. I used glued tape to group the wires together and label them. In this way, it will be easier reconnect the chassis to the board.
I used Velcro to attach the breadboard and the Raspberry Pi to the car. This is how the final assembly looks like.
I bought this car in a second-hand-stuff shop. Originally it was remote-controlled but when I bought it, it no longer had the remote control. I don’t know the motor specification. This car has five AA batteries (7.5V), so I think it is safe to use my 5V power source. I put it on a box to avoid it to run away.
This time I used the L293D attached to GPIO 18 and 23 in a way I can make the motor run forwards or backwards.
I used the Servo Blaster library as presented on Day 14. In order to run the motor forwards, I kept one signal at zero and changed the other one.
echo "2=0" > /dev/servoblaster
echo "5=500" > /dev/servoblaster
To run backwards, I inverted the signals:
echo "5=0" > /dev/servoblaster
echo "2=500" > /dev/servoblaster
It worked with values from 300 to 2000.
When the motor runs forwards, the white LED is on. The LED is connected after the L293D.
When the motor runs backwards, the green LED is on. The LED is connected before the L293D.
This time I replaced the red LED in the circuit I used on Day 11 for a ultra bright white LED.
The white LED requires more power than the Pi can provide, so I added the external power source used on Day 9 and a motor control chip, the L293D. I did the wiring based on this Adafruit tutorial but my Cobbler is connected in the inverted position.
This is the final circuit:
- I used the following wire color guidelines: Black for ground, Red for Vcc, Yellow for data, and Blue for control.
- The white LED can take up to 80mA and is connected to 100/3 = 33 Ohms resistor.
- The green LED is connected to a 330 Ohms resistor.
- I used an external 5V power source connected to the bottom-right corner.
The following picture shows the connections from another direction:
This is the final result: