For Blog #8 I am posting the code I created for the Seeing EyeDuino. This has been the longest, most involved part of my project.
First, here is a layout of how the Arduino pins are assigned:
Arduino pin configuration
0 - 13 digital 14 - 19 analog (A0 - A5)
0
1 Braille Pin1 *
2 Braille Pin2 *
3 Braille Pin3 *
4 Servo break left - myservo2 *
5 Servo break right - myservo3 *
6 trigPinB *
7 echoPinB *
8 Front Servo - myservo *
9 trigPinA *
10 echoPinA *
11 Braille Pin4 *
12 Braille Pin5 *
13 Braille Pin6 *
14
15 Down warning LED red
16 Right warning yellow *
17 Right warning red *
18 Left warning yellow *
19 Left warning red *
Integers
**Record distance from ultrasonic sensors
**Front
distanceL
distanceF
distanceR
**Down
distanceD
**Time taken for ping to return
durationA
durationB
**Servo home position front, break right and break left
pos **Front
pos2 **Right
pos3 **Left
**Constant time delay
timeA
timeB
timeC
Here is the code:
#include <Servo.h> Servo myservo; //Front Servo myservo2; //Left Servo myservo3; //Right //Assign actuator delay times int timeA = 200; int timeB = 300; int timeC = 500; //Ultrasonic Sensor A (Front) const int trigPinA = 9; const int echoPinA = 10; long durationA; int distanceL; int distanceF; int distanceR; int pos = 0; //myservo int pos2 = 0; //myservo3 right int pos3 = 0; //myservo2 left //Ultrasonic Sensor B (Back) const int trigPinB = 6; const int echoPinB = 7; long durationB; int distanceD; void setup() { //Ultrasonic Sensor Forward pinMode(trigPinA, OUTPUT); pinMode(echoPinA, INPUT); Serial.begin(9600); //Ultrasonic Sensor Down pinMode(trigPinB, OUTPUT); pinMode(echoPinB, INPUT); Serial.begin(9600); myservo.attach(8); //Front servo myservo2.attach(4); //Break left myservo3.attach (5); //Break right //Braille pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); //Set Braille actuators to off digitalWrite(1, LOW); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13, LOW); //Warning lights and sound pinMode(15, OUTPUT); //Down warning red pinMode(16, OUTPUT); //Right warning yellow pinMode(17, OUTPUT); //Right warning red pinMode(18, OUTPUT); //Left warning yellow pinMode(19, OUTPUT); //Left warning red } void loop() { //Send servo to start position and turn to face forward for (pos = 30; pos <= 90; pos += 1) { // in steps of 1 degree myservo.write(pos); delay(15); } //Turn to far right for (pos = 90; pos <= 150; pos += 1) { // in steps of 1 degree myservo.write(pos); delay(15); } //Ping and record distance right digitalWrite(trigPinA, LOW); delayMicroseconds(2); digitalWrite(trigPinA, HIGH); delayMicroseconds(10); digitalWrite(trigPinA, LOW); durationA = pulseIn(echoPinA, HIGH); distanceR= durationA*0.034/2; //Distance in mm //Return to forward position for (pos = 150; pos >= 90; pos -= 1) { myservo.write(pos); delay(15); } //Ping and record distance forward digitalWrite(trigPinA, LOW); delayMicroseconds(2); digitalWrite(trigPinA, HIGH); delayMicroseconds(10); digitalWrite(trigPinA, LOW); durationA = pulseIn(echoPinA, HIGH); distanceF= durationA*0.034/2; //Distance in mm //Move to far left position for (pos = 90; pos >= 30; pos -= 1) { // in steps of 1 degree myservo.write(pos); delay(15); } //Ping and record distance left digitalWrite(trigPinA, LOW); delayMicroseconds(2); digitalWrite(trigPinA, HIGH); delayMicroseconds(10); digitalWrite(trigPinA, LOW); durationA = pulseIn(echoPinA, HIGH); distanceL= durationA*0.034/2; //Distance in mm //Ping and record distance Down digitalWrite(trigPinB, LOW); delayMicroseconds(2); digitalWrite(trigPinB, HIGH); delayMicroseconds(10); digitalWrite(trigPinB, LOW); durationB = pulseIn(echoPinB, HIGH); distanceD= durationB*0.034/2; //Distance in mm //With ping distance information decide how to proceed if (distanceL <= 600 && distanceL > 400) { digitalWrite (18, HIGH); //O { letterO(); } delay(timeB); digitalWrite (18, LOW); //B { letterB(); } delay(timeB); digitalWrite (18, HIGH); //J { letterJ(); } delay(timeB); digitalWrite (18, LOW); //E & 5 { letterE(); } delay(timeB); digitalWrite (18, HIGH); //C & 3 { letterC(); } delay(timeB); digitalWrite (18, LOW); //T { letterT(); } digitalWrite (18, HIGH); //Break left turn left for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } delay(timeC); for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //L { letterL(); } delay(timeB); digitalWrite (18, LOW); //E & 5 { letterE(); } delay(timeB); digitalWrite (18, HIGH); //F & 6 { letterF(); } delay(timeB); digitalWrite (18, LOW); //T { letterT(); } } if (distanceL <= 400) { digitalWrite(18, HIGH); digitalWrite(19, HIGH); //M { letterM(); } delay(timeB); digitalWrite(19, LOW); //O { letterO(); } delay(timeB); digitalWrite(19, HIGH); //V { letterV(); } delay(timeB); digitalWrite(19, LOW); //E & 5 { letterE(); } digitalWrite(19, HIGH); //Break left turn left for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } delay(timeC); for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //L { letterL(); } delay(timeB); digitalWrite (19, LOW); //E & 5 { letterE(); } delay(timeB); digitalWrite (19, HIGH); //F & 6 { letterF(); } delay(timeB); digitalWrite(18, LOW); digitalWrite (19, LOW); //T { letterT(); } } if (distanceR <= 600 && distanceR >400) { digitalWrite (16, HIGH); //O { letterO(); } delay(timeB); digitalWrite (16, LOW); //B & 2 { letterB(); } delay(timeB); digitalWrite (16, HIGH); //J & 0 (zero) { letterJ(); } delay(timeB); digitalWrite (16, LOW); //E & 5 { letterE(); } delay(timeB); digitalWrite (16, HIGH); //C & 3 { letterC(); } delay(timeB); digitalWrite (16, LOW); //T { letterT(); } //Break right turn right for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } delay(timeC); for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } digitalWrite (16, HIGH); //R { letterR(); } delay(timeB); digitalWrite (16, LOW); //I & 9 { letterI(); } delay(timeB); digitalWrite (16, HIGH); //G & 7 { letterG(); } delay(timeB); digitalWrite (16, LOW); //H & 8 { letterH(); } delay(timeB); digitalWrite (16, HIGH); //T { letterT(); } digitalWrite (16, LOW); } if (distanceR <= 400) { digitalWrite(16, HIGH); digitalWrite(17, HIGH); //M { letterM(); } delay(timeB); digitalWrite(17, LOW); //O { letterO(); } delay(timeB); digitalWrite(17, HIGH); //V { letterV(); } delay(timeB); digitalWrite(17, LOW); //E & 5 { letterE(); } //Break right turn right for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } delay(timeC); for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } digitalWrite(17, HIGH); //R { letterR(); } delay(timeB); digitalWrite (17, LOW); //I & 9 { letterI(); } delay(timeB); digitalWrite (17, HIGH); //G & 7 { letterG(); } delay(timeB); digitalWrite (17, LOW); //H & 8 { letterH(); } delay(timeB); digitalWrite (17, HIGH); //T { letterT(); } digitalWrite (16, LOW); digitalWrite (17, LOW); } if (distanceF <= 800 && distanceF > 550) { digitalWrite(16, HIGH); digitalWrite(18, HIGH); //S { letterS(); } delay(timeB); //L { letterL(); } delay(timeB); //O { letterO(); } delay(timeB); //W { letterW(); } digitalWrite(16, LOW); digitalWrite(18, LOW); } if (distanceF <= 550 && distanceF > 300) { digitalWrite(17, HIGH); digitalWrite(19, HIGH); //S { letterS(); } delay(timeB); digitalWrite(17, LOW); digitalWrite(19, LOW); //L { letterL(); } delay(timeB); digitalWrite(17, HIGH); digitalWrite(19, HIGH); //O { letterO(); } delay(timeB); digitalWrite(17, LOW); digitalWrite(19, LOW); //W { letterV(); } //Break left to stop for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //Break right to stop for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } delay(timeC); for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } } if (distanceF < 300) { digitalWrite(16, HIGH); digitalWrite(17, HIGH); digitalWrite(18, HIGH); digitalWrite(19, HIGH); //S { letterS(); } delay(timeB); digitalWrite(16, LOW); digitalWrite(17, LOW); digitalWrite(18, LOW); digitalWrite(19, LOW); //T { letterT(); } delay(timeB); digitalWrite(16, HIGH); digitalWrite(17, HIGH); digitalWrite(18, HIGH); digitalWrite(19, HIGH); //O { letterO(); } delay(timeB); digitalWrite(16, LOW); digitalWrite(17, LOW); digitalWrite(18, LOW); digitalWrite(19, LOW); //P { letterP(); } //Break left to stop for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //Break right to stop for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } delay(1000); for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } } if (distanceD <= 300 && distanceD >= 150) { digitalWrite (15, HIGH); //Break left to stop for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //Break right to stop for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } //S { letterS(); } delay(timeB); //T { letterT(); } delay(timeB); //O { letterO(); } delay(timeB); //P { letterP(); } delay(timeC); //S { letterS(); } delay(timeB); //T { letterT(); } delay(timeB); //E { letterE(); } delay(timeB); //P { letterP(); } delay(timeB); //D { letterD(); } delay(timeB); //O { letterO(); } delay(timeB); //W { letterW(); } delay(timeB); //N { letterN(); } for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } digitalWrite (15, LOW); } if (distanceD >= 300) { digitalWrite (15, HIGH); //Break left to stop for (pos3 = 30; pos3 <= 90; pos3 += 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } //Break right to stop for (pos2 = 30; pos2 <= 90; pos2 += 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } //S { letterS(); } delay(timeB); //T { letterT(); } delay(timeB); //O { letterO(); } delay(timeB); //P { letterP(); } delay(timeC); //D { letterD(); } delay(timeB); //R { letterR(); } delay(timeB); //O { letterO(); } delay(timeB); //P { letterP(); } delay(timeB); //O { letterO(); } delay(timeB); //F { letterF(); } delay(timeB); //F { letterF(); } for (pos3 = 90; pos3 >= 30; pos3 -= 1) { // in steps of 1 degree myservo2.write(pos); delay(15); } for (pos2 = 90; pos2 >= 30; pos2 -= 1) { // in steps of 1 degree myservo3.write(pos); delay(15); } digitalWrite (15, LOW); } } void letterA() { digitalWrite (1, HIGH); delay(timeA); //delay between on and off digitalWrite(1, LOW); } void letterB() { digitalWrite (1, HIGH); digitalWrite (3, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (3, LOW); } void letterC() { digitalWrite (1, HIGH); digitalWrite (2, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (2, LOW); } void letterD() { 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); } void letterE() { digitalWrite (1, HIGH); digitalWrite (11, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (11, LOW); } void letterF() { 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); } void letterG() { 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); } void letterH() { 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); } void letterI() { digitalWrite (2, HIGH); digitalWrite (3, HIGH); delay(timeA); //delay between on and off digitalWrite (2, LOW); digitalWrite (3, LOW); } void letterJ() { 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); } void letterK() { digitalWrite (1, HIGH); digitalWrite (12, HIGH); delay(timeA); //delay between on and off digitalWrite (1, LOW); digitalWrite (12, LOW); } void letterL() { 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); } void letterM() { 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); } void letterN() { 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); } void letterO() { 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); } void letterP() { 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); } void letterQ() { 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); } void letterR() { 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); } void letterS() { 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); } void letterT() { 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); } void letterU() { 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); } void letterV() { 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); } void letterW() { 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); } void letterX() { 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); } void letterY() { 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); } void letterZ() { 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); } void period() { 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); } void numbersign() { 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); }
I have 90% of the Seeing EyeDuino complete. I have made some changes to the EyeDuino, but that will be fore the next blog.
Blog #9 - The completed Seeing Eyeduino
Blog #10 - Testing
Thank you
Dale Winhold
Top Comments