High rabbitmoon,
welcome to the Arduino-Forum.
You seem to be right at the beginning. And you did a very important first step that does not happen so often.
Posting your first attempt to write the code. This is very good. Even if there might be some bugs in your code. Your attempt to write the code gives very important information about your skill-level which is important to adapt answers to your knowledge- and skill level.
You posted a tinkercad picture that shows how you have wired things together in the tinkercad simulation. The tinkercad-simulation is good for code-development. But it is really bad about the hardware-aspects.
The onboard-voltage-regulator of an arduino is completely overloaded with a DC-motor and a servo with some load. They need their own powersupply but the GNDs must be connected together.
As a general advice: You should give an overview about the final purpose of your project
What are the DC-motor and the servo do in the end?
Is this just an exercise or is there a realworld-application behind it?
Using some example-code making small modifications in the code is quickly successful.
But changing the functionality of a given example to deviate more requires as a must understanding the lines of code.
From the questions posted above I can conclude your knowledge is improvable.
Basically there are two ways to go on:
-
stumbling forward without really understanding how the code works
you will get a 70% working code pretty quickly. But the 30% missing will need a lot of time to write -
doesn't seem to make any headway at first by learning basic things that have nothing to do with your actual code but teaching you fundamental concepts that you then can apply to your project quickly and successful after having understood the basic concepts.
So you can go on walking by foot as a jogger
or start building a race-car-kit where building the race-car-kit keeps you behind the startline but in a 500 miles race on the third day (after finishing the race-car-kit) you will wrooom!-zoom pass the jogger and win the race.
If you prefer the second way start reading this tutorial
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
best regards Stefan
by the way
Make experienced users help: two ways to quickly post code as a code-section