Arduino Projects
Arduino Projects
int ledpin=12;
void setup(){
pinMode(ledpin,OUTPUT);
}
void loop (){
digitalWrite(ledpin,HIGH); // turn the led on
delay(1000); //wait for one second
digitalWrite(ledpin,LOW); //turn the led off
delay (1000) ;
}
EXEMPLE 2 falshing led using switch
int ledpin=12;
int swichpin=5;
void setup(){
pinMode(ledpin,OUTPUT);
pinMode(swichpin,INPUT);
}
void loop (){
if(digitalRead (swichpin)==HIGH){
digitalWrite(ledpin,HIGH); // turn the led on
delay(1000); //wait for one second
digitalWrite(ledpin,LOW); //turn the led off
delay (1000) ; }
else{
digitalWrite(ledpin,LOW);
}
}
EXAMPLE 3 : traffic
int ledred =12;
int ledyellow =11;
int ledgreen = 10;
void setup(){
pinMode(ledred,OUTPUT);
pinMode(ledgreen,OUTPUT);
pinMode(ledyellow,OUTPUT);
}
void loop (){
digitalWrite(ledred,HIGH);
digitalWrite(ledyellow,LOW);
digitalWrite(ledgreen,LOW);
delay (1000) ;
digitalWrite(ledred,LOW);
digitalWrite(ledyellow,HIGH);
digitalWrite(ledgreen,LOW);
delay (1000) ;
digitalWrite(ledred,LOW);
digitalWrite(ledyellow,LOW);
digitalWrite(ledgreen,HIGH);
delay (1000) ;
}
EXEMPLE 4: potentiometre
int ledred =12;
int Potentiometre=A0;
float val ;
void setup(){
pinMode(ledred,OUTPUT);
pinMode(Potentiometre,INPUT);
}
void loop (){
val = analogRead(Potentiometre);
digitalWrite(ledred,HIGH);
delay(val);
digitalWrite(ledred,LOW);
delay(val) ;
}
Serial.print("temperature= ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
}
%%%%%%%%%%%%%
void setup(){
Serial.begin(9600);
void loop(){
val=analogRead(temppin);
float mv=(val/1024.0)*5000 ;
Serial.print("temperature= ");
Serial.print(cel);
Serial.print("*C");
Serial.print("VOLTS= ");
Serial.print(mv);
delay(1000);
Serial.println();
EXEMPLE 7: LCD
#include<LiquidCrystal.h>
LiquidCrystal lcd (12,11,5,4,3,2);
void setup(){
lcd.begin(16,2);
lcd.print("hello houssine");
}
void loop(){
lcd.setCursor(0,1);
lcd.print(millis()/1000);
}
EXEMPLE 8 : SPEED CONTROL FOR DC MOTOR
int potpin=A0;
int motorpin=9;
float speed ;
void setup(){
pinMode(motorpin,OUTPUT);
}
void loop (){
speed = (analogRead(potpin))/4;
analogWrite(motorpin,speed);
}
pinMode(ledred,OUTPUT);
Serial.begin(9600);
}
void loop(){
int val= Serial.read();
if (val=='1'){digitalWrite(ledred,HIGH);}
if (val=='0'){digitalWrite(ledred,LOW);}
}
EXEMPLE 10 KEYPAD
//Example_13_Keypad_Input
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {9,8, 7, 6};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins,
ROWS,COLS );
void setup()
{ Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();