Electronic Brick : Sensor

 There are Analog sensor and Digital sensor.
Some Analog sensor as a switch, under some environment it output a ‘on’ signal and the other environment it output a ‘off’ signal.
We take a Mercury tilt switch as an example. When the Mercury tilt switch brick up tilt, it will be on and sent out a high level signal, else it will be off and sent out a low level signal.
Hook up the Mercury tilt switch brick to D9 connector of chassis, and hoop up the LED brick to D8 connector. Then By tilting to different end, it acts On/Off like a switch.

int Mercury_tilt = 9;  //define the 9th digital pin for Mercury tilt switch brick
int Buzzer = 8;     //define the 8th digital pin for LED brick
void setup()
{
  pinMode(Buzzer,OUTPUT); //set the LED pin for digital output
  pinMode(Mercury_tilt,INPUT);  //set the tilt sensor pin for digital input
}
void loop()
{
  if (digitalRead(Mercury_tilt)) // if up tilt
  digitalWrite(Buzzer,HIGH);  // ring the Buzzer
  else                     // if not press
  digitalWrite(Buzzer,LOW);   // turn off the Buzzer
}

Program the code into Arduino, and when the brick up tilt, the buzzer will ring to alarm.

Some Digital sensor didn’t like a switch just to put out high or low level signal in different situation.  They put out an impulse signal when some situation.
As a PIR sensor, when people move throw it, it will sent a high level impulse out. The impulse duration can be change by the resistance on the brick. The longer impulse holds up the easier to check by Arduino.
Hook up the PIR sensor brick to D9 connector of Chassis, and hook up the LED brick to D8.

int PIR = 9;  //define the 9th digital pin for PIR sensor brick
int LED = 8;     //define the 8th digital pin for LED brick
int time=0; // initial the time
void setup()
{
  pinMode(LED,OUTPUT); //set the LED pin for digital output
  pinMode(PIR,INPUT);  //set the tilt sensor pin for digital input
}
void loop()
{
  if (digitalRead(PIR)) // if check people move throw
  {
     time = 10000 ; // set a light time
  }
  if (time>0) // check if need to light the LED
  {
    digitalWrite(LED,HIGH);  // light the LED
    time--;        // decrease light time   
  }
  else
  {
    digitalWrite(LED,LOW);  // turn off the LED
  }
}

Program the code into Arduino, and when somebody passes by PIR sensor, the LED will light for a moment.
More information about the PIR sensor is here:
http://www.seeedstudio.com/depot/pir-motion-sensor-module-p-74.html

The Analog sensor is different from Digital sensor, it output the different level analog signals when in different state. The level of analog signal reflect the reality signal that sensor cached, like light strength, gas density, temperature and so on.

Now we take a Gas sensor for example. First, adjust the Resistor of the Brick to correct the sensor output analog level. When power up the gas sensor will heat and finally be warm, and then we can adjust the resistor to about 5K correct the output analog signal to about 1V.

Hook up the Gas sensor brick to A1 connector of the chassis, and the buzzer to the D8 connector.

int Gassensor = 1;  //define the 1th digital pin for gss sensor brick
int Buzzer = 8;     //define the 8th digital pin for buzzer brick
void setup()
{
  pinMode(Buzzer,OUTPUT); //set the LED pin for digital output
}
void loop()
{
  int val=0;
  val=analogRead(Gassensor); //Read the gas sensor for gas density
  if (val>0x300) // if gas dense
  {
    digitalWrite(Buzzer,HIGH); //  ring the Buzzer for alarm
  } 
  else
  {
    digitalWrite(Buzzer,LOW);  // turn off the buzzer
  }
}

More information about Gas sensor is here:
Program the code into Arduino, and put the gas sensor brick in somewhere need to check gas density. If the gas density exceeds the value that we setup, the buzzer will ring for alarm.

The light sensor is similar to gas sensor, it also output the analog signal by the reality signal: the luminous intensity. We can use the light sensor to control the light source turn on when is lightless and turn off if bright.

Hook up the light sensor brick to A1 connector of chassis, and hook up the LED brick to D8 connector as a light source.

 

int LightSensor = 1;  //define the 1th digital pin for light sensor brick
int LED = 8;     //define the 8th digital pin for LED brick
void setup()
{
  pinMode(LED,OUTPUT); //set the LED pin for digital output
}
void loop()
{
  int val=0;
  val=analogRead(LightSensor); 
  //Read analog level which match the luminous intensity
  if (val<0x200)
  {
    digitalWrite(LED,HIGH); //  turn on the light
  } 
  else
  {
    digitalWrite(LED,LOW);  // turn off the light
  }
}

Program the code into the Arduino, and when the light sensor around is dark the LED will light, but the light sensor around is light enough the LED will off.

You can find more sensor brick here:
http://www.seeedstudio.com/depot/electronic-bricks-c-44.html

Please follow and like us:
Wordpress Social Share Plugin powered by Ultimatelysocial