I'm currently working on a cool RC Miata project using an Arduino Uno with an L293D shield. I've already got it running smoothly with four motors and control it using an app on my phone with an HC-05 module. Now, I'm looking to take things up a notch by adding some extra flair - pop-up headlights, underglow, and more lights.
I'm a bit new to Arduino, so I could use some guidance on the hardware I'll need and how to connect it to my L293D board. Specifically, I'm wondering:
What additional components do I need for the lights?
How do I wire and connect these lights to the L293D board and Arduino?
What kind of code should I write to control the lights and coordinate them with the movement of my RC Miata?
If anyone has experience with similar projects or can provide some advice or resources, I'd greatly appreciate it. I'm excited to add some eye-catching features to my RC Miata, and your help would be invaluable.
Simple LEDs plus resistors come to mind; directly connected or in a matrix to save some pins. Addressable LEDs (aka neopixels) are also an option; they will only occupy one pin but if you have too many it can affect the working of the current setup and you might have to modify your code (we can't see it so can't be sure if it will).
We don't know which shield. We don't know which pins are used for the motors.
#include <AFMotor.h>
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command;
void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop(){
if(Serial.available() > 0){
command = Serial.read();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}
void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255);//Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255);//Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void back()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the button
motor2.setSpeed(0); //Define minimum velocity
motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum velocity
motor3.run(RELEASE); //stop the motor when release the button
motor4.setSpeed(0); //Define minimum velocity
motor4.run(RELEASE); //stop the motor when release the button
}
How do I wire and connect these lights to the L293D board and Arduino?
This will be a problem with this shield. I don't now if you have a solder iron that you can use?
Otherwise you could solder the wires to the top of the shield.
I do have a sol[quote="stefankersten, post:5, topic:1174870, full:true"]
How do I wire and connect these lights to the L293D board and Arduino?
This will be a problem with this shield. I don't now if you have a solder iron that you can use?
Otherwise you could solder the wires to the top of the shield.
[/quote]
I do have a soldering iron what pin should I solder my lights and how do I control it
You give the pinnumber your led is connected to a name.
In de setup make sure Arduino nows it a output.
And in the loop you can write your LED high and low.
For your code you can do that in de function (void forward, void back).
I don't now how well you know the hardware side of electronics but you need to wire it like the photo above.
Make sure the longer side of the LED is connected to the gpio of the Arduino and the other side is connected to the gnd.
The risistor you need will be 220 ohms and it doen't matter on which side of the led you make it as long as its there.