loading

In a recent instructable Indigod0g described a mini weather station that works pretty well, using two Arduinos. Maybe not everyone wants to sacrifice 2 Arduinos to get humidity and temperature readings and I commented that it should be possible to do a similar function with two Attiny85's. I guess talk is easy, so I better put my money where my mouth is.

In fact, if I combine two earlier instructables I wrote:

2-Wire LCD interface for Arduino or Attiny
and
Receiving and sending data between Attiny85 (Arduino IDE 1.06)
then most of the work is already done. Only need to adapt the software a bit.

I chose for a two wire lcd solution with a shift register, rather than an I2C LCD because on the Attiny the shift register is easier to implement than the I2C bus. However... if you for instance want to read a BMP180 or BMP085 pressure sensor, you need I2C for that anyway so you might as well use an I2C LCD then too. TinyWireM is a good library for I2C on an Attiny (but it requires extra space).

BOM
The transmitter:
DHT11
Attiny85
10 k resistor
433MHz transmitter module

The receiver
Attiny85
10k resistor
433 MHz receiver module

The display
74LS164 shift register
1N4148 diode
2x1k resistor
1x1k variable resistor
an LCD display 2x16

Step 1: Mini Weather Station With Attiny85: the Transmitter

The transmitter is a very basic configuration of the Attiny85 with a pull up resistor on the reset line.
A transmitter module is attached to digital pin '0' and the DHT11 data pin attaches to digital pin 4.
Attach a wire of 17.2 cm as antenna (for a much better antenna see step 5).
The software is as follows:

//will work on Attiny85/45

//RF433=D0 pin 5
//DHT11=D4 pin 3

// libraries
#include <dht.h> //From Rob Tillaart
#include <Manchester.h>
dht DHT11;
#define DHT11PIN 4
#define TX_PIN 0  //pin where your transmitter is connected
//variables
float h=0;
float t=0;
int transmit_t = 0;
int transmit_h = 0;
int transmit_data = 0;

void setup() 
{
  pinMode(1, INPUT);
  man.setupTransmit(TX_PIN, MAN_1200);
}

void loop() {
 int chk = DHT11.read11(DHT11PIN);
 h=DHT11.humidity;
 t=DHT11.temperature;
// I know, I am using 3 integer variables here
// where I could be using 1
// but that is just so it is easier to follow
 transmit_h=100* (int) h;
 transmit_t=(int) t;
 transmit_data=transmit_h+transmit_t;
  man.transmit(transmit_data);
  delay(500);
}

The software uses Manchester code to send the data.
It reads the DHT11 and stores the temperature and humidity in 2 separate floats. As the Manchester code doesnt send floats, but an integer, I have several options:
1- split the floats into two integers each and send those
2- send each float as an integer
3- send the two floats as one integer

With option 1 I need to combine the integers into floats again in the receiver and I have to identify which integer is what, making the code long winded
With option 2 I still need to identify which integer is for humidity and which for temperature. I cannot go by sequence alone in case one integer is lost in transmission, so I would need to send an identifier attached to the integer.
With option 3, I can send just one integer. Obviously this makes the readings a bit less accurate - within 1 degree- and one cannot send below zero temperatures, but it is just a simple code and there are ways around that. For now it is just about the principle.

So what I do is I turn the floats into integers and I multiply the humidity with 100. Then I add the temperature to the multiplied humidity.
Given the fact that the humidity will never be 100% the max number I will get is 9900. Given the fact that the temperature will also not be above 100 degrees, the max number will be 99, therefore the highest number i will send is 9999 and that is easy to separate at the receiver side.

Ofcourse my calculation in which i use 3 integers is overkill as it could easily be done with 1 variable. I just wanted to make the code easier to follow.

the code now compiles as:

Binary sketch size: 2,836 bytes (of a 8,192 byte maximum)
so that fits in an Attiny 45 or 85

NOTE the dht.h library I use is the one from Rob Tillaart. That library is also suitable for a DHT22. I am using version 1.08. However the Attiny85 may have problems reading a DHT22 with lower versions of the library. It has been confirmed to me that the 1.08 and 1.14 -though working on a regular Arduino- have trouble reading a DHT22 on the Attiny85. If you want to use a DHT22 on the Attiny85, use the 1.20 version of this library. It all ha sto do with timing. The 1.20 version of the library has a faster read. (Thanks for that user experience Jeroen)

Step 2: Mini Weather Station With Attiny85: the Receiver

