Problems with Teensy 4.1 with Photoresistor

jgangano

Member
Hello,

I am testing the capability of a Teensy 4.1 using a photoresistor. I was googling some tutorials on how to do this an I came across this one. The only thing I changed for the most part was the code so that I could the voltage and also the luminosity of the photoresistor.

Code:
int photoPin = A9;

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

void loop() {
  int light = analogRead(photoPin);

  float voltage = light * (5.0 / 1023);
  float luminosity= light * (100/ 1023.0);

  Serial.println("volt: ");
  Serial.print(voltage, 3);
  Serial.println(" V \n\r");

  Serial.print("Luminosity: ");
  Serial.print(luminosity, 3); // Print with 3 decimal pl,aces for accuracy
  Serial.println(" % \n\r");
  delay(100);
 
}

On the Serial monitor I'm getting around 2.8V, and around 59% luminosity. However, when I try to measure the voltage from the photoresistor to ground I get around 1.8V. I'm trying to get it so that the voltage of my photoresistor is the same as the one on my serial monitor, but I'm confused on how to move on.
 
I guess you should change this line
Code:
float voltage = light * (5.0 / 1023);
to something like this
Code:
float voltage = light * (3.3 / 1023);
 
I guess you should change this line
Code:
float voltage = light * (5.0 / 1023);
to something like this
Code:
float voltage = light * (3.3 / 1023);
Hello,

Thanks for your reply. The reason why I have it set to 5.0 and not 3.3 is because the reference voltage I am using is the 5.0 Volt one.
 
On Teensy 4.0 the ADC always uses the 3.3V power as its reference. That's hard-wired inside the chip (why NXP did this I can not say) so you always get 3.3V reference no matter what you do in software.
 
Back
Top