Skip to content

Instantly share code, notes, and snippets.

@electricimp
Last active December 19, 2015 00:49
Show Gist options
  • Save electricimp/5871309 to your computer and use it in GitHub Desktop.
Save electricimp/5871309 to your computer and use it in GitHub Desktop.
Code to convert ADC readings to actual Voltage.
function getPin9Voltage()
{
// Returns value in volts, between 0.0 and 3.3
local voltage = hardware.voltage();
local reading = hardware.pin9.read();
return (reading / 65535.0) * voltage;
}
function sample()
{
server.log("The voltage on Pin 9 is:" + getPin9Voltage());
imp.wakeup(1.0, sample);
}
// Set up imp Pin 9 as an analog input
hardware.pin9.configure(ANALOG_IN);
// Start sampling the voltage on Pin 9
sample();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment