What version do you have of IDE? In newer versions, you install the MySensors library in IDE
//Mattias
What version do you have of IDE? In newer versions, you install the MySensors library in IDE
//Mattias
Yes you can use LDR and a DHT11 together.
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* REVISION HISTORY
* Version 1.0 - Henrik EKblad
*
* DESCRIPTION
* Example sketch showing how to measue light level using a LM393 photo-resistor
* http://www.mysensors.org/build/light
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// NodId
#define MY_NODE_ID 99
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
//Including nescessary libraries
#include <SPI.h>
#include <MySensors.h>
#include <DHT.h>
// Set this offset if the sensor has a permanent small offset to the real temperatures
#define SENSOR_TEMP_OFFSET 0
// Sleep time between sensor updates (in milliseconds)
// Must be >1000ms for DHT22 and >2000ms for DHT11
static const uint64_t UPDATE_INTERVAL = 60000;
// Force sending an update of the temperature after n sensor reads, so a controller showing the
// timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
// the value didn't change since;
// i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
static const uint8_t FORCE_UPDATE_N_READS = 10;
//Defining child ID
#define CHILD_ID_LIGHT 0
#define CHILD_ID_HUM 1
#define CHILD_ID_TEMP 2
//Defining Pin
#define DHT_DATA_PIN 3
#define LDR_PIN A0
//Defining values to store sensor information
float lastTemp;
float lastHum;
uint8_t nNoUpdatesTemp;
uint8_t nNoUpdatesHum;
bool metric = true;
int lastLightLevel;
//Defining sleep and wait times
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)(30 seconds)
#define MESSAGEWAIT 500
MyMessage LightMsg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
DHT dht;
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Temp Fukt Ljus", "1.0"); // 2017 02 05
// wait(MESSAGEWAIT);
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
// wait(MESSAGEWAIT);
present(CHILD_ID_HUM, S_HUM);
// wait(MESSAGEWAIT);
present(CHILD_ID_TEMP, S_TEMP);
metric = getControllerConfig().isMetric;
}
void setup()
{
dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
}
// Sleep for the time of the minimum sampling period to give the sensor time to power up
// (otherwise, timeout errors might occure for the first reading)
sleep(dht.getMinimumSamplingPeriod());
}
void loop() {
// Force reading sensor, so it works also after sleep()
dht.readSensor(true);
// Get temperature from DHT library
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT!");
} else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
// Only send temperature if it changed since the last measurement or if we didn't send an update for n times
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
// Reset no updates counter
nNoUpdatesTemp = 0;
temperature += SENSOR_TEMP_OFFSET;
send(msgTemp.set(temperature, 1));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
} else {
// Increase no update counter if the temperature stayed the same
nNoUpdatesTemp++;
}
// Get humidity from DHT library
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
// Only send humidity if it changed since the last measurement or if we didn't send an update for n times
lastHum = humidity;
// Reset no updates counter
nNoUpdatesHum = 0;
send(msgHum.set(humidity, 1));
#ifdef MY_DEBUG
Serial.print("H: ");
Serial.println(humidity);
#endif
} else {
// Increase no update counter if the humidity stayed the same
nNoUpdatesHum++;
}
int lightLevel = (1023-analogRead(LDR_PIN))/10.23;
Serial.println(lightLevel);
if (lightLevel != lastLightLevel) {
send(LightMsg.set(lightLevel));
lastLightLevel = lightLevel;
}
sleep(SLEEP_TIME);
}
LDR pin A0
DHT pin 3
And i use pro mini.
//Mattias
And my settings are seen in previous posts.
But this does not lead to anything so I finish this now.
I can burn Mysbootloader yes.
But the Atmega circuit does not start.
The problem I think is that Mysbootloader does not use the internal clock
And because you said you had a bootloader for OTA and internal clock, 8MHz I wanted you to send it to me.
Then there would have been no problem, I think.
@MLs said in Another simple (No SMT) relay actuator:
@MLs said in Another simple (No SMT) relay actuator:
Feeling a bit confused how do you know that a bootloader uses the internal clock?
Because I used another bootloader after installing your card, I did not get the Atmega circuit to run. But if I used this bootloader, I started the Atmega circuit and everything worked.But what makes the internal clock in used?
I use a UNO when I'm burning bootloader and do not know if you can change fuses and clock option.If you use a bootloader that uses an external clock, you will not get the Atmega circuit to run. If I understand everything right.
No if I'm burning 8MHz Mysbootloader, the Atmega circuit does not start.
But instead, I use this bootloader (ATmega328 on a 8 MHz internal clock) and I get the Atmega circuit to run, but without OTA.
Therefore, I asked you how to know how a bootloader uses an external clock or internal clock.
@MLs said in Another simple (No SMT) relay actuator:
Feeling a bit confused how do you know that a bootloader uses the internal clock?
Because I used another bootloader after installing your card, I did not get the Atmega circuit to run. But if I used this bootloader, I started the Atmega circuit and everything worked.But what makes the internal clock in used?
I use a UNO when I'm burning bootloader and do not know if you can change fuses and clock option.
If you use a bootloader that uses an external clock, you will not get the Atmega circuit to run. If I understand everything right.
No if I'm burning 8MHz Mysbootloader, the Atmega circuit does not start.
But instead, I use this bootloader (ATmega328 on a 8 MHz internal clock) and I get the Atmega circuit to run, but without OTA.
The problem is not to burn bootloader. The problem I think is that the Mysbootloader does not use internal clock.
Therefore, I asked you how to know how a bootloader uses an external clock or internal clock.
And because you had a bootloader for OTA and internal clock, 8MHz I wanted you to send it to me.
##############################################################
MYSBL13.name=ATmega328 with MYSBootloader
MYSBL13.upload.tool=avrdude
MYSBL13.upload.protocol=arduino
MYSBL13.bootloader.tool=avrdude
MYSBL13.bootloader.unlock_bits=0x3F
MYSBL13.bootloader.lock_bits=0x0F
MYSBL13.build.mcu=atmega328p
MYSBL13.build.board=AVR_PRO
MYSBL13.build.core=arduino
MYSBL13.build.variant=standard
## Arduino with MYSBootloader 1.3pre
## -------------------------------------------------
MYSBL13.menu.cpu.16MHzatmega328=ATmega328 16MHz (XTAL, BOD1V8)
MYSBL13.menu.cpu.16MHzatmega328.upload.maximum_size=30720
MYSBL13.menu.cpu.16MHzatmega328.upload.maximum_data_size=2048
MYSBL13.menu.cpu.16MHzatmega328.upload.speed=115200
MYSBL13.menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF
MYSBL13.menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA
MYSBL13.menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x06
MYSBL13.menu.cpu.16MHzatmega328.bootloader.file=MYSBootloader/MYSBL13pre_atmega328_16Mhz.hex
MYSBL13.menu.cpu.16MHzatmega328.build.mcu=atmega328p
MYSBL13.menu.cpu.16MHzatmega328.build.f_cpu=16000000L
MYSBL13.menu.cpu.8MHzatmega328=ATmega328 8MHz (RC, BOD1V8)
MYSBL13.menu.cpu.8MHzatmega328.upload.maximum_size=30720
MYSBL13.menu.cpu.8MHzatmega328.upload.maximum_data_size=2048
MYSBL13.menu.cpu.8MHzatmega328.upload.speed=38400
MYSBL13.menu.cpu.8MHzatmega328.bootloader.low_fuses=0xE2
MYSBL13.menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA
MYSBL13.menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x06
MYSBL13.menu.cpu.8MHzatmega328.bootloader.file=MYSBootloader/MYSBL13pre_atmega328_8Mhz.hex
MYSBL13.menu.cpu.8MHzatmega328.build.mcu=atmega328p
MYSBL13.menu.cpu.8MHzatmega328.build.f_cpu=8000000L
############# DO NOT WORK INTERNAL CLOCK #####################
MYSBL13.menu.cpu.8MHzinternalclockatmega328=ATmega328 8MHz internal clock (RC, BOD1V8)
MYSBL13.menu.cpu.8MHzinternalclockatmega328.upload.maximum_size=30720
MYSBL13.menu.cpu.8MHzinternalclockatmega328.upload.maximum_data_size=2048
MYSBL13.menu.cpu.8MHzinternalclockatmega328.upload.speed=38400
MYSBL13.menu.cpu.8MHzinternalclockatmega328.upload.tool=arduino:avrdude
MYSBL13.menu.cpu.8MHzinternalclockatmega328.upload.protocol=arduino
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.low_fuses=0xE2
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.high_fuses=0xDA
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.extended_fuses=0xfe
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.file=breadboard/MYSBL13pre_atmega328_8Mhz.hex
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.unlock_bits=0x3F
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.lock_bits=0x0F
MYSBL13.menu.cpu.8MHzinternalclockatmega328.bootloader.tool=arduino:avrdude
MYSBL13.menu.cpu.8MHzinternalclockatmega328.build.mcu=atmega328p
MYSBL13.menu.cpu.8MHzinternalclockatmega328.build.f_cpu=8000000L
MYSBL13.menu.cpu.8MHzinternalclockatmega328.build.core=arduino:arduino
MYSBL13.menu.cpu.8MHzinternalclockatmega328.build.variant=arduino:standard
MYSBL13.menu.cpu.1MHzatmega328=ATmega328 1MHz (RC/8, BOD1V8)
MYSBL13.menu.cpu.1MHzatmega328.upload.maximum_size=30720
MYSBL13.menu.cpu.1MHzatmega328.upload.maximum_data_size=2048
MYSBL13.menu.cpu.1MHzatmega328.upload.speed=9600
MYSBL13.menu.cpu.1MHzatmega328.bootloader.low_fuses=0x62
MYSBL13.menu.cpu.1MHzatmega328.bootloader.high_fuses=0xDA
MYSBL13.menu.cpu.1MHzatmega328.bootloader.extended_fuses=0x06
MYSBL13.menu.cpu.1MHzatmega328.bootloader.file=MYSBootloader/MYSBL13pre_atmega328_1Mhz.hex
MYSBL13.menu.cpu.1MHzatmega328.build.mcu=atmega328p
MYSBL13.menu.cpu.1MHzatmega328.build.f_cpu=1000000L
##############################################################```
I do not get Atmel to run with Mysbootloader 8MHz.
Seems like it does not use the internal clock
Also tried to put your text into the board.txt file without any difference.
But if I use the bottloader ATmega328 on a breadboard (8 MHz internal clock it work.
@dpressle
Ok first, I have to say that I have no problem getting your project to work. It connects directly to HA. What I get a little confused about is that according to the link I linked to it says.
Be sure to select "ATmega328 on a breadboard (8 MHz internal clock)" when burning the bootloader.(If you select the wrong item and configure the microcontroller to use an external clock, it won't work unless you connect one.)
And as I interpret your post, you can take whatever bootloader you want (8 MHz).
And if I understand you right now, all settings iis n the board.txt file?
//Mattias
Feeling a bit confused how do you know that a bootloader uses the internal clock?
Because I used another bootloader after installing your card, I did not get the Atmega circuit to run. But if I used this bootloader, I started the Atmega circuit and everything worked.
But what makes the internal clock in used?
I use a UNO when I'm burning bootloader and do not know if you can change fuses and clock option.
It depends a little on what you want to do, but at first it is enough. However, if you want to use MySensor's example using external libraries, you will also need to download this link.
Https://github.com/mysensors/MySensorsArduinoExamples/archive/master.zip
For example, DHT 22, which measures temperature and humidity.
//Mattias