hello i am using a esp32s2 to read the frequency of a string of a guitar using a…
- User
hello i am using a esp32s2 to read the frequency of a string of a guitar using a infrared led and phototransistor combo. i am using arduinofft library to convert what is comming in the esp32s2 analog pin to frequency's. Now i am running into a few problems. i somehow need to invert what the phototransistor outputs.. I have the emiter at gnd and the collector via a resistor to 3.3v. and collector going to gpio analog pin 5 for reading. The problem is is that the infrared light shines on the string when it is not strung. meaning that it reads 5v when i shine at the string. Is there another configuration of the phototransistor so that it outputs 0v when it reasives full ir light from the ir led. and when it recieves (almost) no ir light from the led it outpus 5v.. essentially inverting its operation from how it operates now.
- Assistant
To invert the output of your phototransistor circuit, you can change the configuration of how it's connected. Currently, you have an emitter-follower setup, where the emitter is connected to GND and the collector is pulled up to 3.3V through a resistor. This configuration causes the voltage at the collector to drop when the phototransistor conducts (when IR light is present).
To invert the signal, you want the output to be high when there’s no IR light and low when IR light is present. Here’s how you can modify your circuit:
- Switch the positions of the collector and emitter:
- Connect the emitter of the phototransistor to 3.3V.
- Connect the collector of the phototransistor to the resistor.
- Connect the other end of the resistor to GND.
- Connect the collector (node between the phototransistor and the resistor) to the GPIO analog pin.
Here's how the circuit will look:
3.3V | | o | (/) Phototransistor | C | +---- GPIO Analog Pin | R (Resistor) | GNDIn this configuration:
- When the phototransistor receives IR light, it conducts, pulling the voltage at the collector node (and thus the GPIO analog pin) low (towards GND).
- When the phototransistor does not receive IR light, it does not conduct, and the voltage at the collector node (and thus the GPIO analog pin) is pulled high by the resistor (towards 3.3V).
This inversion will give you a high voltage (close to 3.3V) when there is no IR light, and a low voltage (close to 0V) when there is IR light.
Additionally, make sure that your resistor is appropriately valued to balance sensitivity and response time. A common starting point is a 10kΩ resistor, but you might need to adjust it depending on your specific components and requirements.
By reconfiguring your circuit in this way, you will effectively invert the output of the phototransistor to match your desired behavior.
- Switch the positions of the collector and emitter: