I create a new topic that shows how to reconvert an old RC car in a smart car using an Arduino UNO and Bluetooth connection. Before make this project I will create some easy and interesting tutorials that will help you to familiarise with create apps for Android and develop programs for Arduino.
The first lesson is controlling a DC Motor with an application created for Android that will allow us to control his velocity.
Material Needed
- DC Motor or a fan.
- Protoboard.
- NPN Transistor.
- Arduino UNO.
- Modul Bluetooth HC-05 or HC-06.
To create the apps we are gooing to use Appinventor.
Circuit
The link below shows the results:
The link below shows the tutorial:
#include <SoftwareSerial.h>
SoftwareSerial BT(10,11); //10 RX, 11 TX.
String state = ""; //Save data that come from Bluetooth
String lastState= "";
int inChar = 0;
char pwmChar[3];
int i = 0;
int pwm = 0, lastPwm=0;
void setup()
{
BT.begin(9600);
analogWrite(3,0);
}
void loop()
{
while (BT.available()>0) { // While there are data come frome bluetooth...
inChar = BT.read(); // Read data
pwmChar[i]= (char)inChar; //Save data to array type char
state += pwmChar[i]; //Save chars in a String
i++;
delay(1);
}
if (lastState != state) // Control when to write the PWM
{
pwm = state.toInt(); // Convert the String to a int value
analogWrite(3,pwm); // Send the value to PWM Pin
// Reset variables value
i = 0;
state="";
inChar =0;
lastPwm = pwm;
}
}