Homework 2

Combo_Lock_unlocked This combination lock works with two potentiometers and a button and two leds for indication of state. Potentiometers have to be set to a certain range, when checking by pressing the button the red led turns off and the green turns on indicating the unlocking of the system.

In collaboration with Joanna Chin.


boolean unlock0 = false;
boolean unlock1 = false;

void setup() {
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT);

void loop()
int sensorValue0;
sensorValue0 = analogRead(A0);
// Serial.println(sensorValue0);

int sensorValue1;
sensorValue1 = analogRead(A1);
// Serial.println(sensorValue1);

//range of first potentiometer
if (sensorValue0 > 800 && sensorValue0 < 1023) {
unlock0 = true;
unlock0 = false;
//range of second potentiometer
if (sensorValue1 > 0 && sensorValue1 < 200) {
unlock1 = true;
unlock1 = false;

if(digitalRead(2) == HIGH){
else {

if(unlock0 == true && unlock1 == true && digitalRead(2) == HIGH){
digitalWrite(13, HIGH);
digitalWrite(11, LOW);
digitalWrite(13, LOW);
digitalWrite(11, HIGH);


Here are the two exercises we completed in class.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s