Arduino Lernen

Arduino…

Arduino-callouts1

 

 

 

 

 

 

1. Blink

Skectch_Arduino_LED_Blink

 

 

 

 

 

 

 

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

 

2. Button on off

button

 

 

int led =8;      // LED is Connected to PIN 8
int button =9;   // Pushbutton PIN is 9
int  OnFlag=0;   // Flag we need to tell if the LED is ON or OFF
void setup()
{
pinMode(led,OUTPUT); pinMode(button,INPUT_PULLUP); // Setting the PINs direction, we need to set PIN9 as output and the other PIN as input
}
void loop()
{
if(digitalRead(button)==LOW && OnFlag=0) // if the button is pressed and the LED is OFF then
{
delay(250);                          // 250 ms delay for debounce
digitalWrite(led,HIGH);              // Then Turn ON LED(Anode PIN of LED is connected to GND
OnFlag=1;                           // Set the Flag to 1
}
if(digitalRead(button)==LOW && OnFlag==1) // Now if the button is Pressed and the LED is ON
{
 delay(250);                               // 250 ms delay for debounce
digitalWrite(led,LOW);                    // Then Turn OFF LED
OnFlag=0;                                 // Clear the Flag to 0
}
}

3. PIR Sensor

Schematic_bb

 

 

 

 

 

 

 

int led =8;      // LED is Connected to PIN 8
int button =9;   // Pushbutton PIN is 9
int  OnFlag=0;   // Flag we need to tell if the LED is ON or OFF
void setup()
{
pinMode(led,OUTPUT); pinMode(button,INPUT_PULLUP); // Setting the PINs direction, we need to set PIN9 as output and the other PIN as input
}
void loop()
{
if(digitalRead(button)==LOW && OnFlag=0) // if the button is pressed and the LED is OFF then
{
delay(250);                          // 250 ms delay for debounce
digitalWrite(led,HIGH);              // Then Turn ON LED(Anode PIN of LED is connected to GND
OnFlag=1;                           // Set the Flag to 1
}
if(digitalRead(button)==LOW && OnFlag==1) // Now if the button is Pressed and the LED is ON
{
 delay(250);                               // 250 ms delay for debounce
digitalWrite(led,LOW);                    // Then Turn OFF LED
OnFlag=0;                                 // Clear the Flag to 0
}
}

4. LM35 Temperatur Sensor

 

LM35-temperature-sensor-pinout lm35

 

 

 

 

 

 

 

 

LM35 sensor has three legs like a Transistor, first leg is Vin second one is Vout and the third one is Ground. we have to supply 5 volts to Vin and Ground and take the output voltage at Vout which tells us the temperature in terms of voltage.

Circuit
 
 Code
// this is where we will store the temperature in centigrade
float temperature;
// this is where we will store the raw reading from the analogue pin
int reading;          
// this is where we will store the pin number that we are reading from
int lm35Pin =5;          

voidsetup()
{
analogReference(INTERNAL);
Serial.begin(9600);
}
voidloop()
{
reading =analogRead(lm35Pin);
temperature = reading /9.31;
Serial.println(temperature);
delay(1000);
}

5. Keypad

keypad4x4 4-x-4-keypad

 

 

 

 

 

 

 

#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;                                                          
 
//define the symbols on the buttons of the keypads
char Keys[ROWS][COLS] =
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
 
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(Keys),rowPins,colPins,ROWS,COLS);
 
void setup()
{
  Serial.begin(9600);
  Serial.println("Please press the keyboard:");
}
 
void  loop()
{
  char key = customKeypad.getKey();
  if(key!=NO_KEY)
  {
    Serial.print("Key Value : ");
    Serial.println(key);
  }
}

 

6. Servo

 

1

 

 

 

 

 

 

 

#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;                                                          
 
//define the symbols on the buttons of the keypads
char Keys[ROWS][COLS] =
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
 
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(Keys),rowPins,colPins,ROWS,COLS);
 
void setup()
{
  Serial.begin(9600);
  Serial.println("Please press the keyboard:");
}
 
void  loop()
{
  char key = customKeypad.getKey();
  if(key!=NO_KEY)
  {
    Serial.print("Key Value : ");
    Serial.println(key);
  }
}

7. ACS712

arduino_Amp

 

 

 

 

 

 

 

int sensorValue;  // sensor value by ADC, 10-bit (0-1023)
long current;    // actual current value in mA


void setup() {
  Serial.begin( 9600 );  // sets the serial port to 9600
}

void loop() {
  sensorValue = analogRead( 0 );   // read analog input pin 0
  Serial.print(sensorValue, DEC);  // prints the value read
  Serial.print( " = " );
  // truncate max limit
  if( sensorValue < 103 ) sensorValue = 102;
  else if( sensorValue > 921 ) sensorValue = 922;
  sensorValue -= 102;
  // calculate current using integer operation
  current = ( ( sensorValue * 1248 ) >> 10 ) - 5000;
  Serial.print( (int)current, DEC );  // prints current value
  Serial.println( " mA" );
  delay(100);               // wait 100 ms for next reading
}

 

7.LCD Keypad Shild

 

arduino-lcd-keypad-shield

 

 

 

 

 

 

 

keypad

 

 

 

 

 

 

 

 

Pin Function
Analog 0 Button (select, up, right, down and left)
Digital 4 DB4
Digital 5 DB5
Digital 6 DB6
Digital 7 DB7
Digital 8 RS (Data or Signal Display Selection)
Digital 9 Enable
Digital 10 Backlit Control

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

 /*******************************************************
This program will test the LCD panel and the buttons
 Mark Bramwell, July 2010
********************************************************/

 
 // select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0); // read the value from the sensor
/* my buttons when read are centered at
 these values: 0,144, 329, 504, 741
we add approx 50 to those values and
check to see if we are close */

 
// We make this the 1st option for speed reasons
 since it will be the most likely result

if (adc_key_in > 1000) return btnNONE;
 
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;

// For V1.0 comment the other threshold and use the one below:
/* if (adc_key_in < 50) return btnRIGHT;
 if (adc_key_in < 195) return btnUP;
 if (adc_key_in < 380) return btnDOWN;
 if (adc_key_in < 555) return btnLEFT;
 if (adc_key_in < 790) return btnSELECT; */


 return btnNONE; // when all others fail, return this...
 }

void setup()
 {
 lcd.begin(16, 2); // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
 }

 void loop()
{
 // move cursor to second line "1" and 9 spaces over
 
 lcd.setCursor(9,1);
 lcd.print(millis()/1000); // display seconds elapsed since power-up

 lcd.setCursor(0,1); // move to the begining of the second line
 lcd_key = read_LCD_buttons(); // read the buttons

 // depending on which button was pushed, we perform an action

switch (lcd_key)
{
 case btnRIGHT:
 {
 lcd.print("RIGHT ");
 break;
 }
 case btnLEFT:
 {
 lcd.print("LEFT ");
 break;
 }
 case btnUP:
 {
 lcd.print("UP ");
 break;
 }
 case btnDOWN:
 {
 lcd.print("DOWN ");
 break;
 }
 case btnSELECT:
 {
 lcd.print("SELECT");
 break;
 }
 case btnNONE:
 {
 lcd.print("NONE ");
 break;
 }
 }
 }

 

 

 

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.