Windows on Device project practice 2, ondevice

Source: Internet
Author: User

Windows on Device project practice 2, ondevice

In the previous article "Windows on Device Project Practice 1-PWM bulb lamp production", we learned how to design and complete a PWM bulb by using Intel Galileo Development Board and Windows on Device. In this case, we need to manually adjust the potentiometer and control the brightness of the LED lamp through the PWM waveform. In the current smart home system design, many devices need intelligence, that is, they can automatically serve us without human intervention.

In this project, we will use the photosensitive resistor to design and create a high light. The light source can automatically adjust the brightness of the LED light according to the ambient light intensity.

 

1. photosensitive resistance

Photovaristor, also known as light resistance, is a type of resistance made by the photoelectric effect of semiconductors. Its resistance value changes with the strength of the incident light: the incident light is strong, the resistance decreases, and the incident light is weak, increase the resistance. Photosensitive resistors are generally used for light measurement, light control, and photoelectric conversion (converting light changes to electrical changes ). Photosensitive resistors can be widely used in various optical control circuits, such as lighting control and adjustment, and can also be used for optical control switches.

 

2. Component and hardware connection

Components required for this practical project include:

  • Photosensitive resistance * 1
  • Direct LED * 1
  • 10 KB Ω direct insertion resistance * 1
  • 220 Ω direct insertion resistance * 1
  • Bread * 1
  • Bread board jumper

In this production, the photosensitive resistance is a component that can change the resistance value according to the light intensity. Naturally, the Galileo analog port is required to read the analog value. Therefore, we can refer to the PWM interface experiment, change the potentiometer to a photosensitive resistor to control the brightness of the LED light when the light intensity is different. The schematic diagram and hardware diagram of the connection are as follows:

 

 

3. source code parsing

In the following source code, we divide the return value of the simulated port read by 4 because the return value range of the simulated input analogRead () function is 0 to 1023, and the simulated output analogWrite () the output value range of the function is 0 to 255.

// Main. cpp: Defines the entry point for the console application.
//

# Include "stdafx. h"
# Include "arduino. h"

Int _ tmain (int argc, _ TCHAR * argv [])
{
Return RunArduinoSketch ();
}

Int potpin = 0; // define analog interface 0 connection photosensitive resistance
Int ledpin = 11; // defines the digital interface 11 output PWM to adjust the LED brightness
Int val = 0; // defines the variable val
Void setup ()
{
PinMode (ledpin, OUTPUT); // defines the digital interface 11 as the OUTPUT
}
Void loop ()
{
Val = analogRead (potpin); // read the simulated value of the sensor and assign it to val
Log (L "val: % d \ r \ n", val); // display the val variable value
AnalogWrite (ledpin, val/4); // turn on the LED and set the brightness (maximum PWM output value: 255)
Delay (10); // delay: 0.01 seconds
}

4. debugging results

Start Galileo, use TelNet to establish a connection, and then click debug. The program will be downloaded to Galileo through the network port. The photosensitive resistance changes with the light intensity. After partial pressure, the value read from the analog port 0 also changes. We can try to use hands to block the photosensitive resistance, so that its resistance changes, so as to achieve the purpose of debugging.

Debugging video links as follows, you can see the effect of the Light: http://v.youku.com/v_show/id_XODU2Mjk1ODYw.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.