Inspiration

We looked at daily tasks of humans as they are the most beneficial to be automated. We then picked the most repetitive task because there is a greater chance that people would need them automated.

What it does

We made a machine that detects occupancy in a room using ultrasonic sensors and toggles a light between on/off.

How we built it

We used an Arduino Uno R3 and 2 ultrasonic sensors and an LED with resistors and a breadboard. We initially simulated the system using python to experiment with different logics and theories. This also enabled us to add complexities without having to do too much complicated work.

Challenges we ran into

Out primary issue was our hardware probably knew a certain mouse the way it was acting goofy. The mechanical buttons for our Arduino had a lot of bounce (switch not working to perfectly close circuit). We solved this by switching to ultrasonic sensors because they were more accurate to recreate a real-life application and were simpler to code and implement.

Accomplishments that we're proud of

We are proud of being able to achieve the final outcome and persevering through difficulties. It was also our first time working together as a team and we are proud of our chemistry. Our problem soving capabilities were also tested and we are proud of out ability to counter our issues.

What we learned

We learned how to use Arduino and join hardware with software. We also learned how to notice user errors and how to plan for adversity for the machine.

What's next for Light-tronic 3000

We plan on putting the sensor and occupancy detecting capabilities as a part of more projects.

Built With

Share this project:

Updates

posted an update

Ardiuno code: ```// Variable to track occupancy

int people = 0;

// false is off, true is on

bool light = false;

// variable for while loops

bool cont = true;

// ULTRASONIC SETUP

const int TRIG_PIN = 6; // Arduino pin connected to Ultrasonic Sensor's TRIG pin

const int ECHO_PIN = 7; // Arduino pin connected to Ultrasonic Sensor's ECHO pin

const int TRIG_PIN2 = 10; // Arduino pin connected to Ultrasonic Sensor's TRIG pin

const int ECHO_PIN2 = 11; // Arduino pin connected to Ultrasonic Sensor's ECHO pin

// Maximum distance for ultrasonic sensor to track within

const int DISTANCE_THRESHOLD = 10;// centimeters

// LED SETUP

const int ledPin = 3;

// Variables to Track ultrasonic sensor distance

float duration_us, distance_cm, duration_us2, distance_cm2;

void setup() {

// put your setup code here, to run once:

// Setup for serial port to help with debugging

Serial.begin(9600);

// Declaring Arduino pins as input or output

pinMode(TRIG_PIN, OUTPUT); // set arduino pin to output mode

pinMode(ECHO_PIN, INPUT); // set arduino pin to input mode

pinMode(TRIG_PIN2, OUTPUT); // set arduino pin to output mode

pinMode(ECHO_PIN2, INPUT); // set arduino pin to input mode

pinMode(ledPin, OUTPUT);

}

void loop() {

// Getting time of reflection for outwards ultrasonic sensor

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN, LOW);

duration_us = pulseIn(ECHO_PIN, HIGH);

// Getting time of reflection for inwards ultrasonic sensor

digitalWrite(TRIG_PIN2, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN2, LOW);

duration_us2 = pulseIn(ECHO_PIN2, HIGH);

// Calculating the distance from return time of ultrasonic waves

distance_cm = 0.021 * duration_us;

distance_cm2 = 0.021 * duration_us2;

// If outside ultrasonic sensor detects a person

if(distance_cm < DISTANCE_THRESHOLD){

while(cont){

  // Calculating the distance from return time of ultrasonic waves

  digitalWrite(TRIG_PIN2, HIGH);

  delayMicroseconds(10);

  digitalWrite(TRIG_PIN2, LOW);

  duration_us2 = pulseIn(ECHO_PIN2, HIGH);

  distance_cm2 = 0.021 * duration_us2;

  // and second sensor detects person

  if(distance_cm2 < DISTANCE_THRESHOLD){

    // Turn on the light if needed

    if(people == 0){

      light = true;

    }

    // increase occupancy

    people+=1;

    // delay to avoid errors

    delay(1000);

    // break loop to continue code

    cont = false;

  }

}

// If inside ultrasonic sensor detects a person

}else if(distance_cm2 < DISTANCE_THRESHOLD){

while(cont){

  // Calculating the distance from return time of ultrasonic waves

  digitalWrite(TRIG_PIN, HIGH);

  delayMicroseconds(10);

  digitalWrite(TRIG_PIN, LOW);

  duration_us = pulseIn(ECHO_PIN, HIGH);

  distance_cm = 0.021 * duration_us;

  // and second sensor detects person

  if(distance_cm < DISTANCE_THRESHOLD){

    // turn off the lights if last person leaves the room

    if(people == 1){

      light = false;

    }

    // Decrease the occupancy

    if(people>=0){

      people-=1;

    }

    // Delay to avoid errors

    delay(1000);

    // Break loop to continue code

    cont = false;

  }

}

}

// Turn on or off light depending on veriable state

if(light){

digitalWrite(ledPin, HIGH);

}else if(!light){

digitalWrite(ledPin, LOW);

}

// Output measured distances and occupancy for debugging

Serial.print("distance: ");

Serial.print(distance_cm);

Serial.println(" cm");

Serial.print("distance2: ");

Serial.print(distance_cm2);

Serial.println(" cm");

Serial.println(people);

// Delay for serial output

delay(100);

// Allowing while loops to run in next iteration of loop

cont = true;

}```

Log in or sign up for Devpost to join the conversation.