-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATOM_Car.ino
100 lines (96 loc) · 2.57 KB
/
ATOM_Car.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//Car controlled by voice commands through bluetooth module for arduino
#include<string.h>
//Initialize the pins in the Arduino for controlling motor driver
void setup()
{
//Pins 6 and 11 support PWM (Pulse Width Modulation)
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
}
//A function which will take the voice commands and controls the motor driver
void control_car(String message)
{
//If the pin connection is as above
//This will rotate both the front wheels in the car
if(message=="forward")
{
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
analogWrite(6,255);
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
analogWrite(11,255);
delay(5000); //Delay is given by default for 5 sec
}
//This will rotate both the back wheels in the car
else if(message=="backward")
{
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
analogWrite(6,255);
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
analogWrite(11,255);
delay(5000);
}
//This will rotate only the right wheel
else if(message=="left")
{
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
analogWrite(11,255);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
analogWrite(6,0);
delay(5000);
}
//This will rotate only the left wheel
else if(message=="right")
{
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
analogWrite(6,255);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
analogWrite(11,0);
delay(5000);
}
//This will stop the wheels
else if(message=="stop")
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
analogWrite(6,0);
digitalWrite(13,LOW);
digitalWrite(12,LOW);
analogWrite(11,0);
}
}
//Voice control statements
String voice;
void loop()
{
while (Serial.available()) //Check if bluetooth module is connected and if bytes(characters) can be read from it
{
delay(10);
char c = Serial.read(); //Read from the bluetooth module
if (c == '#') //Marks end of received message
break;
voice += c;
//Read character by character and append it to form a string
}
if (voice.length() > 0)
{
Serial.println(voice);
/* Remove the above statement if you don't want it.
This is to print the message in the command-line interface for testing purposes */
voice = string.toLowerCase(); //Convert the message to lower case for easy control in the function
control_car(voice);
voice = ""; //Make the existing string empty for new message
}
}