I would like to leave the "scale" I made the other day outdoors for a few days to check the fluctuations in the readings. Therefore, I improved the system to send measurement data to Ambient once a minute, and also to run on battery power.
Click here to see the previous article.
Ambient
It is a free cloud service that allows us to visualize and display those data by continuously uploading your measurement results.
I have used this service for bed sensors in the past, and it was very easy to use, so I would like to use this service again this time. For more information on how to use Ambient, please click here.
Program
I will improve the program to measure the weight, send it to Ambient, and DeepSleep for one minute. Since it will be running on battery this time, I decided to measure the battery voltage as well and send it to Ambient along with the weight.
This is part of the program.
//Scale #include "HX711.h" HX711 scale; const int DT_PIN = 32; const int SCK_PIN = 33; const int SW_PIN = 0; const int LED_PIN = 23; long offset = 417190; long scaleFactor = 321; double baseWeight = 200.0; #include Preferences ScaleParam; //DeepSleep #include #include "esp_deep_sleep.h" #include "soc/rtc_cntl_reg.h" //WiFi #include const char* WifiSSID = "SSID"; const char* WifiPassword = "PASSWORD"; //Ambient #include "Ambient.h" const unsigned int WriteChannelId = WRITE_CHANNEL_ID; const char* writeKey = "WRITE_KEY"; WiFiClient wifiClient; Ambient ambient; //AD const int BATT_AD_PIN = 36; const double aDVoltageGain = 0.00079365 * 2.0; const double aDVoltageOffset = 0.13; void setup() { Serial.begin(115200); Serial.println("start"); scale.begin(DT_PIN, SCK_PIN); pinMode(SW_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); //Show Reset Reason Serial.print("CPU0 reset reason:"); verbose_print_reset_reason(rtc_get_reset_reason(0)); //read scale parameter for from preferences readScaleParameter(); //Enable scaleSetup except for Wakeup if ( rtc_get_reset_reason(0) != 5 ) scaleSetup(); //Measurment Weight long value = scale.get_units(5); double weight = (double)(value) * 0.1; Serial.printf("%.1f[g] ", weight ); //Measurment Batt Voltage int battAD = analogRead(BATT_AD_PIN); double battVoltage = battAD * aDVoltageGain + aDVoltageOffset; Serial.printf("%.2f[V]\n", battVoltage ); //Connect WiFI if ( connectWiFi() == true ) { //Initialize Ambient ambient.begin(WriteChannelId, writeKey, &wifiClient); //Write to Ambient writeToAmbient( weight , battVoltage); } //Prepare to sleep scale.power_down(); WiFi.disconnect(); WiFi.mode(WIFI_OFF); Serial.printf("zzz...\n"); deepSleep(60); }
The entire program can be downloaded here.
Change lines 20 and 21 to the SSID and password of your home wireless LAN, and change lines 26 and 27 to Ambient's light channel ID and light key that you obtained yourself.
Here's the program flow in a nutshell
- Read the strain gage parameters (offset and conversion factor to weight) from the preferences (non-volatile storage) and make the initial settings for the instrument.
- When returning from DeepSleep, pass the mode to measure the parameters of the strain gauge
- Measure weight and battery voltage
- Try to connect to WiFi, and send the measurement results to Ambient when WiFi connection is established
- Put the HX711 into sleep mode and enter DeepSleep for one minute
Press the Boot button immediately after pressing the Reset button to enter the mode to measure the parameters of the strain gage. If you release the Boot button after about 2 seconds, it will enter the offset measurement mode, and if you hold it down for more than 6 seconds and release it, it will enter the mode to measure the conversion factor to weight. The measurement results are recorded in the preference and will not disappear even after resetting. Do not place anything on the scale when measuring offset. When in the mode of measuring the conversion factor to weight, place a 200g object on the scale beforehand.
Modify the circuit
Adding functionality
Add functions to the circuit as shown above.
- Connect four AA rechargeable batteries (eneloop) to 5V and GND
- Divide the voltage between 5V and GND with a 1MΩ resistor, and connect half of the battery voltage to AD0 (IO36)
- Connect an LED to IO23 as an indicator of the mode in which the strain gauge parameters are measured
I used DuPont Connector pins and housings to turn ordinary wires and battery box wires into pins that would stick into the breadboard.
This is then crimped onto the wires using a crimping tool.
These parts and tools are very useful because you can make any number of pins to stick into the breadboard.
Improvement of scales
To prevent noise from entering the system, I shortened the wiring from the strain gage to the HX711 and lengthened the wiring for the digital signal to the ESP32. Since there are four wires for digital signals, I cut and used a USB cable that also has four wires in it.
The circuit modification is now complete.
Place in a case
Put it in a case to make it waterproof. This storage container from a 100 yen store was just the right size.
Put in the breadboard and battery box.
Put the lid on and you're done.
The experimental apparatus for weighing has been completed.
Set up outdoor
For now, I set it up under the eaves where there is shelter from the rain.
Here is the result after leaving it for two hours. The blue line represents the weight, and the red is the battery voltage. Since there is nothing on the scale, it is correct that the blue line should be 0g, but the weight is getting more and more negative. Since it was placed in an environment exposed to the sun, the temperature may have risen and deformed the strain gauge.
I'd like to leave it for a few days and record the change in weight.