# Using ESP32 but sensor operating on 5V (external ps)

**URL:** <https://forum.arduino.cc/t/using-esp32-but-sensor-operating-on-5v-external-ps/1234146>\
**Category:** Nano ESP32\
**Created:** [March 11, 2024, 1:34pm UTC](https://forum.arduino.cc/t/using-esp32-but-sensor-operating-on-5v-external-ps/1234146 "2024-03-11T13:34:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cxnvass](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cxnvass/32/1034964_2.png) [@cxnvass](https://forum.arduino.cc/u/cxnvass)\
**Post date:** [March 11, 2024, 1:34pm UTC](https://forum.arduino.cc/t/using-esp32-but-sensor-operating-on-5v-external-ps/1234146/1 "2024-03-11T13:34:21Z")

</div>

So here is an example code

```arduino
void setup() {
  Serial.begin(9600); //Baud rate: 9600
}
void loop() {
  int sensorValue = analogRead(A0);// read the input on analog pin 0:
  float voltage = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  Serial.println(voltage); // print out the value you read:
  delay(500);
}

```

The sensor is operating on 5V, it is powered by an external power supply. But, I am using an ESP32. My question is can I use the code as it is or should I use (3.3 / 4096) instead of (5.0 / 1024.0)?

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 11, 2024, 1:47pm UTC](https://forum.arduino.cc/t/using-esp32-but-sensor-operating-on-5v-external-ps/1234146/2 "2024-03-11T13:47:33Z")

</div>

@cxnvass  
Use analogReadMillivolts()

This function is used to get ADC raw value for a given pin/ADC channel and convert it to calibrated result in millivolts.  
uint32\_t analogReadMilliVolts(uint8\_t pin);  
pin is GPIO pin to read analog value  
This function will return analog value in millivolts (calibrated).

You will need to use a voltage divider on your 5V input. The values for the resistors will depend on the ESP32 module/board you are using.
