SlideShare a Scribd company logo
1 of 10
Hello Please I wanna fix the code problems as it does not run
through arduino propaply
Here is the CODE:
/****************************************************
***********/
/* */
/* Garage Controller Range v2.0 */
/* */
/****************************************************
***********/
#include
#define SF(x) String(F(x))
#define CF(x) String(F(x)).c_str()
#define RANGE_MIN 35
#define RANGE_MAX 39
#define RANGE_1 49
#define RANGE_2 64
#define RANGE_3 84
#define RANGE_4 200
int
iPinRed1 = 3;
int
iPinRed2 = 4;
int
iPinRed3 = 5;
int
iPinRed4 = 6;
int
iPinGreen1 = 7;
int
iPinRed5 = 8;
int
iPinRange = 9;
/****************************************************
***********/
/* Function: setup */
/****************************************************
***********/
void
setup()
{
Serial.begin(9600);
Serial.println(SF(
"setup()"
));
pinMode(iPinRed1, OUTPUT);
pinMode(iPinRed2, OUTPUT);
pinMode(iPinRed3, OUTPUT);
pinMode(iPinRed4, OUTPUT);
pinMode(iPinGreen1, OUTPUT);
pinMode(iPinRed5, OUTPUT);
pinMode(iPinRange, OUTPUT);
}
/****************************************************
***********/
/* Function: loop */
/****************************************************
***********/
void
loop()
{
long
lDuration = 0, lCM = 0;
// 2 Microsecond Clear + 5 Microsecond Pulse
pinMode(iPinRange, OUTPUT);
digitalWrite(iPinRange, LOW);
delayMicroseconds(2);
digitalWrite(iPinRange, HIGH);
delayMicroseconds(5);
digitalWrite(iPinRange, LOW);
// Get Return Pulse
pinMode(iPinRange, INPUT);
lDuration = pulseIn(iPinRange, HIGH);
lCM = ConvertMSToCM(lDuration);
Serial.println(
"Distance: "
+ String(lCM) +
" cm"
);
// Too Close
if
(lCM < RANGE_MIN)
{
digitalWrite(iPinRed1, LOW);
digitalWrite(iPinRed2, LOW);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, HIGH);
}
// Perfect
else
if
(lCM >= RANGE_MIN & lCM < RANGE_MAX)
{
digitalWrite(iPinRed1, LOW);
digitalWrite(iPinRed2, LOW);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, HIGH);
digitalWrite(iPinRed5, LOW);
}
// Range 1
else
if
(lCM >= RANGE_MAX & lCM < RANGE_1)
{
digitalWrite(iPinRed1, HIGH);
digitalWrite(iPinRed2, HIGH);
digitalWrite(iPinRed3, HIGH);
digitalWrite(iPinRed4, HIGH);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
// Range 2
else
if
(lCM >= RANGE_1 & lCM < RANGE_2)
{
digitalWrite(iPinRed1, HIGH);
digitalWrite(iPinRed2, HIGH);
digitalWrite(iPinRed3, HIGH);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
// Range 3
else
if
(lCM >= RANGE_2 & lCM < RANGE_3)
{
digitalWrite(iPinRed1, HIGH);
digitalWrite(iPinRed2, HIGH);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
// Range 4
else
if
(lCM >= RANGE_3 & lCM < RANGE_4)
{
digitalWrite(iPinRed1, HIGH);
digitalWrite(iPinRed2, LOW);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
// Range 5
else
if
(lCM >= RANGE_4)
{
digitalWrite(iPinRed1, LOW);
digitalWrite(iPinRed2, LOW);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
else
{
digitalWrite(iPinRed1, LOW);
digitalWrite(iPinRed2, LOW);
digitalWrite(iPinRed3, LOW);
digitalWrite(iPinRed4, LOW);
digitalWrite(iPinGreen1, LOW);
digitalWrite(iPinRed5, LOW);
}
delay(50);
}
/****************************************************
***********/
/* Function: ConvertMSToCM */
/****************************************************
***********/
long
ConvertMSToCM(
long
lMicroSeconds)
{
// The speed of sound is 340 m/s or 29 microseconds per
centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled. - Arduino Site
return
lMicroSeconds / 29 / 2;
}
Here is the link to the project:
http://blog.mikejmcguire.com/2014/04/20/using-an-arduino-as-
a-garage-gar-parking-sensor/

More Related Content

Similar to Hello Please I wanna fix the code problems as it does not run throug.docx

All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docxAll contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
galerussel59292
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
LynellBull52
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST Demystified
Andres Almiray
 
Embedded c programming22 for fdp
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdp
Pradeep Kumar TS
 

Similar to Hello Please I wanna fix the code problems as it does not run throug.docx (16)

Supermarket
SupermarketSupermarket
Supermarket
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docxAll contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
All contents are Copyright © 1992–2012 Cisco Systems, Inc. A.docx
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
Gsp 215 Exceptional Education / snaptutorial.com
Gsp 215  Exceptional Education / snaptutorial.comGsp 215  Exceptional Education / snaptutorial.com
Gsp 215 Exceptional Education / snaptutorial.com
 
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
Experiment 16 x2 parallel lcd
Experiment   16 x2 parallel lcdExperiment   16 x2 parallel lcd
Experiment 16 x2 parallel lcd
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
Rodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementationRodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementation
 
002207866
002207866002207866
002207866
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST Demystified
 
Embedded c programming22 for fdp
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdp
 

More from josephineboon366

Hello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docxHello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docx
josephineboon366
 
Hello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docxHello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docx
josephineboon366
 

More from josephineboon366 (20)

Hello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docxHello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docx
 
Hello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docxHello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docx
 
Hello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docxHello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docx
 
Hello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docxHello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docx
 
hello,Can you write a research paper Racisim defin Rcism an.docx
hello,Can you write a research paper  Racisim defin Rcism an.docxhello,Can you write a research paper  Racisim defin Rcism an.docx
hello,Can you write a research paper Racisim defin Rcism an.docx
 
Hello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docxHello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docx
 
Hello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docxHello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docx
 
Hello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docxHello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docx
 
Hello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docxHello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docx
 
Hello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docxHello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docx
 
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docxHello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
 
Hello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docxHello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docx
 
Hello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docxHello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docx
 
hello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docxhello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docx
 
Hello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docxHello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docx
 
Hello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docxHello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docx
 
Hello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docxHello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docx
 
Hello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docxHello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docx
 
Hello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docxHello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docx
 
Hello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docxHello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docx
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 

Recently uploaded (20)

Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 

Hello Please I wanna fix the code problems as it does not run throug.docx

  • 1. Hello Please I wanna fix the code problems as it does not run through arduino propaply Here is the CODE: /**************************************************** ***********/ /* */ /* Garage Controller Range v2.0 */ /* */ /**************************************************** ***********/ #include #define SF(x) String(F(x)) #define CF(x) String(F(x)).c_str() #define RANGE_MIN 35 #define RANGE_MAX 39 #define RANGE_1 49 #define RANGE_2 64 #define RANGE_3 84 #define RANGE_4 200 int iPinRed1 = 3; int iPinRed2 = 4; int iPinRed3 = 5; int
  • 2. iPinRed4 = 6; int iPinGreen1 = 7; int iPinRed5 = 8; int iPinRange = 9; /**************************************************** ***********/ /* Function: setup */ /**************************************************** ***********/ void setup() { Serial.begin(9600); Serial.println(SF( "setup()" )); pinMode(iPinRed1, OUTPUT); pinMode(iPinRed2, OUTPUT); pinMode(iPinRed3, OUTPUT); pinMode(iPinRed4, OUTPUT);
  • 3. pinMode(iPinGreen1, OUTPUT); pinMode(iPinRed5, OUTPUT); pinMode(iPinRange, OUTPUT); } /**************************************************** ***********/ /* Function: loop */ /**************************************************** ***********/ void loop() { long lDuration = 0, lCM = 0; // 2 Microsecond Clear + 5 Microsecond Pulse pinMode(iPinRange, OUTPUT); digitalWrite(iPinRange, LOW); delayMicroseconds(2); digitalWrite(iPinRange, HIGH); delayMicroseconds(5); digitalWrite(iPinRange, LOW);
  • 4. // Get Return Pulse pinMode(iPinRange, INPUT); lDuration = pulseIn(iPinRange, HIGH); lCM = ConvertMSToCM(lDuration); Serial.println( "Distance: " + String(lCM) + " cm" ); // Too Close if (lCM < RANGE_MIN) { digitalWrite(iPinRed1, LOW); digitalWrite(iPinRed2, LOW); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, HIGH);
  • 5. } // Perfect else if (lCM >= RANGE_MIN & lCM < RANGE_MAX) { digitalWrite(iPinRed1, LOW); digitalWrite(iPinRed2, LOW); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, HIGH); digitalWrite(iPinRed5, LOW); } // Range 1 else if (lCM >= RANGE_MAX & lCM < RANGE_1) {
  • 6. digitalWrite(iPinRed1, HIGH); digitalWrite(iPinRed2, HIGH); digitalWrite(iPinRed3, HIGH); digitalWrite(iPinRed4, HIGH); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW); } // Range 2 else if (lCM >= RANGE_1 & lCM < RANGE_2) { digitalWrite(iPinRed1, HIGH); digitalWrite(iPinRed2, HIGH); digitalWrite(iPinRed3, HIGH); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW);
  • 7. } // Range 3 else if (lCM >= RANGE_2 & lCM < RANGE_3) { digitalWrite(iPinRed1, HIGH); digitalWrite(iPinRed2, HIGH); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW); } // Range 4 else if (lCM >= RANGE_3 & lCM < RANGE_4) {
  • 8. digitalWrite(iPinRed1, HIGH); digitalWrite(iPinRed2, LOW); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW); } // Range 5 else if (lCM >= RANGE_4) { digitalWrite(iPinRed1, LOW); digitalWrite(iPinRed2, LOW); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW);
  • 9. } else { digitalWrite(iPinRed1, LOW); digitalWrite(iPinRed2, LOW); digitalWrite(iPinRed3, LOW); digitalWrite(iPinRed4, LOW); digitalWrite(iPinGreen1, LOW); digitalWrite(iPinRed5, LOW); } delay(50); } /**************************************************** ***********/ /* Function: ConvertMSToCM */ /**************************************************** ***********/ long ConvertMSToCM( long lMicroSeconds)
  • 10. { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. - Arduino Site return lMicroSeconds / 29 / 2; } Here is the link to the project: http://blog.mikejmcguire.com/2014/04/20/using-an-arduino-as- a-garage-gar-parking-sensor/