Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created October 22, 2023 04:25
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 kakopappa/7d45a826ba02203ab8571b735add45c9 to your computer and use it in GitHub Desktop.
Save kakopappa/7d45a826ba02203ab8571b735add45c9 to your computer and use it in GitHub Desktop.
#if defined(ESP8266)
const int sPin = A0;
const int vccPin = D2;
#elif defined(ESP32)
const int sPin = 34;
const int vccPin = 17;
#elif defined(ARDUINO_ARCH_RP2040)
const int sPin = 26;
const int vccPin = 6;
#endif
void setup() {
Serial.begin(9600);
pinMode(sPin, INPUT);
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, LOW); // turn off the sensor at the begining.
}
void loop() {
digitalWrite(vccPin, HIGH); // turn on the power for sensor.
delay(100); // wait 100ms
int value = analogRead(SIGNAL_PIN); // make a reading from sensor
digitalWrite(POWER_PIN, LOW); // turn off the sensor
Serial.printf("value: %d\n", value); // print reading
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment