Skip to content

Commit

Permalink
Merge pull request #144 from LaCoolCo/enhancement/Battery-ADC
Browse files Browse the repository at this point in the history
Fix battery voltage measurement
  • Loading branch information
3rwww1 authored Jun 22, 2018
2 parents 824e8a7 + 9fe529a commit dc8011d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/CoolBoardSensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ bool CoolBoardSensors::config() {
config.set<bool>(json["SI114X"], "ir", this->lightDataActive.ir);
config.set<bool>(json["SI114X"], "uv", this->lightDataActive.uv);
config.set<bool>(json, "vbat", this->vbatActive);
config.set<bool>(json, "vbat", this->vbatActive);
config.set<bool>(json, "soilMoisture", this->soilMoistureActive);
config.set<bool>(json, "wallMoisture", this->wallMoistureActive);
DEBUG_LOG("Builtin sensors configuration loaded");
Expand Down Expand Up @@ -191,11 +190,10 @@ float CoolBoardSensors::readVBat() {

// read battery voltage
int raw = analogRead(A0);
// convert it to approx. correct tension in volts
float val = 6.04 / 1024 * raw;

DEBUG_VAR("Battery voltage:", val);
return (val);
float voltage = (raw * MAX_BATTERY_VOLTAGE) / ADC_MAX_VAL;
DEBUG_VAR("Raw value:", raw);
DEBUG_VAR("Battery voltage:", voltage);
return (voltage);
}

float CoolBoardSensors::readSoilMoisture() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/CoolBoardSensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define MOISTURE_SENSOR_PIN 13
#define ANALOG_MULTIPLEXER_PIN 12
#define ADC_MAX_VAL 1023.
#define MAX_BATTERY_VOLTAGE 5.6

class CoolBoardSensors {

Expand Down

0 comments on commit dc8011d

Please sign in to comment.