photocells get light intensity

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
Bestinbest
Posts: 4
Joined: Thu Nov 18, 2021 10:58 am

photocells get light intensity

Post by Bestinbest » Thu Nov 18, 2021 11:12 am

Hello everyone,

I work on a school project, and I need to get the light intensity with a photocell. Do you have any link or tips to help us get started ? I already have the raspberry pi and I know how to paste a code to the pico.
However I didn't find the information I needed on the official pdf. I am using micorpyhton, but I am not opposed to switch to C even though I know very little about it.

Thanks for replying.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: photocells get light intensity

Post by OlivierLenoir » Thu Nov 18, 2021 5:40 pm

Are you looking for something like that?
SolarTracker_schem.png
SolarTracker_schem.png (81.93 KiB) Viewed 8357 times
SolarTracker_bb.png
SolarTracker_bb.png (256.16 KiB) Viewed 8357 times
Last edited by OlivierLenoir on Fri Nov 19, 2021 3:56 pm, edited 1 time in total.

Bestinbest
Posts: 4
Joined: Thu Nov 18, 2021 10:58 am

Re: photocells get light intensity

Post by Bestinbest » Fri Nov 19, 2021 7:51 am

Yes thanks, but how do I get the photocell's resistance ? Can the pico get the current so I can use Ohm's law ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: photocells get light intensity

Post by Roberthh » Fri Nov 19, 2021 8:03 am

The pico can measure the voltage, and from that and the known value of the other resistor you can determine the value of the light cell.

Bestinbest
Posts: 4
Joined: Thu Nov 18, 2021 10:58 am

Re: photocells get light intensity

Post by Bestinbest » Fri Nov 19, 2021 8:23 am

Thanks a lot, I'll try this as soon as I can.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: photocells get light intensity

Post by OlivierLenoir » Fri Nov 19, 2021 4:00 pm

Based on proposed schematic, you can read photocells with this code.

Code: Select all

from machine import Pin, ADC

# Set sensors
sensor_a = ADC(Pin(26))  # ADC0
sensor_b = ADC(Pin(27))  # ADC1
sensor_c = ADC(Pin(28))  # ADC2

# Read sensors
# read value, 0-65535 across voltage range 0.0v - 3.3v
sensor_a.read_u16()
sensor_b.read_u16()
sensor_c.read_u16()

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: photocells get light intensity

Post by OlivierLenoir » Fri Nov 19, 2021 4:28 pm

An other approach, would consist of using an LED as a light sensor, amplified by a transistor.
SolarTrackerLEDSensor_schem.png
SolarTrackerLEDSensor_schem.png (104.45 KiB) Viewed 8354 times

Bestinbest
Posts: 4
Joined: Thu Nov 18, 2021 10:58 am

Re: photocells get light intensity

Post by Bestinbest » Thu Nov 25, 2021 10:18 am

Thanks, you saved us much time x)
Last question, I want to apply Millman to get R1 for example, is the current running in this direction ?
And is the current coming from 31 negligible ?
Attachments
SolarTracker_schema_courant.png
SolarTracker_schema_courant.png (94.59 KiB) Viewed 8234 times

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: photocells get light intensity

Post by OlivierLenoir » Thu Nov 25, 2021 4:41 pm

You can consider GP26_A0 as an high impedance, so current iGP26_A0 can be considered as 0A.
Current iR1 = iR2. As R1 depend on light, i = 3.3V / (R1 + R2), so i is not constant.

Example with different value for R2
CurrentR1-R2.png
CurrentR1-R2.png (25.81 KiB) Viewed 8220 times

Post Reply