> > What 's the best way to make a sunshine detector? Best is always subject to debate and seriously depends on the criteria. > > The purpose of this detector is to control (via a PIC of course) > electrically actuated sun screens in front of a window of my house. > > First question is: would I need two photo sensors (one "looking" to the > sun, one looking in the other direction, so a differential measurement > can be made)? Or would one sensor suffice (by measuring the absolute > level of brightness)? Depends on the application. And "looking to the sun" is a completely different and more difficult activity. Essentially that's tracking. Best guess is to start with absolute, see if it meets your needs, if not then examine other strategies. > > Second question: would a sensor in the visible light range be the best > choice, or UV (or perhaps even IR)? Mine was visible light. I needed to control my outdoor lights. > > I'm considering to do a first test with a TSL230 (Texas Instruments). > This device outputs a frequency proportional to the irradiance (visible > light), so interfacing to a PIC is straight forward. Well before you do that you may want to make a $5 electronics run and test the real simple detector I put together. It consists of a 555 timer, a CDR light sensitive resistor, and a handful of components. Essentially it does the same as the TSL230, though not nearly as linear. In short hook up the 555 in astable multivibrator mode with the CDR as R1 (the top resistor connected between pins 7 and 8. The the frequency of the 555 will depend on the amount of light shining on the CDR, the brighter it gets, the faster it vibrates. BTW I found it useful to parallel the CDR with a fixed resistor so that the slowest frequency can be capped. BTW while I've never done it, this 555 action should be easily duplicated using a couple of PIC pins. Consider. B0-------CDR-------+--R1--CAP------GND | B1 The following steps should get a proportional reading. 1) Make B1 an output and ground, discharging the cap. Make sure that R1 is at least 20 ohms to limit the current through the PIC I/O pin. 2) Make B1 an input and B0 an output set to 5V. The cap will charge through the CDR and R1 and will eventually register as a 1 on B1's input. The length of time that it takes B1 to go from a 0 to a 1 is proportional to the current resistance of the CDR which is coupled to the amount of light shining on the CDR. Again you may want to parallel a somewhat high value resistor with the CDR so that complete darkness doesn't take forever. BTW has anyone had good luck with circuits like this? With both of these techniques you will want to have hysteresis averaging a bunch of samples and delaying a while after performing an action. I checked for 20 seconds of consecutive light or dark readings with a mix causing no action. Just reviewing my code (now two years old) I don't see the timeout after switching for light and dark, just resetting the 20 second counts for both light and dark. It worked fine until my relay blew. I'm in the process of switching to a time based system. Hope this gives some insight into the process. I advise starting with the simplest scenario, hardware, and software, and only refine it when it doesn't meet your needs. BAJ -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.