this is a small prototype for color sensor, which can detect three colors... this was made by using an LDR,1.5 K resistor and the wiz wiki 7500 board

Dependencies:   mbed

Fork of ADC_test by Simon Blandford

the things you need for this are wiznet board or any other micro controller can do it when you understand the logic i have applied here.An LDR and one resistor for your reference i have used 1.5K resistor in my work.

connect the LDR and resistor in series in between the 3.3V and GND of the board.take outpt from the point where LDR and resistor met.

it's just an voltage divider circuit depends on the color you subject to LDR the resistance of LDR will vary and the volatge also does the same.

then feed the output on the adc pin of micro controller, then you will get various values for various colors. the adc which i have used is 12 bit one that's why it's having 4096 count. you have to change the values in the program according to your adc count.

sorry for my bad english.........

Committer:
shia
Date:
Mon Jan 18 08:28:25 2016 +0000
Revision:
1:c88c8173b9b2
Parent:
0:a2562dfbf543
color sensor using LDR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simonb 0:a2562dfbf543 1 #include "mbed.h"
shia 1:c88c8173b9b2 2 AnalogIn adc(A0);
shia 1:c88c8173b9b2 3 DigitalOut myled1(LED1);
shia 1:c88c8173b9b2 4 DigitalOut myled2(LED2);
shia 1:c88c8173b9b2 5 DigitalOut myled3(LED3);
simonb 0:a2562dfbf543 6
shia 1:c88c8173b9b2 7 int meas;
shia 1:c88c8173b9b2 8 int main()
shia 1:c88c8173b9b2 9 {
simonb 0:a2562dfbf543 10
shia 1:c88c8173b9b2 11 printf("\n GSAS Micro Systems \r\n");
simonb 0:a2562dfbf543 12
shia 1:c88c8173b9b2 13 wait(0.1f);
simonb 0:a2562dfbf543 14
shia 1:c88c8173b9b2 15 while(1)
shia 1:c88c8173b9b2 16 {
shia 1:c88c8173b9b2 17 meas = adc.read_u16();
shia 1:c88c8173b9b2 18 printf("meas is %d\r\n", meas);
shia 1:c88c8173b9b2 19
shia 1:c88c8173b9b2 20
shia 1:c88c8173b9b2 21 if(meas<1000){
shia 1:c88c8173b9b2 22 myled1 = 1;
shia 1:c88c8173b9b2 23 myled2 = 1;
shia 1:c88c8173b9b2 24 myled3 = 0;
shia 1:c88c8173b9b2 25 wait(0.5);}
shia 1:c88c8173b9b2 26 else
shia 1:c88c8173b9b2 27 myled3 = 1;
shia 1:c88c8173b9b2 28
shia 1:c88c8173b9b2 29 if(meas>1000){
shia 1:c88c8173b9b2 30 if(meas<1100){
shia 1:c88c8173b9b2 31 myled1 = 0;
shia 1:c88c8173b9b2 32 myled2 = 1;
shia 1:c88c8173b9b2 33 myled3 = 1;
shia 1:c88c8173b9b2 34 wait(0.5);}
shia 1:c88c8173b9b2 35 else
shia 1:c88c8173b9b2 36 myled1 = 1;}
shia 1:c88c8173b9b2 37 if(meas>1100){
shia 1:c88c8173b9b2 38 myled1 = 1;
shia 1:c88c8173b9b2 39 myled2 = 0;
shia 1:c88c8173b9b2 40 myled3 = 1;
shia 1:c88c8173b9b2 41 wait(0.5);}
shia 1:c88c8173b9b2 42 else
shia 1:c88c8173b9b2 43 myled2 = 1;
shia 1:c88c8173b9b2 44
shia 1:c88c8173b9b2 45
shia 1:c88c8173b9b2 46 wait(0.3); }
simonb 0:a2562dfbf543 47 }
simonb 0:a2562dfbf543 48
shia 1:c88c8173b9b2 49