Pulse Width Modulation

Hi there!

I'd need some help to modulate the raw signal given by a photodiode when light is shone onto it. i don't really know how to implement the PWM in order to convert the raw data.

The code I use for signal retrieval is:

#define inPin0 A0

void setup(void) {
    Serial.begin(9600);
    Serial.println();
     
}

void loop(void) {
  int pinRead0 = analogRead(inPin0);
  float pVolt0 = pinRead0 / 1024.0 * 5.0;
  Serial.print(pVolt0);
  Serial.println();
   
  delay(100);

}

Many thanks in advance!
r

Who gave you the idea to have the code in that hard-to-read yellow?

(Code tags added, changed to easier to read color - Moderator.)

What PWM?

Mark

Try this:

void loop(void) {
  int pinRead0 = analogRead(inPin0);
  analogWrite (pwmPin, pinRead0 >>2); // PWM output
  float pVolt0 = pinRead0 / 1024.0 * 5.0;
  Serial.print(pVolt0);
  Serial.println();
   
  delay(100);

}

define/declare pwmPin as needed - 3,5,6,9,10 or 11

I still get a few errors, but I'll try to fix them. I have never used an Arduino before, so Im on unknown grounds here.

But you're saying that using this code alone, I should read the modulated signal given by the photodiodes?

Thanks!
r

Why is the signal from the photodiode modulated? Please provide a schematic in order to make it clear.

The signal from the photodiode is not modulated; that is what Im trying to obtain.
Below I attach the fritzing diagram of the circuit I use, the spectrum of the photodiode as shown in its datasheet and the spectrum I read with the arduino.

JEC1-4ALT.4.e.pdf (398 KB)

ried88:
the fritzing diagram mess

Fixed it :wink: A REAL circuit diagram is so much easier to understand... Most of us are not going to decipher a Fritzing mess by looking up pinouts an stuff...

r

Screen Shot 2017-05-31 at 5.38.10 PM.png

The signal from the photodiode is not modulated; that is what Im trying to obtain.

The JEC 1-4ALT appears to be a receiver. What is it receiving? Is the source modulated?

it receives UV from a deuterium-halogen light source

I don't understand how you would like to modulate the received signal? It will respond to the source illumination. Is the source modulated?

Can you explain a bit more about what you are trying to achieve.

IF you use the output level of the light detector as an input to the PWM (duty cycle) that is modulation :slight_smile:

A photodiode is basically a variable resistor, yes?

You would put the diode in series with a resistor of a known value. This would be put across 5v/ground, and you'd take a tap from the center to an analog input pin. This will give you a value between 0 and 1023. You'd do a little math to work out how the sensed voltage will vary with the restistance of the diode.

You'd then stuff this value into a PWM pin:

const float R = 1000; // using a series 1k resistor between 5v and the diode
const float diodeMax = 10000; // 10K ?
void loop() {
  float v = analogRead(A0);
  float r = (v * R) / (1024-v); // I think

  analogOut(3, r / diodeMax * 256);
}

PaulMurrayCbr:
A photodiode is basically a variable resistor, yes?

Nope, it's not. It's a light dependent current source :slight_smile:

septillion:
Nope, it's not. It's a light dependent current source :slight_smile:

Oh. Too much electronics for me, then. :slight_smile:

Are you using the photodiode in forward or reverse biased mode? :wink: