Maple Lesson 10 - Light indicator"

From Microduino Wiki
Jump to: navigation, search

Objective

In photoresistance experiment, the light is divided into two levels, strong or weak. This experiment will finish a light indictor using 4 LEDs and divides the light into 5 levels. Photoresistance receives the lighter, and light up more LED to achieve the purpose of instruction.

Equipment

Microduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.

  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • Photoresistance one
    • LED Light-emitting diodes four
    • 220Ω four
    • 10k resistor one
    • USB Data cable one

Schematic

The photoresistance's connection in contrast to the last time, the purpose is let you know the usage of photoresistance deeply. photoresistance directly connects to the power supply at one end, the other end through a resistance to connect GND . The initial state is low and with the increase of light intensity voltage is higher and higher.

Program

const int analogInPin = 14;
const int ledPin = 4;

float sensorValue = 0;        // value read from the pot

int xl=4000; //This is the basic environmental brightness variables, please check your own brightness values, fill out here is slightly greater than the measured value of the data but the data is less than the light

void setup() {
  pinMode(analogInPin, INPUT);
  for(int i=3; i<=6;i++)          //Set the I/O port 2 - 5 to output mode.
  {
    pinMode(i,OUTPUT);
  }
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  
if (sensorValue>=1000)             
  {
    digitalWrite(3,HIGH);
    digitalWrite(3,LOW);
  }
  if(sensorValue>1500)
   {
    digitalWrite(4,HIGH);
    digitalWrite(4,LOW);
  }
    if(sensorValue>2000)
   {
     digitalWrite(5,HIGH);
     digitalWrite(5,LOW);
  }
    if(sensorValue>2500)
   {
     digitalWrite(6,HIGH);
     digitalWrite(6,LOW);
  }
  
  SerialUSB.print("sensorValue = ");
  SerialUSB.println(sensorValue);
  delay(500);
}

Result

When the light is very weak, lower the set minimum value, all the lights are off. With the increase of light, reach to a set level would light up an LED, to achieve the effect of instruction. Actually LED lamp has been flashing, because in order to make the light intensity is not a certain level, to put out the light of the level, directly after the lights out immediately, with no delay in the implementation process, as long as the grade, circulation processing, so it looks as if always on.