Cannot get code to work with ATmega328P

I have a ATmega328P Mini Nano and I cannot seem to get code to work on it. The code works fine in simulation but does not work when loaded in. Is there something I can add to the code or set differently in the Arduino program? I have it set to Board: Arduino Nano, Processor ATmega 328P (Old Bootloader).

How in the world can we answer that question without seeing the code? And “code doesn’t work” conveys on useful information that we can use to help you. Tell us what the code actually does and how that differs from what you want. If there are compile errors, post the entire error message. Do not paraphrase.

Read the forum guidelines to see how to properly post code and error messages.

Yes

The code is: #include <Servo.h>
Servo myservo;
const int Digit1_En=13;
const int Digit2_En=12;
const int Motor_En=8;
const int button_Set=A0;
const int button_Minus=A1;
const int button_Plus=A2;
const int button_Next=A3;
void setup()
{
pinMode(Digit1_En,OUTPUT);
pinMode(Digit2_En,OUTPUT);
pinMode(button_Set,INPUT);
pinMode(button_Minus,INPUT);
pinMode(button_Plus,INPUT);
pinMode(button_Next,INPUT);
myservo.attach(9);
DDRD = 0b11111110; //D1-D7(Set as output)
}

void loop()
{

}

void zero()
{
PORTD = 0b00000010;
}
void one()
{
PORTD = 0b10011110;
}
void two()
{
PORTD = 0b00100100;
}
void three()
{
PORTD = 0b00001100;
}
void four()
{
PORTD = 0b10011000;
}
void five()
{
PORTD = 0b01001000;
}
void six()
{
PORTD = 0b01000000;
}
void seven()
{
PORTD = 0b00011110;
}
void eight()
{
PORTD = 0b00000000;
}
void nine()
{
PORTD = 0b00011000;
}
void selfTest_7Seg()
{
digitalWrite(Digit1_En,HIGH);
digitalWrite(Digit2_En,HIGH);
zero();
delay(1000);
one();
delay(1000);
two();
delay(1000);
three();
delay(1000);
four();
delay(1000);
five();
delay(1000);
six();
delay(1000);
seven();
delay(1000);
eight();
delay(1000);
nine();
delay(1000);
}
void selfTest_DcMotor()
{
digitalWrite(Motor_En,HIGH);
delay(10000);
digitalWrite(Motor_En,LOW);
delay(10000);
}
void selfTest_ServoMotor()
{
for(int i=0;i<=360;i++)
{
myservo.write(i);
delay(30);
}
delay(500);
for(int j=360;j>=0;j–)
{
myservo.write(j);
delay(30);
}
delay(500);
}
void selfTest_Buttons()
{
if(digitalRead(button_Set) == HIGH)
{
digitalWrite(Digit1_En,HIGH);
one();
}
else if(digitalRead(button_Minus) == HIGH)
{
digitalWrite(Digit1_En,HIGH);
two();
}
else if(digitalRead(button_Plus) == HIGH)
{
digitalWrite(Digit1_En,HIGH);
three();
}
else if(digitalRead(button_Next) == HIGH)
{
digitalWrite(Digit1_En,HIGH);
four();
}
}

This is the pin schematic.

I will try again. Read the forum guidelines.

Also it would help if you use the IDE auto format tool (ctrl-t or Tools, Auto Format) before posting code in code tags.

Your loop is empty. Nothing will happen with an empty loop() function.

You cannot power motors and servos from the Arduino 5V. It cannot supply the required current and will shut itself down (if you are lucky) or just burn out. Power heavier loads from an external supply capable of supplying the current, Connect the external supply ground to the Arduino ground.

Your motor circuit is lacking the required flyback diode.

You can’t use a voltage regulator to switch the motor.

The program is doing exactly what you’ve instructed it to do… which is… absolutely nothing.

Please do some reading on the absolute basics of Arduino programming. There is a reason why setup() and loop() are predefined in every program created by the IDE.

The motor cannot be attached to the Arduino 3.3v pin.

Do not connect the servo to the Arduino 5v pin.

Connect switches between the input pin and GND; use INPUT_PULLUP for input pins. Look for a LOW on the pin to see if it is closed.

Use S3 in the schematic below for pin wiring:

If that’s a simple 7 segment LED display, you need series dropping resistors; how is the displayed powered ?

Where is your GND connection to the Arduino ?