Again the Attiny85 is used in a basic configuration with the Reset pin pulled high with a 10 k resistor. The Receiver module is attached to digital pin 1 (pin 6 on the chip). The LCD is attached to digital pins 0 and two.
Attach a wire of 17.2 cm as antenna.
The code is as follows:

#include <Manchester.h>
#include <LiquidCrystal_SR.h>
LiquidCrystal_SR lcd(0,2,TWO_WIRE);
#define RX_PIN 1 //= physical pin 6

void setup() {
  lcd.begin(16,2);
  lcd.home();
  man.setupReceive(RX_PIN, MAN_1200);
  man.beginReceive();
}

void loop() { if (man.receiveComplete()) { uint16_t m = man.getMessage(); man.beginReceive(); lcd.print("Humid: "); lcd.print(m/100); lcd.setCursor(0,1); lcd.print("Temp "); lcd.print(m%100); } }

The code is fairly simple: the transmitted integer is received and stored in variable 'm'.
It is divided by 100 to give the humidity and the modulo of 100 gives the temperature.
So suppose the integer received was 3325
3325/100=33
3325 % 100=25
This code compiles as 3380 bytes and therefore can only be used with an attiny85, not with a 45

Step 3: Mini Weather Station With Attiny85/45: the Display

For the display it is best that I refer to my instructable on a two wire display.
In short, a common 16x2 display uses a shiftregister so it can operate with two digital pins.
Ofcourse if you prefer to use an I2C ready display, that is possible too, but then you need to implement an I2C protocol on the Attiny. The Tinywire protocol can do that. Though some sources say that that expects a 1 Mhz clock, I didnt have any trouble (in another project) to use it on 8Mhz
Anyway I just didnt bother here and used a shift register.

Step 4: Mini Weather Station With Attiny85/45: Possibilities/Conclusions

As said, I made this instructable to show that one can make a mini weather station with two attiny85's (even with one attiny85+ 1 attiny45).
It only sends humidity and temperature, using a DHT11.
However, the Attiny has 5 digital pins to use, 6 even with some trickery. Therefore it is possible to send data from more sensors.
In my project- as seen in the pics on stripboard and on a professional PCB (OSHPark)- I send/receive data from a DHT11, from an LDR and from a PIR, all using two attiny85's
The limitation in using an attiny85 as receiver though is the presentation of the data in a flashy style. As the memory is limited: Texts like 'Temperature, Humidity, light level, subject approaching' will fill up valuable memory space pretty fast.
Nevertheless, no reason to use two Arduino's just to send/receive temperature and humidity.

Additionallly, it is possible to have the transmitter go to sleep and only have it wake up to send data say every 10 minutes and thus feed it from a button cell.
Obviously, not only temperature or humidity data can be send but one can have an array of small transmitters sending soil moisture readings as well, or add an anemometer, or a rain meter

Step 5: Mini Weather Station: the Antenna

The antenna is an important part of any 433Mhz set up.
I have experimented with the standard 17.2 cm 'rod' antenna and had a short flirt with a coil antenna, What seemed to work best is a coil loaded antenna that is easy to make. The design is from Ben Schueler and apparently was published in 'Elektor' magazine. A PDF with the description of this 'Air cooled 433 MHz Antenna' is easy to follow

Step 6: Adding a BMP180

Want to add barometric pressure sensor like the BMP180? check my other instructable on that.

