Introduction: Red Signal Crossing by Karam

Picture of Red Signal Crossing by Karam

ان المشروع مثل اشارة المرور بدون الون الاخضر مع عداد يعد

الى العشرة واذا تحرك شيئ امامها سوف تزمر و تبقا اشارة

امرور الحمراء مضيئة,انها تحمي اذا دخل شخص غريب الى

البيت او الفندق او المكتب او اي مكان اخر , او تستخدم الى

تعليم الاطفال كيف تعمل اشارة المرور .

Step 1:

Picture of

PARTS:

1:SEVEN SEGMENTS.

2:Ultrasonic Ranging Module HC - SR04.

3:buzzer.

4:TWO RED (LEDS) .

5:WIRES.

6: TWO RESISTANC(RED,RED,BLACK,GOLD)220 OHM, And one Resistanc ( green, blue, brown, gold)561 OHM.

Step 2: Code

int trigPin = 13;
int echoPin = 12;
int led = 7;
int buzzer = 1;
//#define led2 11
int Sig1_G=11;
int Sig1_R =10;

int a = 2; //For displaying segment "a"
int b = 3; //For displaying segment "b"
int c = 4; //For displaying segment "c"
int d = 5; //For displaying segment "d"
int e = 6; //For displaying segment "e"
int f = 8; //For displaying segment "f"
int g = 9; //For displaying segment "g"
int i;
void setup() {
pinMode(a, OUTPUT); //A
pinMode(b, OUTPUT); //B
pinMode(c, OUTPUT); //C
pinMode(d, OUTPUT); //D
pinMode(e, OUTPUT); //E
pinMode(f, OUTPUT); //F
pinMode(g, OUTPUT); //G

pinMode(Sig1_G,OUTPUT);
pinMode(Sig1_R,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
}
void displayDigit(int digit)
{


//Conditions for displaying segment a
if(digit!=1 && digit != 4)
digitalWrite(a,HIGH);

//Conditions for displaying segment b
if(digit != 5 && digit != 6)
digitalWrite(b,HIGH);

//Conditions for displaying segment c
if(digit !=2)
digitalWrite(c,HIGH);

//Conditions for displaying segment d
if(digit != 1 && digit !=4 && digit !=7)
digitalWrite(d,HIGH);

//Conditions for displaying segment e
if(digit == 2 || digit ==6 || digit == 8 || digit==0)
digitalWrite(e,HIGH);

//Conditions for displaying segment f
if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
digitalWrite(f,HIGH);
if (digit!=0 && digit!=1 && digit !=7)
digitalWrite(g,HIGH);
//digitalWrite(Sig1_G,HIGH);


}
void crossRedsignal()
{
digitalWrite(buzzer,LOW);
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 100) { // This is where the LED On/Off happens
digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
// digitalWrite(led2,LOW);
}
else {
digitalWrite(led,LOW);
//digitalWrite(led2,HIGH);
}
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
// digitalWrite(led,HIGH);
}
delay(500);
}

void turnOff()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);


// delay(2000);
}

void loop() {
for( i=0;i<10;i++)
{
displayDigit(i);
crossRedsignal();
digitalWrite(Sig1_G,HIGH);
digitalWrite(Sig1_R,HIGH);
delay(1000);

turnOff();

}
if ( i = 10) {digitalWrite(Sig1_G,LOW);digitalWrite(Sig1_R,LOW); delay(1000);}
//crossRedsignal();
}

Step 3:

Comments

Swansong (author)2016-11-18

This is a great way to show them how they work :)