Sum Lock(Advanced Locker)

SRJT08302

During Luncheon, Jugaadu was told by his father that they need to change their main locker. They replaced their main locker twice in the previous week as it got jammed. As all their important things are kept in a locker, Jugaadu's father asked Jugaadu to do something that can solve this. Can you help Jugaadu here?

Bag Items:

  1. Arduino UNO UNO
  2. Jumper Wires
  3. USB Cable
  4. Foamsheet
  5. Battery and DC Jack
  6. Gluegun
  7. Touch sensor
  8. Servo Motor
  9. Cutter
  10. Breadboard

"

We can make an advanced sum locker which will be based on the touch sensor and servo motor. Here we can feed our confidential sum in the machine. To open the lock, touch the touchpad and provide the desired sum which is previously fed in the machine; otherwise, the lock will not be opened.

    #include  
Servo myservo; 
int pos = 0; 
int out1_pin=2; 
int out2_pin=3; 
int out3_pin=4; 
int out4_pin=5; 
int sum = 0; 
int count = 0; 
void setup() { 

pinMode(out1_pin,INPUT); 
pinMode(out2_pin,INPUT); 
pinMode(out3_pin,INPUT); 
pinMode(out4_pin,INPUT); 
myservo.attach(9); 
Serial.begin(9600); 

} 

void loop() { 
delay(100); 

if(digitalRead(out1_pin)){ 


digitalWrite(out1_pin,HIGH); 
if(count == 3){ 
count++; 
sum+=1; 
Serial.println(sum); 
sum = 0; 
} 
else{ 
count++; 
sum+=1; 
} 
Serial.println(sum); 
}else 
{ 
digitalWrite(out1_pin,LOW); 
} 
if(digitalRead(out2_pin)) 
{digitalWrite(out2_pin,HIGH); 

if(count == 3){ 
count++; 
sum+=2; 
Serial.println(sum); 
sum = 0; 
} 
else{ 
count++; 
sum+=2; 
} 
Serial.println(sum); 
}else 
{digitalWrite(out2_pin,LOW); 
} 
if(digitalRead(out3_pin)) 
{digitalWrite(out3_pin,HIGH); 

if(count == 3){ 
count++; 
sum+=3; 
Serial.println(sum); 
sum = 0; 
} 
else{ 
count++; 
sum+=3; 
} 
Serial.println(sum); 
}else 
{digitalWrite(out3_pin,LOW); 
} 
if(digitalRead(out4_pin)) 
{digitalWrite(out4_pin,HIGH); 

if(count == 3){ 
count++; 
sum+=4; 
Serial.println(sum); 
sum = 0; 
} 
else{ 
count++; 
sum+=4; 
} 
Serial.println(sum); 
} else 
{digitalWrite(out4_pin,LOW); 

} 
if(count==4){ 
count = 0; 
if (sum==10 ) 
{ 
myservo.write(90); 

} 
else{ 
myservo.write(0); 

} 

}}