# Help fix code

**URL:** <https://forum.arduino.cc/t/help-fix-code/680714>\
**Category:** Programming\
**Created:** [October 31, 2020, 10:38am UTC](https://forum.arduino.cc/t/help-fix-code/680714 "2020-10-31T10:38:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CharlieStakes](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@CharlieStakes](https://forum.arduino.cc/u/CharlieStakes)\
**Post date:** [October 31, 2020, 10:38am UTC](https://forum.arduino.cc/t/help-fix-code/680714/1 "2020-10-31T10:38:31Z")

</div>

Hi Everyone,

I've been working on this code for a while but I'm so confused on the errors if anyone can please help me fix the errors I will be forever thankful!

void setup() {  
// put your setup code here, to run once:

#define trigpin 8  
#define echopin 6  
pinMode(trigpin, OUTPUT);  
pinMode(echopin, INPUT);

int buttonPin = 8;  
int buttonState = 0;

digitalWrite(trigpin, HIGH);  
delay(50);  
digitalWrite(trigpin, LOW);

unsigned long duration=pulseIn(echopin,HIGH);  
int distance=(duration/2)/29.1;

#include \<Servo.h\>  
Servo myservo;

myservo.attach(9);  
myservo.writeMicroseconds(50);  
myservo.write(90);

int val, potpin = 0;  
val = analogRead(potpin);  
val = map(val, 0, 1023, 0, 180);

pinMode(buttonPin, INPUT);  
digitalWrite(buttonPin, HIGH);

#include \<LiquidCrystal.h\>  
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);  
lcd.begin(16, 2);  
lcd.clear();  
lcd.print("Stay out!");

}

[Door\_opener.ino](https://forum.arduino.cc/uploads/short-url/h77WeYKUAulGuTcOvdgNVK6yjdl.ino) (783 Bytes)

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [October 31, 2020, 10:40am UTC](https://forum.arduino.cc/t/help-fix-code/680714/2 "2020-10-31T10:40:05Z")

</div>

Please follow the advice on posting a programming question given in [Read this before posting a programming question](https://forum.arduino.cc/index.php?topic=97455.0)

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [October 31, 2020, 10:44am UTC](https://forum.arduino.cc/t/help-fix-code/680714/3 "2020-10-31T10:44:13Z")

</div>

Please post your code within \</\> code-tags.

You've put you whole code within setup() and loop() is missing  
All the includes & defines should be before any of the function declarations.

Have a look at any of the examples.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:49am UTC](https://forum.arduino.cc/t/help-fix-code/680714/4 "2021-05-06T00:49:39Z")

</div>

Closed on May 6, 2021, 12:49am UTC


