D
D
Dona Balkanska2016-10-18 00:41:57
Arduino
Dona Balkanska, 2016-10-18 00:41:57

Arduino question (sketch errors)?

Arduino Uno, SIM800L, DHT11, Ethernet shield- for monitoring temperature and outside the limit for sending SMS. My sketch did not work, where is the mistake?
64064a13d4134cf39b01e94ad5ff0670.png
-----------
Here:
#include SoftwareSerial.h
#include String.h
#include EEPROM.h
#include Wire.h
#include SPI.h
#include Ethernet.h
#include dht.h
// pins definition
SoftwareSerial sim800l(7, 6); // actual RX, TX pins of SIM800l board
const int TestButton = 10; // internal pull-up activated, button is wired to GND, LOW when pressed
const int LEDPowerFailure = 9;
const int LEDTemperatureFailure = 4;
const int LEDLANFailure = 11;
const int LEDDiagnostics = 13; // internal LED for diagnostics
const int PowerSenseInput= A1; // from DC adapter via a voltage divider
const int DHT11Pin = 12; // DHT11 onewire pin
// failure definitions constants - bitwise
const int StateOk = 0;
const int StatePowerDownFailure = 1;
const int StateLANFailure = 2;
const int StateTemperatureFailure = 4;
const int StateTest = 8;
float TempSensorValue; // current temperature from sensor DHT11
float PowerSenseInputValue; // voltage after divider
int PingFailure = 0; // flag
int PingCountOk; // counter
int TestButtonState; // pressed LOW
int State = StateOk; // status of the net/temp/power/test
// User configurable variables (via source recompile and upload to Arduino board again)
// pinging
byte useDhcp = true;
byte useDns=true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// these values ​​must be changed
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false !!!
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false !!!
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false !!!
char serverName[] = "server1.tu-plovdiv.bg"; // Only if useDns is true !!!
// thresholds
const int TemperatureAlarmValue = 36; // over 36C - alarm
const int PingCountAlarmValue = 3; // over 3 lost packets - alarm
const float DCPowerAlarmValue = 0.5; // under 0.5 volts after voltage diveider - alarm
const float DCPowerVoltage = 9.0; // voltage of the power adapter
EthernetClient Client; // Declare client object
dht DHT; // DHT object
void setup() // initialise ports/values
​​{
pinMode(TestButton, INPUT_PULLUP); // LOW when pressed
// LEDs - light on HIGH
pinMode(LEDPowerFailure, OUTPUT);
pinMode(LEDTemperatureFailure, OUTPUT);
pinMode(LEDLANFailure, OUTPUT);
pinMode(LEDDiagnostics, OUTPUT);
// initialise Serial and SIM800l
sim800l.begin(9600); // initialize SIM800l module at 9600 bps
Serial.begin(9600); // debug messages to serial monitor of Arduino IDE
delay(500); // wait for proper initialization of the SIM800l 500mS
}
void loop()
{
State = StateOk;
// check
TestButtonState = digitalRead(buttonPin); // if LOW - do diagnostic (Power failure simulation)
if (TestButtonState == LOW) { // test diagnostic SMS and PowerLow LED simulation
Serial.println("Diagnostics button pressed.");
state = state | StateTest;
}
// check temperature
int chk = DHT.read11(DHT11Pin);
if (chk == DHTLIB_OK) {
TempSensorValue = DHT.temperature;
if (TempSensorValue > TemperatureAlarmValue) {
State = State | StateTemperatureFailure;
Serial.print("Temperature overflow");
Serial.println(TempSensorValue, 1);
}
}
// check power down state, read twice after 500ms to avoid brownouts
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
delay(500); // wait for brownout 500mS
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
State = State | StatePowerDownFailure;
Serial.println("Power down.");
}
}
// check ping state of the server
// ..
if (PingFailure) {
State = State | StatePowerDownFailure;
Serial.println("Ping failed - server is down.");
}
// process state
if (sim800l.available()){ // is SIM800l receive SMS or status - dump it back
Serial.write(sim800l.read());
}
}
void SendTextMessage()
{
Serial.println("Sending Text Message...");
//sim800l.print("AT+CMGF=1\r
"); // Set the shield to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"+3591234567\"\r"); // put actual number here
delay(200);
//sim800l.print("Failure
is: ");
// ... by State...
sim800l.print("\r"); //the content of the message
delay(500);
sim800l.print((char)26); //the ASCII code of the ctrl+z is 26 (required ^Z at end of SMS)
delay(100);
sim800l.println();
Serial.println("Text Message Sent.");
delay(500);
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GreyPhantom, 2016-10-18
@GreyPhantom

What Ethernet shield? the one on the W5100 uses pins 4, 10, in addition to SPI (4 is the choice of SD card, 10 is Ethernet itself). As I see it, you have the 10th pin assigned as an input, because of which both the shield itself and what else uses this output may not work.

C
Cyril, 2016-10-18
@argz

What exactly doesn't work?

D
Dona Balkanska, 2016-10-18
@donadonadona

When entering the program code into the Arduino IDE
and after checking Compile
, the program showed errors
that I don't know how to clean.
Here:
Arduino: 1.6.11 (Windows 10), Board: "Arduino/Genuino Uno"
Build options changed, rebuilding all
ServerGuard_Dona_with_SIM800l:53: error: 'dht' does not name a type
dht DHT; // DHT object
^ ServerGuard_Dona_with_SIM800l:81: error: expected primary-expression before '.' token int chk = DHT.read11(DHT11Pin); ^ ServerGuard_Dona_with_SIM800l:82: error: 'DHTLIB_OK' was not declared in this scope if (chk == DHTLIB_OK) { ^
C:\Users\admin\Desktop\ServerGuard_Dona_with_SIM800l\ServerGuard_Dona_with_SIM800l.ino: In function 'void loop()':
ServerGuard_Dona_with_SIM800l:74: error: 'buttonPin' was not declared in this scope
TestButtonState = digitalRead(buttonPin) ; // if LOW - do diagnostic (Power failure simulation)
^
ServerGuard_Dona_with_SIM800l:83: error: expected primary-expression before '.' token
TempSensorValue = DHT.temperature;
^
Multiple libraries were found for "Ethernet.h"
Used: C:\Users\admin\Documents\Arduino\libraries\Ethernet
Not used: C:\Program Files (x86)\Arduino\libraries\Ethernet
exit status 1
'dht' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question