const int BuzzerPin = 3; //Buzzer Pin const int SwitchPin= 2; // Push-button pin
void setup() { pinMode(BuzzerPin,OUTPUT); //Defines pinBuz as an Output pinMode(SwitchPin,INPUT); // Defines pinSwi as an input }
void loop () { int botao; // To save the last logic state of the button botao = digitalRead(pinSwi); //Put the reading value of the switch on botao Serial.println(botao); //Shows the logic state of the input on Serial Monitor if (botao == 1) // Pressed button, logic State HIGH (5V) { digitalWrite(pinBuz,1); //Switch pressed, buzzer on }else { digitalWrite(pinBuz,0); //If the switch isn’t pressed, buzzer off. } delay(10); //reading delay }
Motion Sensor
The three pins are: VCC (Vin): + Vin to 5V Out (O output): Signal wire to digital pin 2 GND (- aka ground): GND - ground to board GND Wire up your motion detector like this picture.
_______________________________________________________________________________________ #include "Servo.h" //Include Servo Motor library for using Servo Servo myServo1;
#define sensor A0
int servo1 = A1; //Digital PWM pin used by the servo 1