MKR1010 wifi not woring on batteries

I am working with MKR1010, I have connected two heat sensors and created a database to collect the data.
The sketch is working fine and device is getting connected to wifi and posting the data as required.
But this is happening when only connected to USB or a power source. The device is switching ON when connected to batteries but not connecting to WIFI?

Anyone faced this type of issue?

1 Like

That sounds like a hardware problem. Post a schematic of your circuit and how you have it wired, not a frizzy picture. Also include links to technical information on the hardware devices.

If you have while (!Serial); or anything printing to Serial the sketch won't continue on battery power alone because it is waiting for a USB connection. Comment those things out and see if that works.

2 Likes

maybe the cable that connects the batteries to the circuit is not attached ... I say this because it happened to me! ...
otherwise you could disconnect and reattach the batteries once the connection to the PC is removed ...

Thanks for your reply .
I don't have any "While(!Serial) in my code. The code is working fine when it is connected to the power source(phone charger).

I have used 4 batteries to power the MKR and it is working fine for a day. After that, it does not send data.
So, This is because of the power issue.
Even though the MKR required only 3.3v , The WIFI needs a 5V or above to start. So, 4.5V supply is enough for the circuit but not wifi.

I have tried low power mode but it is of no use..

Can anyone suggest to draw the power from batteries for a longer period of time?

1 Like

if the LEDs remain off, if the screen is off ...
if you need the code to disable these things just ask!

1 Like

I am not using any LEDs and screen at present, I attached two temperature sensors and printing the values on serial.

I want to install the device near and hot and cold water tap.It is working fine but batteries are powering the Arduino only for a few hours.

a tip, if you are using the carrier remove it ... ... otherwise the temperature sensor, (if you do not remove the carrier), it is already there and therefore you do not need to connect 2

1 Like

however it is normal that it does not last long, you can only push away the moment when it will go out! otherwise you can use a socket connected to the arduino so that it never runs out!

this simple code will let you know both the voltage (with the penultimate line) and the battery percentage (with the last one). The problem is that it changes based on what is being used ... not sure but I think it takes the carrier...
if you need something just ask!

`float sensorValue = analogRead(ADC_BATTERY);
float battery = sensorValue * (4.3 / 1023.0);
int  batteria_percentuale = round((battery - 3.48) / (4.1 - 3.48) * 100);

I ran into a similar WiFi problem with a MKR1000. The WiFi could connect fine when on USB power, but would not connect on battery power. It turns out it was an issue with the firmware version and the WINC module. I had to downgrade to a previous version; after which, it worked fine. Here's a Q/A on StackOverflow about it:

I doubt the MKR1010 has the exact same issue since it uses a different communication module, but it would be worth investigating.

For your power issues, I'd recommend going into deepsleep mode, and wakeup/reconnect on regular intervals. This is what I've done for a weather sensor I made. I'm using a 5000mA LiPo battery with a 6V, 300ma solar panel for power. It works better than I expected. I set the wakup interval to 3 minutes. Without charging the battery will last ~10 days, and the solar panel has kept it working for 4 months non-stop.

Here's the sketch:

#include <Adafruit_DPS310.h>
#include <ArduinoLowPower.h>
#include <RTCZero.h>
#include <DHT_U.h>
#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUdp.h>
#include "MKR.h"

#define DHTTYPE DHT22

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
char host[] = HOST_NAME;
WiFiUDP udp;
sensors_event_t event;
sensors_event_t tevent, pevent;

float temp = NAN;
float temp2 = NAN;
float hum = NAN;
float pres = NAN;
int vbat = 0;
int vcel = 0;
String msg = "";
int result;
unsigned int port = 2391;
uint32_t sleepDelay = 120000;
//uint32_t sleepDelay = 5000;
int wifiStatus = WL_IDLE_STATUS;
IPAddress endpoint = IPAddress(192, 168, 1, 255);
IPAddress localip;
sensor_t sensor;

DHT_Unified dht(DHTPIN, DHTTYPE);
Adafruit_DPS310 dps;

void setup() {
	WiFi.hostname(host);
	udp.begin(port);
	dht.begin();
	dps.begin_SPI(CS, CLK, MISO, MISI);
	dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
	dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
	delay(10000);
	Serial.println();
	//ConnectToWifi();
}

void loop() {
	//read sensor data
	dht.temperature().getSensor(&sensor);
	dht.humidity().getSensor(&sensor);
	dht.temperature().getEvent(&event);
	temp = (float)(event.temperature * 1.8 + 32.0);
	dht.humidity().getEvent(&event);
	hum = event.relative_humidity;

	while (!dps.pressureAvailable() || !dps.temperatureAvailable())
		delay(10);
	dps.getEvents(&tevent, &pevent);
	temp2 = (float)(tevent.temperature * 1.8 + 32.0);
	pres = pevent.pressure * 0.0295;

	vbat = analogRead(VBAT);
	vcel = analogRead(VCEL);

	msg = "";
	msg = msg + DEVICEID + ";" + temp + ";" + hum + ";" + pres + ";" + temp2 + ";" + vbat + ";" + vcel;
	delay(3000);

	//Broadcast to WiFi
	ConnectToWifi();
	result = udp.beginPacket(endpoint, port);
	udp.print(msg);
	udp.endPacket();
	delay(1000);
	WiFi.end();
	LowPower.deepSleep(sleepDelay);
	awaken();
	delay(1000);
}

void awaken() {
	WiFi.hostname(host);
	udp.begin(port);
}

void ConnectToWifi() {
	wifiStatus = WiFi.status();
	int retrys = 10;
	while (wifiStatus != WL_CONNECTED) {
		wifiStatus = WiFi.begin(ssid, pass);
		delay(1000);
		if (wifiStatus != WL_CONNECTED) {
			retrys--;
			if (retrys < 0)
			{
				retrys = 10;
				delay(3600000);
			}
			delay(9000);
		}
	}
	localip = WiFi.localIP();
	//Serial.print("Connected: ");
	//Serial.println(localip);
}

BTW, disregard the code for reading the battery levels...that part doesn't work when connected to charging power. I'm still trying to figure that part out. Also be aware that when you put the Arduino into deepsleep, it will disable the Serial Monitor. There is a procedure to reinitialize that if you really need it, but I found it to be too much of a hassle (didn't always work) and I didn't need it anyway.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.