Hello, I found a lot of useful information on this forum so I hope you can help with this as well.
Thanks In advance.
I'm building a remote weather station that will be sending its data via sms. Following devices are attached to my Arduino:
SIM800l - sending SMS,
I2C OLED - temporay for debugging,
DHT11 - temp and humidity sensor,
BMP180 - atmospheric pressure sensor,
HC-SR04 - ultrasonic distance sensor, I use it to measure snow depth.
All these devices work when connected separately, of I connect all of them but use code that uses only some, but as soon as more than some critical amount is connected Arduino starts outputting blank values, or 0 s instead of actual values.
I thought it was a memory issue, I use String to create text message, I reduced amount of variables and it helped and I have somewhat stable setup that works if I exclude the OLED and create a shorter text message.
But then I tried to recreate it with ESP8266 which has more memory and got the same problems.
I'd appreciate if someone could point me in the right direction! I can share the code if needed.
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Please post your full sketch, using code tags when you do. How is the board powered ?
Thanks for response, this is the code I'm using for Arduino right now.
I'm powering it with 7.2v NiMH battery via VIN and all devices are attached to Arduino 5V.
For ESP8266 I used 18650 battery, SIM800l directly powered by it.
#include <Wire.h>
#include "DHT.h"
#include <afstandssensor.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
DHT dht(7, DHT11);
AfstandsSensor afstandssensor(9, 8); // Starter afstandssensoren på ben 13 og 12.
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
//measure Pressure
#define seaLevelPressure_hPa 1013.25
Adafruit_BMP085 bmp;
const int transistor = 13;
const int resetPin = 12;
void setup() {
delay(10);
digitalWrite(resetPin, HIGH);
pinMode(resetPin, OUTPUT);
pinMode(transistor, OUTPUT);
digitalWrite(transistor, HIGH);
Serial.begin(9600);
Serial.println("transistor high");
delay(15000);
dht.begin();
delay(2000);
dht.readTemperature();
dht.readTemperature();
Serial.println(F("Welcome to YUFU WEATHER STATION"));
delay(5000);
// Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(5000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
}
void loop() {
delay(1000);
Serial.print(String(analogRead(A0) * 0.0147, 2) + F("V\n"));
Serial.print(String(afstandssensor.afstandCM(), 1) + F("cm\n"));
Serial.print(String(dht.readTemperature(), 1) + F("C\n"));
Serial.print(String(dht.readHumidity(), 0) + F("%\n"));
// Serial.print(String(bmp.readPressure(),0) + F("Pa\n"));
Serial.print(bmp.readPressure());
Serial.print(F("Pa\n"));
Serial.println();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+995599140152\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print("Battery: ");
mySerial.print(String(analogRead(A0) * 0.0147, 2) + F("V\nSnow: "));
mySerial.print(String(afstandssensor.afstandCM(), 1) + F("cm\nTemp: "));
mySerial.print(String(dht.readTemperature(), 1) + F("C\nHumid: "));
mySerial.print(String(dht.readHumidity(), 0) + F("%\nPressure: "));
// mySerial.print(String(bmp.readPressure(),0) + F("Pa\n")); //text content
mySerial.print(bmp.readPressure());
mySerial.print(F("Pa\n"));
updateSerial();
mySerial.write(26);
Serial.println();
delay(10000);
Serial.println("transistor low");
digitalWrite(transistor, LOW);
delay(1800000);
Serial.println("resetting");
delay(100);
digitalWrite(resetPin, LOW);
delay(10);
Serial.println("this should not be displayed");
// delay(1800000);
while (1) {}
}
void updateSerial() {
delay(500);
while (Serial.available()) {
mySerial.write(Serial.read()); //Forward what Serial received to Software Serial Port
}
while (mySerial.available()) {
Serial.write(mySerial.read()); //Forward what Software Serial received to Serial Port
}
}
I always love it when a comment doesn't match the code. That code above will ensure that the loop function will only run once and then stop forever. where as your comment suggests it will delay for 30 minutes.
Don't you think that the comment should match what the code is doing? Especially as you are posting it in a public forum, viewed by people who are not mind readers.
So how about:-
// Stop code from sending too many many SMS messages while testing
while (1) {}