Skip to content

Instantly share code, notes, and snippets.

@IsmailSan
Created September 11, 2019 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsmailSan/582e4fc6acd1178144ab4cb3f71266fd to your computer and use it in GitHub Desktop.
Save IsmailSan/582e4fc6acd1178144ab4cb3f71266fd to your computer and use it in GitHub Desktop.
//Phototransistor terhubung pada GPIO 36 di board ESPectro32
int photoPin = 36;
float potValue = 0;
float potVoltage = 0;
void setup() {
Serial.begin(9600);
delay(500);
}
void loop() {
//Membaca nilai phototransistor
potValue = analogRead(photoPin);
//mengkonversi nilai raw data (0 - 4095) ke tegangan (0.0V - 3.3V):
potVoltage = potValue * (3.3 / 4095.0);
Serial.print("Photo Transistor Value :");
Serial.println(potValue);
Serial.print("Photo Transistor Voltage :");
Serial.println(potVoltage);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment