Dont know how to programm. Edit programm

Hello! I am newby.
I make project with laser alarm system. I got evrything ok, got code etc. But however its wont work, because i have passive not active buzzer. So i need help to improve my main code with tone code for buzzer. can some one help me write. Codes below:
Main code:

int LED =11; //LED piesl?gts pie pin 13

int Buzzer =8; //Ska?as sign?ls piesl?gts pie pin 7

int Sensor =0; // Fotorezistors piesl?dz pie pin 0

int val = 0; //val is used to store state of input pin
void setup() {
pinMode(LED, OUTPUT); //iest?da digital pin k? izeja
pinMode(Buzzer, OUTPUT); //iest?da digital pin k? izeja
pinMode(Sensor, INPUT); //iest?da analog pin k? ieeja
}
void loop() {
val = analogRead(Sensor); //Nolasa ien?košo sensora v?rt?bu un to saglab?
  if (val<100) // Ja sensors v?rt?ba ir zem <100
   {
   digitalWrite(LED, HIGH); //Iesledz LED
   digitalWrite(Buzzer, HIGH); //Iesl?dz sir?nu
 delay(5000);
   }
    
else if (val>100)

   {      
     digitalWrite(LED, LOW); //pr?t?ji LED izsl?gts
     digitalWrite(Buzzer, LOW); //pret?ji Buzzer izsl?gts
   }
  
}

2. code

void setup()  { 
 // declare pin 9 to be an output:
 pinMode(9, OUTPUT);
 beep(50);
 beep(50);
 beep(50);
 delay(1000);
} 

[color=red]void loop()  { 
 beep(200); 
}

void beep(unsigned char delayms){
 analogWrite(9, 20);      // Almost any value can be used except 0 and 255
                          // experiment to get the best tone
 delay(delayms);          // wait for a delayms ms
 analogWrite(9, 0);       // 0 turns it off
 delay(delayms);          // wait for a delayms ms   
}  [/color]

This part is that what i need in my main code so i got sound from my buzzer.

What have you tried?

(Please, use code tags when posting code)

First, welcome to the Arduino Forum.

You will get a lot more readers and help if you follow the guidelines for posting that appear in the first two posts of this forum. Also, place your cursor in the source code window within the IDE and press Ctrl-T to format your code in the standard way. Then use the "post code" tags (click on '#') to copy from the IDE to the forum.

We said "code" tags, not "color" tags.

This part is that what i need in my main code so i got sound from my buzzer

So, why don't you put it there?

AWOL:
We said “code” tags, not “color” tags.

This part is that what i need in my main code so i got sound from my buzzer

So, why don’t you put it there?

I tried. i am not so skilled with programming and i dont know what i need to change in code to get working it. So it dosnt throw me errors etc.
I tried few variations how i thought it will work, but it wouldnt.

In code there can be 2 void loop’s( i think not(? Thats what i dont know which part i need save, wich change or something delete from code to get working it in 1 code.

I just thought for skilled programmer it would be easy peasy to done it. Thats why i asked for help :slight_smile:

When someone doesn't follow directions, such as putting their code in code tags, people start to question whether any advice they give will be effective.

Arrch: When someone doesn't follow directions, such as putting their code in code tags, people start to question whether any advice they give will be effective.

Quite right. It is a two pronged test:- 1) If they can't follow the instructions then they are not going to understand the reply. 2) If they can't be bothered to follow the instructions then they don't deserve a reply.

kalashas: i have passive not active buzzer. So i need help to improve my main code with tone code for buzzer.

You need to understand how your buzzer works in electrical terms - what input does it need in order to make the noise you want? Perhaps it just needs a 0-5V square wave of the appropriate frequency and less than 20mA. In that case I suggest you start with a test sketch that just drives the buzzer with the right frequency and get that working before you try to add that capability back into your original sketch. Perhaps you will find the tone() function useful for that.

Yap.

TC

i solved my problem with tone/ notone. Its just 1beep, buts its good for me.

Thanks everyone for helping!