Skip to content

Reading Sensors (The Photo resistor Demo)

jn edited this page Apr 11, 2014 · 13 revisions

Home


Purpose

This experiment will demonstrate how can we use light to control a device using Galileo, sensors and electronic components. It exemplifies how to read analog input in the board as well.

Summary

The photo-resistor is setup along with a 10K resistor used to protect the circuit and to create a voltage divisor. As the amount of light varies on the photo-resistor so does the voltage in this divisor circuit. The output from this circuit will be used by Galileo to monitor the amount if light through A0 analog input.

In order to create variable-intensity light scenario we set up a simple circuit with a potentiometer in parallel to a LED.

Later on, a transistor is used to control a relay. This relay allows us to control a wide variety of devices as motors, lights, etc. as independent circuits. The circuit is based on a NPN transistor which activates the relay as commanded by the pin 8 of the Galileo; based on the lecture we are obtaining from the light sensor.

Finally we will control a RGB led and using the blue light connected to the NC pin in the Relay, this will simulate standby mode. The Green Led is activated when the light sensor overpass the threshold and Galileo activates the relay, this one is connected to NO pin in the Relay. Finally the Red light will be activated with the sensor is overpassing the max allowed value. By using pin 4 Galileo activates this led and deactivates the system.

Pre-requisites

You need:

  1. One PC with USB Ports running either Linux, Windows or Mac OS with Internet Connection

  2. One Intel Galileo Board

  3. One USB to MicroUSB cable

  4. One 5K pontentiometer

  5. One photo-resistor

  6. Four 1K ohm resistor

  7. One RGB Led

  8. One S8050 (NPN transistor)

  9. One LED (White)

  10. Proto-board

  11. Many connection wires

  12. Small box or piece of paper

Procedure

STEP 1: Craft the proto-board circuit as shown in figure 1

Find the Fritzing Diagram here

Demo

STEP 2: Connect the circuit to your Galileo board

STEP 3: Open ARDUINO IDE and code the following sketch:

Important: do not disconnect the USB wire from the PC or Galileo, will be used in another steps. Latest version of the Sketch can be found here

int val = 0;          // This variable will be used to measure the light sensor value. We will use A0 port for this experiment.
int blink_led_dp_13 = 13; // Will indicate when the system will start to run.
int trans_base = 8; // This variable will control the transistor and activate the relay when required.
int relay = 7; 
int warning = 4; // This pin will protect the system from photocell malfunction.

void setup() {
Serial.begin(9600); // Ini
setPinModes();
blinkSignal();
setpin_ini();
}

void loop(){
  val = analogRead(0);// Asigns the sensor value in A0 to the variable.
  Serial.println(val);// Prints the value in the Serial Port

if (val >150 and val <200)  digitalWrite(trans_base, HIGH),digitalWrite (warning, LOW); // If the sensor outcome is higher than 150 and less than 200, then activates the transistor and disable the warning pin. 
  else digitalWrite(trans_base, LOW);

if (val > 200)  digitalWrite(trans_base, HIGH), digitalWrite (warning, HIGH); // If the sensor outcome is higher than 610, then deactivates the transistor and activates the protection using the warning pin. 
  
  }
  
void setPinModes(){
  /*SET PINS AS OUTPUTS */
  pinMode(blink_led_dp_13, OUTPUT);
  pinMode(trans_base, OUTPUT);
  pinMode(relay, OUTPUT);
   pinMode(warning, OUTPUT);
}
void blinkSignal(){
  /*INDICATES ROUTINE START*/
  digitalWrite(blink_led_dp_13, HIGH); delay(100);
  digitalWrite(blink_led_dp_13, LOW); delay(1000);
  digitalWrite(blink_led_dp_13, HIGH); delay(100);
  digitalWrite(blink_led_dp_13, LOW); delay(1000);
  digitalWrite(blink_led_dp_13, HIGH); delay(100);
  digitalWrite(blink_led_dp_13, LOW); delay(1000);  
}
  /*SET PINS INITIAL VALUES */

void setpin_ini() {
  digitalWrite(trans_base, LOW);
  digitalWrite(relay, LOW);
  digitalWrite(warning, LOW);
  
}

STEP 3: Launch the serial monitor

  • From Arduino IDE goto Tools->Serial Monitor.
  • Select the same COM port you used to load the sketch to Arduino.

STEP 4: Operate the Circuit

  • Use the small box or the paper to protect the light sensor from the daylight.
  • Use the potentiometer to activate the device according to the amount of light emited from the LED

Home | Initial Setup