Sei sulla pagina 1di 15

Arduino

Digital I/O (2 13) Serial Transfer (0 -1)

USB (Data & Power)

Power Source Reset


Jumper

Alternate Power (9V)

5V / 9V / GND (x2) Analog Input (0 5)


Led blinking
SINGLE LED BLINKING CODE
// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin 13 as an output.


pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever

void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second

digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
LED Chaser using Arduino
//program for led chaser
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}

// the loop function runs over and over again forever

void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(12, LOW);
digitalWrite(11, LOW);
delay(100); // wait for a second
digitalWrite(13, LOW);
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(11, LOW);
delay(100);
digitalWrite(13, LOW);
digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(11, HIGH);
delay(100); // wait for a second
}
Interfacing Buzzer with Arduino
program
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);

}
Interfacing push button
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Introduction to PIR sensor
Motion Sensor Light Circuit with an Arduino
const int ledPin= 13;

const int inputPin= 2;

void setup()
{

pinMode(ledPin, OUTPUT);

pinMode(inputPin, INPUT);

void loop(){
int value= digitalRead(inputPin);

if (value == HIGH)
{
digitalWrite(ledPin, HIGH);
delay (3000);
}

else
{
digitalWrite(ledPin, LOW);
}
}
Night Light Circuit Using an Arduino
CIRCUIT
Code
The code to turn on an LED when the light level falls below a certain threshold is shown below.

const int ledPin=13; //the code will flash the LED connected to pin 13
const int sensorPin= 0; //Sensor pin connects to analog pin A0

int level; //the variable that will hold the light level reading

const int threshold=150; //this represents the threshold voltage. If voltage is below 150, this triggers the LED to turn on

void setup() {
pinMode (ledPin, OUTPUT); //sets digital pin 13 as output
Serial.begin(9600); //sets the baud rate at 9600 so we can check the values the sensor is obtaining on the Serial Monitor
}

void loop(){
level= analogRead(sensorPin); //the sensor takes readings from analog pin A0
if (level < threshold){
digitalWrite(ledPin, HIGH); //if the light level is below the threshold level, the LED turns on
}
else{
digitalWrite(ledPin, LOW); //otherwise, if the light level is above the threshold level, the LED is of
}
}

Potrebbero piacerti anche