you are welcome to this forum. Really! You can ask as many questions about programming and about electronics as you like. As long as you show some own effort in learning you will receive answers to your questions.
This is a very generalised comment. Asking in a hidden way "can somebody post the code that will make my LED switch on and the buzzer buzz?"
There are thousands of similarities to your coding-problem
on one signal-input switch on/off two outputs. Take any code that uses a single input
and switches an output. And you can start to adapt this code.
I guess this short explanation does not help at all.
There is no way around learning some basic things about arduino-programming.
- what does function setup do?
- what does function loop do?
- how do I configure an IO-pin as output?
- what is a pullup-resistor
How can I make code-execution conditional?
How can I detect a state-change?
Without this basic knowledge you depend 101% on other users to again and again and again modify the code to your needs.
One way to learn these basic things is
Take a look into this tutorial:
Arduino Programming Course
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.
In your schematic you connected the LED and the buzzer directly to arduino-IO-pins
From your schematic I assume that you knowledge about the circuitside is too less.
An LED needs a current-limiting resistor which you haven't drawn in your schematic.
Your buzzer will draw more than 40mA which will burn through the Arduino Megas IO-pin
Connecting a 12V signal through a 1kOhm-resistor to "adapt" to the 5V-level of the Ardiuno-Mega is unprofessional. This should be done through an optocoupler (again with a matching current-limiting resistor or with a voltage-divider with matching values.
You are really welcome to ask many questions how to optimise your project just the way you did it: Posting a schematic and asking for feedback what other (more experienced people) say to your design.
best regards Stefan