Use to WIZwiki-W7500. Sensing to CDS.

Dependencies:   mbed

Fork of CDS_Sensor_WizWiki-W7500 by Scott Jeong

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

pin map

CDS Sensor

https://developer.mbed.org/users/4180_1/notebook/using-a-photocell-to-determine-light-levels/

Wiring

/media/uploads/joon874/cds_hw_wiring.png

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

Committer:
joon874
Date:
Mon Apr 03 00:24:25 2017 +0000
Revision:
1:19ab27910302
Parent:
0:f6d98a2fee3b
Delete UART declaration.

Who changed what in which revision?

UserRevisionLine numberNew 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 int main() {
joon874 1:19ab27910302 7
joon874 1:19ab27910302 8 wait(0.5);
joon874 1:19ab27910302 9 printf("Hello WizWIki-W7500!\n\r");
joon874 1:19ab27910302 10 printf("===========================================\n\r");
joon874 1:19ab27910302 11
nanjsk 0:f6d98a2fee3b 12 int CDS_data = 0;
nanjsk 0:f6d98a2fee3b 13 double CDS_vol = 0;
joon874 1:19ab27910302 14
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
joon874 1:19ab27910302 19 printf("CDS Data : %3d\r\n",CDS_data);
nanjsk 0:f6d98a2fee3b 20 //CDS Sensor Voltage data
joon874 1:19ab27910302 21 printf("CDS Voltage : %3.3lfV\r\n",CDS_vol);
joon874 1:19ab27910302 22 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 }