Use to WIZwiki-W7500. Sensing to CDS.
Dependencies: mbed
Fork of CDS_Sensor_WizWiki-W7500 by
Prerequisite
This example is for controlling LED with CDS sensor. CDS or Photoresistor(or light-dependent resistor, LDR) is a light controlled variable resistor. The resister of a photoresistor decreases with increasing incident light intensity. CDS can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
- CDS Sensor
Hardware Configuration
WIZwiki-W7500 Pin map
CDS Sensor
https://developer.mbed.org/users/4180_1/notebook/using-a-photocell-to-determine-light-levels/
Wiring
ADC for CDS Sensor
6ch ADC on WIZwiki-W7500 is able to read from CDS Sensor are A0, A1, A2, A3,A4 and A5.
3 color LED on WIZwiki-W7500 is able to display the condition of CDS value are LED1, LED2 and LED3.
Software
Read CDS value
//Declaration ADC, GPIO Pin DigitalOut myled(LED1); // For Debug LED AnalogIn CDS(A0); // ADC pin for CDS CDS_data = CDS.read()*1000; // .read() is function to read ADC value CDS_vol = CDS.read()*3.3; // *3.3 is for voltage range
Control LED with CDS value
if(CDS_data < 600){ myled = 1; // Light-activated } //Status is dark. else { myled = 0; // Dark-activated }
Caution
Basically WIZwiki-W7500 can be debug with USB cable. So User need to install mbed serial driver and set serial communication baud-rate 9600bps
main.cpp@0:f6d98a2fee3b, 2015-06-29 (annotated)
- Committer:
- nanjsk
- Date:
- Mon Jun 29 05:20:10 2015 +0000
- Revision:
- 0:f6d98a2fee3b
- Child:
- 1:19ab27910302
use to WIZwiki-W7500. Sensing to CDS.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nanjsk | 0:f6d98a2fee3b | 1 | #include "mbed.h" |
nanjsk | 0:f6d98a2fee3b | 2 | |
nanjsk | 0:f6d98a2fee3b | 3 | DigitalOut myled(LED1); |
nanjsk | 0:f6d98a2fee3b | 4 | AnalogIn CDS(A0); |
nanjsk | 0:f6d98a2fee3b | 5 | |
nanjsk | 0:f6d98a2fee3b | 6 | Serial pc(USBTX, USBRX); |
nanjsk | 0:f6d98a2fee3b | 7 | |
nanjsk | 0:f6d98a2fee3b | 8 | int main() { |
nanjsk | 0:f6d98a2fee3b | 9 | pc.baud(115200); |
nanjsk | 0:f6d98a2fee3b | 10 | wait(0.5f); |
nanjsk | 0:f6d98a2fee3b | 11 | pc.printf("Hello WizWIki-W7500!\n\r"); |
nanjsk | 0:f6d98a2fee3b | 12 | pc.printf("===========================================\n\r"); |
nanjsk | 0:f6d98a2fee3b | 13 | int CDS_data = 0; |
nanjsk | 0:f6d98a2fee3b | 14 | double CDS_vol = 0; |
nanjsk | 0:f6d98a2fee3b | 15 | while(1) { |
nanjsk | 0:f6d98a2fee3b | 16 | CDS_data = CDS.read()*1000; |
nanjsk | 0:f6d98a2fee3b | 17 | CDS_vol = CDS.read()*3.3; |
nanjsk | 0:f6d98a2fee3b | 18 | //CDS Seneor ADC Low Data |
nanjsk | 0:f6d98a2fee3b | 19 | pc.printf("CDS Data : %3d\r\n",CDS_data); |
nanjsk | 0:f6d98a2fee3b | 20 | //CDS Sensor Voltage data |
nanjsk | 0:f6d98a2fee3b | 21 | pc.printf("CDS Voltage : %3.3lfV\r\n",CDS_vol); |
nanjsk | 0:f6d98a2fee3b | 22 | pc.printf("===========================================\n\r"); |
nanjsk | 0:f6d98a2fee3b | 23 | wait(1); |
nanjsk | 0:f6d98a2fee3b | 24 | //Status is bright. |
nanjsk | 0:f6d98a2fee3b | 25 | if(CDS_data < 600){ |
nanjsk | 0:f6d98a2fee3b | 26 | myled = 1; |
nanjsk | 0:f6d98a2fee3b | 27 | } |
nanjsk | 0:f6d98a2fee3b | 28 | //Status is dark. |
nanjsk | 0:f6d98a2fee3b | 29 | else { |
nanjsk | 0:f6d98a2fee3b | 30 | myled = 0; |
nanjsk | 0:f6d98a2fee3b | 31 | } |
nanjsk | 0:f6d98a2fee3b | 32 | } |
nanjsk | 0:f6d98a2fee3b | 33 | } |