int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 5000;
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
}
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}
void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
void setup()
{
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void loop()
{
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(8,1);
digitalWrite(2,0);
digitalWrite(6,0);
digitalWrite(3,0);
digitalWrite(7,0);
digitalWrite(10,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(6,1);
digitalWrite(5,0);
delay(1000);
digitalWrite(2,1);
digitalWrite(8,1);
digitalWrite(7,1);
digitalWrite(3,0);
digitalWrite(6,0);
digitalWrite(9,0);
digitalWrite(5,0);
digitalWrite(10,0);
digitalWrite(4,0);
delay(5000);
digitalWrite(9,1);
digitalWrite(8,0);
delay(1000);
digitalWrite(5,1);
digitalWrite(2,1);
digitalWrite(10,1);
digitalWrite(6,0);
digitalWrite(8,0);
digitalWrite(4,0);
digitalWrite(7,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(3,1);
digitalWrite(2,0);
delay(1000);
}
#include "SevSeg.h" SevSeg sevseg; void setup() { byte numDigits = 4; byte digitPins[] = {2, 3, 4, 5}; byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); sevseg.setBrightness(90); } void loop() { sevseg.setNumber(3141, 3); sevseg.refreshDisplay(); }
#include <LiquidCrystal.h>
int tempPin = 0;
int lightPin = 1;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
lcd.print("Temp F ");
lcd.setCursor(6, 0);
lcd.print(tempF);
int lightReading = analogRead(lightPin);
lcd.setCursor(0, 1);
lcd.print("Light ");
lcd.setCursor(6, 1);
lcd.print(lightReading);
delay(500);
}
#include <Keypad.h> #include<LiquidCrystal.h> #include<EEPROM.h> LiquidCrystal liquid_crystal_display(9,8,7,6,5,4,); char password[4]; char initial_password[4],new_password[4]; int i=0; int relay_pin = 10; char key_pressed=0; const byte rows = 4; const byte columns = 4; char hexaKeys[rows][columns] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte row_pins[rows] = {A0,A1,A2,A3}; byte column_pins[columns] = {A4,A5,3,2}; Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns); void setup() { pinMode(relay_pin, OUTPUT); liquid_crystal_display.begin(16,2); liquid_crystal_display.print(" DIYhacking.com"); liquid_crystal_display.setCursor(0,1); liquid_crystal_display.print("Electronic Lock "); delay(2000); liquid_crystal_display.clear(); liquid_crystal_display.print("Enter Password"); liquid_crystal_display.setCursor(0,1); initialpassword(); } void loop() { digitalWrite(relay_pin, HIGH); key_pressed = keypad_key.getKey(); if(key_pressed=='#') change(); if (key_pressed) { password[i++]=key_pressed; liquid_crystal_display.print(key_pressed); } if(i==4) { delay(200); for(int j=0;j<4;j++) initial_password[j]=EEPROM.read(j); if(!(strncmp(password, initial_password,4))) { liquid_crystal_display.clear(); liquid_crystal_display.print("Pass Accepted"); digitalWrite(relay_pin, LOW); delay(2000); liquid_crystal_display.setCursor(0,1); liquid_crystal_display.print("Pres # to change"); delay(2000); liquid_crystal_display.clear(); liquid_crystal_display.print("Enter Password:"); liquid_crystal_display.setCursor(0,1); i=0; } else { digitalWrite(relay_pin, HIGH); liquid_crystal_display.clear(); liquid_crystal_display.print("Wrong Password"); liquid_crystal_display.setCursor(0,1); liquid_crystal_display.print("Pres # to Change"); delay(2000); liquid_crystal_display.clear(); liquid_crystal_display.print("Enter Password"); liquid_crystal_display.setCursor(0,1); i=0; } } } void change() { int j=0; liquid_crystal_display.clear(); liquid_crystal_display.print("Current Password"); liquid_crystal_display.setCursor(0,1); while(j<4) { char key=keypad_key.getKey(); if(key) { new_password[j++]=key; liquid_crystal_display.print(key); } key=0; } delay(500); if((strncmp(new_password, initial_password, 4))) { liquid_crystal_display.clear(); liquid_crystal_display.print("Wrong Password"); liquid_crystal_display.setCursor(0,1); liquid_crystal_display.print("Try Again"); delay(1000); } else { j=0; liquid_crystal_display.clear(); liquid_crystal_display.print("New Password:"); liquid_crystal_display.setCursor(0,1); while(j<4) { char key=keypad_key.getKey(); if(key) { initial_password[j]=key; liquid_crystal_display.print(key); EEPROM.write(j,key); j++; } } liquid_crystal_display.print("Pass Changed"); delay(1000); } liquid_crystal_display.clear(); liquid_crystal_display.print("Enter Password"); liquid_crystal_display.setCursor(0,1); key_pressed=0; } void initialpassword(){ for(int j=0;j<4;j++) EEPROM.write(j, j+49); for(int j=0;j<4;j++) initial_password[j]=EEPROM.read(j); }
#include<LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int in = 8; int Reset=6; int start=7; int count=0,i=0,k=0,rate=0; unsigned long time2,time1; unsigned long time; byte heart[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000 }; void setup() { lcd.createChar(1, heart); lcd.begin(16,2); lcd.print("Heart Beat "); lcd.write(1); lcd.setCursor(0,1); lcd.print("Monitering"); pinMode(in, INPUT); pinMode(Reset, INPUT); pinMode(start, INPUT); digitalWrite(Reset, HIGH); digitalWrite(start, HIGH); delay(1000); } void loop()
{ if(!(digitalRead(start))) { k=0; lcd.clear(); lcd.print("Please wait......."); while(k<5) { if(digitalRead(in)) { if(k==0) time1=millis(); k++; while(digitalRead(in)); } } time2=millis(); rate=time2-time1; rate=rate/5; rate=60000/rate; lcd.clear(); lcd.print("Heart Beat Rate:"); lcd.setCursor(0,1); lcd.print(rate); lcd.print(" "); lcd.write(1); k=0; rate=0; } if(!digitalRead(Reset)) { rate=0; lcd.clear(); lcd.print("Heart Beat Rate:"); lcd.setCursor(0,1); lcd.write(1); lcd.print(rate); k=0; } }
int incomingByte = 0; // for incoming serial data void setup() { Serial.begin(9600); pinMode(13, OUTPUT); } void loop() { if (Serial.available() > 0) { incomingByte = Serial.read() Serial.print(“I received: “); Serial.println(incomingByte, DEC); if ( incomingByte == 65) { digitalWrite(13, HIGH); } else if ( incomingByte == 97) { digitalWrite(13, LOW); } }
int sensorPin=A0;
int sensorValue=0;
int piezoPin=9;
void setup()
{
pinMode(sensorPin,INPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(piezoPin,OUTPUT);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
}
void loop()
{
sensorValue=analogRead(sensorPin);
if(sensorValue<=1000)
{
digitalWrite(piezoPin,HIGH);
{tone(9,3047,400); noTone(8); } digitalWrite(7,HIGH); }
else
{digitalWrite(piezoPin,LOW); digitalWrite(7,LOW); }
sensorValue=1000; }
#include <LiquidCrystal.h> LiquidCrystal lcd(7, 8, 9, 10, 11, 12); int potPin = A4; int potValue = 0; int buzzer = 6; void setup() { lcd.begin(16, 2); // lcd rows and columns lcd.print("GAS SENSOR"); pinMode(6, OUTPUT); } void loop() { potValue = analogRead(potPin); lcd.setCursor(0, 1); lcd.print("Value = "); lcd.print(potValue); delay(1000); lcd.print(" "); delay(1); if (potValue>15) { digitalWrite(6,HIGH); delay(1000); } }
const int sensorPin = A0;
const int ledPin = 3;
const int potentiometerPin = A1;
float potentiometerVal;
float sensorVal;//sensor
float light = 0;
float mapping;
void setup(){
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop(){
sensorVal = analogRead(sensorPin);
potentiometerVal = analogRead(potentiometerPin);
potentiometerVal = map(potentiometerVal, 0, 1023, 0, 255);
sensorVal = map(sensorVal,0,1023, 255, 0);
mapping = potentiometerVal;
light = map (sensorVal, 0, 255, sensorVal - potentiometerVal , 255);
if (light <= 0)
light=0;
Serial.print("Brightness: ");
Serial.println(sensorVal);
Serial.print("Mapping: ");
Serial.println(potentiometerVal);
analogWrite(ledPin,light);
Serial.print("Light: ");
Serial.println(light);
delay(15);
}