program( USING FOR LOOP)
(agr kisi project ka time different ho toh hm off on time use krty hain r agr on nzaida dair
rakhna ho r off time kam ho toh b hm yeh phenomenon use kr skty hain r yeh technique
traffic light main use hoti hai.)
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
// put your setup code here, to run once:
void loop() {
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
// put your main code here, to run repeatedly:
}
for (int j=1; j<=5; j++){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
//int j=1;
// while(j<=10){
//digitalWrite(yellowledpin,HIGH);
//delay(yelowontime);//1000ms means 1s.
//digitalWrite(yellowledpin,LOW);
//delay(yellowofftime);
// j++
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
// put your setup code here, to run once:
void loop() {
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
// put your main code here, to run repeatedly:
for (int j=1; j<=5; j++){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
//int j=1;
// while(j<=10){
//digitalWrite(yellowledpin,HIGH);
//delay(yelowontime);//1000ms means 1s.
//digitalWrite(yellowledpin,LOW);
//delay(yellowofftime);
// j++
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
// put your setup code here, to run once:
void loop() {
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
// put your main code here, to run repeatedly:
for (int j=1; j<=5; j++){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
//int j=1;
// while(j<=10){
//digitalWrite(yellowledpin,HIGH);
//delay(yelowontime);//1000ms means 1s.
//digitalWrite(yellowledpin,LOW);
//delay(yellowofftime);
// j++
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
// put your setup code here, to run once:
void loop() {
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
// put your main code here, to run repeatedly:
for (int j=1; j<=5; j++){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
//int j=1;
// while(j<=10){
//digitalWrite(yellowledpin,HIGH);
//delay(yelowontime);//1000ms means 1s.
//digitalWrite(yellowledpin,LOW);
//delay(yellowofftime);
// j++
}
program( USING WHILE LOOP)
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
// put your setup code here, to run once:
void loop() {
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
// put your main code here, to run repeatedly:
Serial.println(" ");
Serial.println("yellow is blinking");
int j=1;
while(j<=10){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
Serial.print(j);
Serial.println("blink");
j++;
program( Serial monitor)
computer r arduino ki communication through usb ho rhi hoti hai r yeh serial communication hoti hai.
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("HELLO WORLD");
delay(500);
program( Serial monitor using for loop)
int redledpin=13;
int redontime=500;
int redofftime=500;
int yellowledpin=12;
int yellowontime=500;
int yellowofftime=500;
void setup() {
pinMode(redledpin,OUTPUT);//pin number 13 is setup
pinMode(yellowledpin,OUTPUT);
Serial.begin(9600);
// put your setup code here, to run once:
void loop() {
Serial.println("red is blinking");
for (int i=1; i<=10; i++){
digitalWrite(redledpin,HIGH);
delay(redontime);//1000ms means 1s.
digitalWrite(redledpin,LOW);
delay(redofftime);
Serial.print(i);
Serial.println("blink");
// put your main code here, to run repeatedly:
Serial.println(" ");
Serial.println("yellow is blinking");
int j=1;
while(j<=10){
digitalWrite(yellowledpin,HIGH);
delay(yellowontime);//1000ms means 1s.
digitalWrite(yellowledpin,LOW);
delay(yellowofftime);
Serial.print(j);
Serial.println("blink");
j++;
program( Serial monitor user input)
int number;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Enter a number:");
while(Serial.available()==0){}
number=Serial.parseInt();
Serial.print("The number is");
Serial.print( number);
program( analog input)
float y=153.0;
float x;
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
analogWrite(13,y);
x=y/51.0;
Serial.println("the output voltage is");
Serial.println(x);
Serial.println(" ");
delay(500);
}
program(read input from arduino):
int ReadVolts;
float RealVolts;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
ReadVolts=analogRead(A0);
RealVolts=(5.0/1023.0)*ReadVolts;
Serial.println(RealVolts);
delay(250);
}
program(using map command):
int ReadVolts;
float RealVolts;
int val;
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
ReadVolts=analogRead(A0);
RealVolts=(5.0/1023.0)*ReadVolts;
val=map(ReadVolts,0,1023,0,255);
analogWrite(13,val);
Serial.println(RealVolts);
delay(250);
program(servo motor):
“Built in program”
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
myservo.attach(9); // attaches the servo on pin 9 to the servo object
void loop()
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
program(DC motor speed Control):
program(keypad interfacing)
program(LCD interfacing)
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 9 , 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}