<p>Hi guys! help please, can't send the code for the button with the Attiny 13. what did I do wrong, the code compiles but no action happens(( how can I improve? is it possible to feed from the batteries with sleep mode attiny to last longer worked?</p><p>?Here is the code for the Arduino and it works great:</p><p>?=====================================</p><p>?#include &lt;RCSwitch.h&gt;</p><p>int button = 12;</p><p>RCSwitch mySwitch = RCSwitch();</p><p>void setup() {</p><p>Serial.begin(9600);</p><p>// Transmitter is connected to Arduino Pin #10</p><p>mySwitch.enableTransmit(10);</p><p>pinMode(button, INPUT);</p><p>}</p><p>void loop() {</p><p>if(digitalRead(button) == HIGH){mySwitch.send(11235377, 24);}</p><p>delay(500);</p><p>}</p><p>?============================================</p><p>?And this is the code for Attiny 13, the code is loaded but no action, help to fix the problem</p><p>?</p><p>?===============================================</p><p>#include &lt;RCSwitch.h&gt;</p><p>#include &lt;avr/io.h&gt;</p><p>#include &lt;util/delay.h&gt;</p><p>int button = 3;</p><p>RCSwitch mySwitch = RCSwitch();</p><p>int main( void ) {</p><p>// Transmitter is connected to Arduino Pin #0 (PB0)</p><p>mySwitch.enableTransmit(0);</p><p>pinMode(button, INPUT);</p><p>}</p><p>void loop() {</p><p>if(digitalRead(button) == LOW){mySwitch.send(11235377, 24);}</p><p>_delay_ms(500);</p><p>}</p><p>?===============================================</p><p>?</p>
<p>I replied this in my other instructable where u asked this</p>
Wonder if anyone has tried using a esp8266 for the same project.
<p>I must have missed your comment because in fact I actually have:</p><p><a href="https://www.instructables.com/id/Atmosphere-in-the-Hen-House-DHT11-DS18B20-ESP8266/">https://www.instructables.com/id/Atmosphere-in-the-...</a></p><p>and here I even add a BMP 180:</p><p><a href="https://www.instructables.com/id/Atmosphere-in-the-Hen-House-DHT11-DS18B20-ESP8266/">https://www.instructables.com/id/Atmosphere-in-the-...</a></p><p>Now I didnt use deepsleep as I used it to illustrate what one can do with the ESP8266-01 and that isnt so suitable for deep sleep (unless you solder a small wire on the chip)<br>But it surely will work with deepsleep on an esp8266-12</p>
<p>I was just thinking the same question. I think that the issue with the ESP8266 is the power draw. Although you can Sleep the ESP8266, I have seen posts claiming that there are issues with a stand-alone ESP8266 reconnecting to the DHTxx sensors on Waking. Using the Tiny85 to run Code might alleviate this issue. I would be interested to hear if anyone has any success.<br></p>
<p>I have done this successfully on the ESP8266 with the Dallas DS18B20 sensor and it works fine when waking from a WiFi.forceSleepBegin(). This seems to extend battery life a lot, I have avoided to the full on deep sleep for now (had some problems with a dodgy sketch I uploaded that put it into deepsleep to quickly and I the struggled to upload a new sketch).<br></p>
If you do create it I would love to see an instructable. I has a few of these ESP8266 and nrf24l01.
<p>Look for nodemcu for a &quot;all in one&quot; sollution :-) Check out banggood, aliexpress etc. some few dollars.. you can also buy a shield.. Beware that different hw designs exist :-)</p>
<p>Here are some links to what I have found so far with just using the ESP8266 stand alone on batteries. I am not planning to do any of my own development on this anytime soon so let me know if you get anywhere with running the ESP8266 for extended periods (months) on low power.<br><a href="https://tzapu.com/minimalist-battery-powered-esp8266-wifi-temperature-logger/" rel="nofollow">https://tzapu.com/minimalist-battery-powered-esp82...</a><br></p><p><a href="http://www.bntdumas.com/2015/07/23/how-to-battery-powered-temperature-and-humidity-sensors/" rel="nofollow">http://www.bntdumas.com/2015/07/23/how-to-battery-...</a></p>
<p>I did.</p>
<p>correct. Have seen an esp8266 read a DHT11, no problem but forget abt batteries</p>
<p>Sure you can, I have used ESP8266 for DHT22 and many other sensors.<br>You can also make it send data to thingspeak directly :-)<br><br>Sensors I've used on esp8266:<br>* Light sensor<br>* Sound sensor (microphone)<br>* DHT22, DHT11<br>* Dust sensor (Sharp)<br>+++<br><br>I've also used oled ( https://github.com/olikraus/u8glib), not all oled libs work.<br>PS. you might have to buy or create logic level converters for some sensors.</p>
<p>I'd be tempted to try. Never had much luck with RF! I'd also make a fleet of these things, powered by coin cells - then have them in each room of my house...</p>
<p>Wow! It looks very nice!! Thanks you.</p>
<p>Thank you. Honestly though before making this, consider an esp8266 that sends it directly to a webpage.<br></p>
<p>I am having errors while compiling example code of RadioHead, VirtualWire and</p><p>Manchester library.</p><p>I am using ATtiny13a. I searched a lot but no luck. any suggestions ?<br>Error with VirtualWire lib : <strong>'TCCR1A' was not declared in this scope</strong></p><p>Error with RadioHead lib:<strong> error: 'DORD' was not declared in this scope</strong></p><p>Error with Manchester lib :<strong> #error &quot;Manchester library only supports 8mhz, 16mhz on ATMega328&quot;</strong></p><p>these are just line no. 1 of errors. </p><p>Will appreciate any help ! :)</p><p>Thanks. :)<br></p><p></p>
<p>I think the errormessages already give you all the help you need. The Manchester library only supports 8 and 16 MHz. The attiny13A supports 4.8 and 9.6 Mhz.<br>The TCCR1A and DORD refers to registers the 13A doesnt have.<br>It will work on an Attiny85 though<br></p>
<p>Yes. 13a is limited. and with unusual frequency Manchester can't work. is there any way that I can make it work using some older versions of library and cores ? I am not sure It's just my guess. </p><p>thank you !?</p>
<p>no, older cores and libraries will not magically make it work. I gave a link on yr orangeboard to a program that supposedly does work</p>
<p>Hi. I&rsquo;m struggling to send the information wirelessly.</p><p>I have made the full circuit and if I bridge the transmitters pin 5 and the receivers pin 6 together with a wire it works fine, so the Manchester library is working fine.</p><p>I set up a simple wireless button and LED circuit with the transmitter and receiver modules and that works fine too.</p><p>It just doesn&rsquo;t work if I try and use the wireless modules to send the data from one Attiny85 to the other.</p><p>Any suggestions?</p>
<p>let me see if i understood you correct: you made both the transmitter and the receiver and when you connect the transmitter antenna with the receiver antenna, it works as is, so you are receiving the data sent by the transmitter as in my circuit in your receiver as in my circuit. Correct?<br>So the attiny85 circuit that is sending is working as is the attiny85 circuit that is receiving as long as you connect the two antennas. Correct?<br>In that case the problem must be in your antennas.<br>please correct me if i misunderstood your problem<br></p>
<p>No, not connecting the antennas together. I connected one Attiny85's output pin 5 to the other Attiny85's input pin 6 and didn't used the wireless modules at all...and that worked...so I knew the Manchester code was working ok. </p><p>Then I did a test like this (with button and LED) (start at 2:20):</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/RHJVyMYJ1XQ" width="500"></iframe></p><p>....to test that the wireless modules work...and they do.</p><p>They just won't work to send the data from one Attiny85 to the other.</p><p>Have also tried swapping out the wireless modules for two new ones and no change.</p>
<p>ah ok i see so the attiny's work, the transmitter and receiver work, they just dont work together?<br>That is indeed very odd. This might be a stupid question but have you attached the right pins?<br>At what voltage are you operating the circuit?</p>
<p>That is exactly the case.</p><p>I have double and triple-checked the pins and asked a friend to do it and can't find a fault.</p><p>I'm running everything from the 5V supply pin from the Arduino Uno (that I used to program the Attiny85s).</p>
<p>in all honesty, I am a bit at a loss here, your circuits/program work, your transmitter wrks, your connections are right but cant establish connection...<br>Hmm.. when you connect de send and receive pins from yr chips.. do you then get proper readable data? I mean a proper sensor value as send by the transmitter or is it garble that you get?</p>
<p>I'm not actually using the LCD. As a separate issue, I get millions of errors when using the LiquidCrystal_SR.h library. Errors like:</p><p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c:426:40: error: 'TWEN' undeclared (first use in this function)</p><p> TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;</p><p>As i eventually plan as using the Arduino Uno as the receiver (with enough pins to not use the shift register) I ignored this while working and implemented the following code to use an LED to show it was working:</p><p>if (t &gt; 28) {</p><p> digitalWrite(2, HIGH); }</p><p>else {</p><p> digitalWrite(2, LOW);</p><p>}</p><p>Any suggestions on how I might fix this?</p>
<p>wich core are u using for the attiny85?</p>
<p>Not quite sure what you mean.</p><p>The clock is set to 8MHz internal...if that's what you mean.</p>
<p>no I mean the core, telling the compiler how to behave. There is the David Mellis core and the tiny core</p>
<p>I've was using the tiny core but have now downloaded and tried the David Mellis core. I'm not so worried about making the Attiny85 use 2 pin LCD as I have wired the LCD to the Arduino Uno and am now using that as the receiver. </p><p>The issue is still that lack of wireless communication. </p>
<p>ok so what error messages do you get now? still the </p><p>TWEN' undeclared (first use in this function)<br></p><p> TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;<br><br>?<br>or was that with the Tiny core?<br>That usually points to an I2C problem but you say you are not using that.<br></p>
<p>I just noticed the top pictures on this page of the transmitter are different, the picture with both transmitter and receiver is different from the actual picture in the transmitter section, just letting you know.</p>
<p>I am not sure which pictures you refer to as you are a bit cryptic in your description, but there is a picture of the transmitter on stripboard and a picture of the final one on a manufactured pcb. Circuits exactly the same. The pcb is made such that it also functions as experimentor board with the pins broken out to so called servo headings: signal-vcc-ground</p>
<p>I got these errors trying to upload the sketch.</p><p>TransmitterV2:10: error: 'dht11' does not name a type</p><p>TransmitterV2.ino: In function 'void loop()':</p><p>TransmitterV2:27: error: 'DHT11' was not declared in this scope</p><p>Uploading blink to the Attiny85 checked out fine. The file was slightly modified by including the dth11.cpp from Rob Tillaart's Library also.</p>
<p>joseph, I know for sure that I sent you a reply twice now already and somehow it just doesnt show up. OK 3rd time:<br>These errors point at your correct library not found. Also there really is no need to include the cpp file.<br>As there are many dht libraries with almost similar nomenclature there may be a mix up: Try this program:</p><p><a href="https://codebender.cc/sketch:361820">https://codebender.cc/sketch:361820</a></p>
You mean use that for a library?
<p>no I mean 'try that program' It is not a library but it is a program using the Rob tillaert DHT library.</p>
<p>Nice project! However I have a question: you say you could feed it from a button cell if you would let the transmitter sleep and only wake up like every 10 minutes. However: a button cell is only 3 volts normally? Will a button cell have enough power to drive the 433mhz transmitter? Normally this has an operating voltage of 5V?</p><p>I'm not too worried about the Attiny85 since it can operate from 2.7V, or something in that range I believe.</p>
<p>Thanks. I think I should clarify that. I meant buttoncell a bit more <br>generic as in 'battery powered'. One 3 volt buttoncell is sufficient for<br> the attiny as you point out and in fact it will also be enough for the <br>transmitter but the range will not be so wide. I currently feed mine <br>from a 3F super capacitor that gets charged to 5V from a small <br>solarpanel. I just do that with a resistor and a zener, probably not the<br> most efficient way but it is small and it works and i dont have to pay <br>any attention to it, other than keep the snow off the panel in the <br>winter. instead of a 3F capacitor a single nicad with a booster (like in<br> dollarstore solar garenlights) or 4 nicads or a LiPo would work too. If <br>it is about spece, the 3F capacitor or a small lipo might be best, but <br>no matter how small this device, it will need some sort of case that <br>likely would have some room for a few nicads</p>
<p>This will make programming ATTiny85 easier</p><p>https://www.htlinux.com/product/attiny-isp-shield/</p>
<p>Hey congrats diy_bloke, ATMEL re-tweeted your Instructable...</p><p>https://twitter.com/Atmel/status/753269714772750336</p>
<p>thanks for letting me know</p>
I keep hearing about this Arduino and ATtiny85. I have been into electronics since the 60s and worked as an electronic tech for Hammond Organ, Zenith, and Sun Electric for a combined time of almost 30 years, but I have never heard of either of them. What the heck are they?
<p>Hehehe, where shall I start :-)<br>The Arduino is a line of open hardware and open software using predominantly Atmel microprocessors. The current 'Workhorse' is the Arduino Uno that has an Atmega328 microcontroller on board. The Arduino has a bootloader so it is easy to upload programs through the IDE software. Look at Arduino.cc for more info.<br><br>The Attiny85 is the small brother of the Atmega328. It only has 8 pins and is very suitable for all sorts of small projects</p>
Thank you
<p>my pleasure</p>
<p><a href="https://www.arduino.cc/en/Guide/Introduction" rel="nofollow">https://www.arduino.cc/en/Guide/Introduction</a><br><br><a href="http://www.atmel.com/images/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf" rel="nofollow">http://www.atmel.com/images/atmel-2586-avr-8-bit-m...</a></p>
Thank you
Open source microcontrollers, which are rather user friendly.
Thank you

About This Instructable

131,856views

1,434favorites

License:

Bio: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I ... More »
More by diy_bloke:Working With the Funduino W5100 Ethernet Module. Uploading Data to ThingSpeak With MQTT Adding an MCP23017 I/O Extender to Arduino or ESP8266 
Add instructable to: