1702 김종은 sshsYoon so young1712이찬장광재박다솜1715최우진
Published

SSHS_CS_7반_2019_Chair_IN_or_OUT

It detects whether the chair is fully put into the desk or not. This works by using a laser module and it shows us by LED light and speakers

BeginnerFull instructions provided3 hours385
SSHS_CS_7반_2019_Chair_IN_or_OUT

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×2
Laser Diode, 655 nm
Laser Diode, 655 nm
×1
Gravity: Analog Ambient Light Sensor For Arduino
DFRobot Gravity: Analog Ambient Light Sensor For Arduino
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

chair_in_out_laser

C/C++
we use it to figure out whether the chair is tucked inside the table or not by laser. If the chair is tucked in, it blocks the laser, and if the chair is not tucked in, the laser is not blocked, so the sensor absorbs the laser light and a song comes out of the speaker.
#include "Timer.h"

Timer t;

int redled = 11;
int greenled = 10;
int blueled = 9;
int laser = 13;

int note_c4 = 262;
int note_d4 = 294;
int note_e4 = 330;
int note_f4 = 349;
int note_g4 = 392;
int note_a4 = 440;
int note_b4 = 494;
int note_c5 = 523;
int note_d5 = 587;
int note_e5 = 659;

int speakerSensor = 8;
int noteDuration = 500/2;

int TIME=0;

void setColor(int red, int green, int blue);

void setup() {
 Serial.begin(9600);
 pinMode(laser, OUTPUT);
 t.oscillate(laser,1800000,HIGH);

 t.every(100,doTest);

 pinMode(speakerSensor, OUTPUT);
 
 pinMode(redled, OUTPUT);
 pinMode(greenled, OUTPUT);
 pinMode(blueled, OUTPUT); 
 
}


void doTest()
{
  
  int cds = analogRead(A0);
  Serial.println(cds);

  
  if(cds<100)
   {

   TIME++;


   if(TIME>100)
   {
      if(TIME%3==2)
        setColor(0, 255, 255); // aqua
    }

   if(TIME<=100 && TIME>80)
     setColor(255, 0, 0); 

   if(TIME<=80 && TIME>60)
     setColor(230, 0, 0); 

   if(TIME<=60 && TIME>40)
     setColor(190, 0, 0); 

   if(TIME<=40 && TIME>0)
     setColor(150, 0, 0); 
   }


  
if(cds>=100)
{
      TIME=0;
      
      digitalWrite(redled, LOW);
      digitalWrite(greenled, LOW);
      digitalWrite(blueled, LOW);

      digitalWrite(speakerSensor, LOW);
 
    }

}


void sound()
{
  if(TIME>100)
  {
  tone(speakerSensor, note_e4, noteDuration);
  delay(200);
  tone(speakerSensor, note_g4, noteDuration);
  delay(200);
  tone(speakerSensor, note_a4, noteDuration);
  delay(400);
  tone(speakerSensor, note_a4, noteDuration);
  delay(400);
  tone(speakerSensor, note_a4, noteDuration);
  delay(200);
  tone(speakerSensor, note_b4, noteDuration);
  delay(200);
  tone(speakerSensor, note_c5, noteDuration);
  delay(400);
  tone(speakerSensor, note_c5, noteDuration);
  delay(400);
  tone(speakerSensor, note_c5, noteDuration);
  delay(200);
  tone(speakerSensor, note_d5, noteDuration);
  delay(200);
  tone(speakerSensor, note_b4, noteDuration);
  delay(400);
   tone(speakerSensor, note_b4, noteDuration);
  delay(400);
   tone(speakerSensor, note_a4, noteDuration);
  delay(200);
   tone(speakerSensor, note_g4, noteDuration);
  delay(200);
   tone(speakerSensor, note_g4, noteDuration);
  delay(200);
   tone(speakerSensor, note_a4, noteDuration);
  delay(400);

  }
}

void setColor(int red, int green, int blue)
{
  digitalWrite(redled, red);
  //analogWrite(redled, red);
  digitalWrite(greenled, green);
  //analogWrite(greenled, green);
  digitalWrite(blueled, blue); 
  //analogWrite(blueled, blue);
}



void loop() {
   
 t.update();
 sound();
}

Credits

1702 김종은 sshs
1 project • 0 followers
Contact
Yoon so young
1 project • 0 followers
Contact
1712이찬
1 project • 0 followers
Contact
장광재
29 projects • 16 followers
Contact
박다솜
14 projects • 5 followers
Contact
1715최우진
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.