For my 5th blog posting I will show the code I am using to run the robot and spelling in Braille. This part has been a bit of work but is coming along great. I have run into issues with the motors I have for driving the robot but that will be discussed in my next blog.
Below is the code (so far) for driving the robot. The Braille code hasn't been added in as of yet but the alphabet has been coded.
#include <Servo.h> Servo myservo; //Drive Motors const int MotorR1 = 6; //forward right motor const int MotorR2 = 7; // backward right motor const int MotorL1 = 4; // forward left motor const int MotorL2 = 5; // backward left motor //Ultrasonic Sensor const int trigPin = 9; const int echoPin = 10; long duration; int distanceL; int distanceF; int distanceR; int pos = 0; void setup() { //Ultrasonic Sensor pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); //Drive Motors pinMode(MotorR1, OUTPUT); pinMode(MotorR2, OUTPUT); pinMode(MotorL1, OUTPUT); pinMode(MotorL2, OUTPUT); digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); myservo.attach(8); //Braille pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); int timeA = 200; int timeB = 300; int timeC = 500; } void loop() { for (pos = 30; pos <= 90; pos += 1) { //Send servo to start position and turn to face forward // in steps of 1 degree myservo.write(pos); delay(15); } //Ping and record distance digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distanceF= duration*0.034/2; for (pos = 90; pos <= 150; pos += 1) { //Turn to far right // in steps of 1 degree myservo.write(pos); delay(15); } //Ping and record distance digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distanceR= duration*0.034/2; for (pos = 150; pos >= 90; pos -= 1) { //Return to forward position myservo.write(pos); delay(15); } //Ping and record distance digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distanceF= duration*0.034/2; for (pos = 90; pos >= 30; pos -= 1) { //Move to far left position // in steps of 1 degree myservo.write(pos); delay(15); } //Ping and record distance digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distanceL= duration*0.034/2; //With ping distance information decide how to proceed if (distanceL <= 600 && distanceL > 400) { //Add braille code here with warning //turn right digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, HIGH); digitalWrite(MotorL1, HIGH); digitalWrite(MotorL2, LOW); delay(500); digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); } if (distanceL <= 400) { //Add braille code here with warning //turn right digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, HIGH); digitalWrite(MotorL1, HIGH); digitalWrite(MotorL2, LOW); delay(750); digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); } if (distanceR <= 600 && distanceR >400) { //Add braille code here with warning //turn left digitalWrite(MotorR1, HIGH); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, HIGH); delay(500); digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); } if (distanceR <= 400) { //Add braille code here with warning //turn left digitalWrite(MotorR1, HIGH); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, HIGH); delay(750); digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); } if (distanceF >= 800) { //go forward digitalWrite(MotorR1, HIGH); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, HIGH); digitalWrite(MotorL2, LOW); delay(2000); } if (distanceF < 800 && distanceF > 600) { //Add braille code here with warning //go forward digitalWrite(MotorR1, HIGH); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, HIGH); digitalWrite(MotorL2, LOW); delay(1000); } if (distanceF < 599 && distanceF > 300) { //Add braille code here with warning //go forward digitalWrite(MotorR1, HIGH); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, HIGH); digitalWrite(MotorL2, LOW); delay(500); } if (distanceF < 300) { //Add braille code here with warning //Stop digitalWrite(MotorR1, LOW); digitalWrite(MotorR2, LOW); digitalWrite(MotorL1, LOW); digitalWrite(MotorL2, LOW); delay(1000); } }
Below is the code I will be using for the Braille. I still have to decide what the warnings will say before it is added into the above code.
pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); int timeA = 200; //delay between on and off int timeB = 300; //delay between Letters int timeC = 500; //delay between Words //A & 1 { digitalWrite (1, HIGH); delay(timeA); //delay between on and off digitalWrite(1, LOW); } //B & 2 { digitalWrite (1, HIGH); digitalWrite (3, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); } //C & 3 { digitalWrite (1, HIGH); digitalWrite (2, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); } //D & 4 { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (11, LOW); } //E & 5 { digitalWrite (1, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (11, LOW); } //F & 6 { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (3, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (3, LOW); } //G & 7 { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); } //H & 8 { digitalWrite (1, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); } //I & 9 { digitalWrite (2, HIGH); digitalWrite (3, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); } //J & 0 (zero) { digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); } //K { digitalWrite (1, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (12, LOW); } //L { digitalWrite (1, HIGH); digitalWrite (3, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); digitalWrite (12, LOW); } //M { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (12, LOW); } //N { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); } //O { digitalWrite (1, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); } //P { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (12, LOW); } //Q { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); } //R { digitalWrite (1, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); } //S { digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (12, LOW); } //T { digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); } //U { digitalWrite (1, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } //V { digitalWrite (1, HIGH); digitalWrite (3, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } //W { digitalWrite (2, HIGH); digitalWrite (3, HIGH); digitalWrite (11, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); digitalWrite (11, LOW); digitalWrite (13, LOW); } //X { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } //Y { digitalWrite (1, HIGH); digitalWrite (2, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } //Z { digitalWrite (1, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } //. { digitalWrite (3, HIGH); digitalWrite (11, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (3, LOW); digitalWrite (11, LOW); digitalWrite (13, LOW); } //# { digitalWrite (2, HIGH); digitalWrite (11, HIGH); digitalWrite (12, HIGH); digitalWrite (13, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (11, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); }
Any questions, comments or ideas is always welcome
Dale Winhold
Top Comments