With an Atmega, create a wireless temperature sensor

To continue the project of automation with the Raspberry, the first important step for me is to have a sensor able to send wireless data. Here I present to you an example of a probe measuring temperature and humidity.

Pi Home Connect - temperature humidity sensor atmega 328

Best Raspberry Pi Projects

In this article (very very long), I warn you that you will might not create the best probe in the world. Many sites offer extensive methods to arrive at an optimal solution. Here I introduce the results of my tests. Je compte sur les experts pour proposer des améliorations via les commentaires 🙂

To recap my probe runs on two AA batteries, with an Atmega328, a LED to indicate the operation and a 433 Mhz transmitter. The LED is optional because it uses energy but useful to confirm that everything is working.

After 16 17 18 19 20 days of work (the writing of the article took me time), my probe still emits the data with a distance of 5m between the sensor and the Gateway (an arduino connected to a Raspberry Pi), without walls but with a wooden furniture. Here is the evolution of the level of the batteries on the two weeks :

Pi Home Connect - temperature humidity sensor atmega 328 - interface

The probe has the following operating : all the 5 seconds (Yes this is for testing), the DHT11 probe is activated, the temperature and humidity are read as well as the battery level. These data constitute the message to send. The message is sent 4 time at an interval of 160ms. Each sending done turn on then turn off LED.

You can therefore imagine that by decreasing the number of messages' send, removing the LED and by increasing the time between each measurement, your battery can last easily a year (I would soon do an article on the subject).

Prerequisites

Before embark you on the adventure, you need a bit of hardware and a ready to use working environment.

Hardware

You will need :

  • An atmega328 (just the chip) with or without bootloader, No matter because we will install our. You can easily find on ebay or Chinese sites in the €1.5 / piece or Amazon. In commissioning several you can still somewhat decrease the price.
    Pi Home Connect - Atmega328P
  • An Arduino UNO where you can remove the atmega. It will be used to send the bootloader and probe management program. You can use this Arduino (or another) as receiver. Count in the €10 (official but legal version), a little more on Amazon (faster). The Arduino can be used to build other probes.
    Pi Home Connect - Arduino Uno with Atmega328p
  • A temperature sensor. I used a DHT11 I had at home. This really isn't the best, the DHT22 is much better, but I only had it at the time. Count € 1.40 the DHT11 or € 4.5 the DHT22 (but ca is worth the cost)
    Pi Home Connect - DHT11
  • Resistance 4.7KΩ necessary for the DHT11 probe
    Pi Home Connect - resitor 4k7
  • A transmitter and a receiver 433 Mhz. The transmitter will be for the probe, the receiver for the Arduino connected to the Raspberry. A little less than €1 the pair. But beware not all have the same quality … Subsequently I will test other communication modules.
    Pi Home Connect - 433Mhz rf kit
  • AA batteries. I'm using 2 that I put in a case from a Christmas LED wreath. The boxes cost about € 3.5 10 pieces (or here for a faster delivery).Pi Home Connect - 2x AA battery holder
  • WiresPi Home Connect - wires
  • A breadboard. Then you can use prototyping plates, smaller and then reuse the breadboard for other installations.Pi Home Connect - Breadboard
  • (Optional but highly recommended !) 22µF capacitors. You will need 2 if your Atmega328 are configured by default to use an external oscillator (and I do not think that you can know in advance)
    Pi Home Connect - 22uF capacitor
  • (Optional but highly recommended !) A 8 Mhz or 16 Mhz resonator if your Atmega328 are configured by default to use an external oscillator
    Pi Home Connect - 16mhz resonator

You are now equipped and ready to assemble your probe.

Workspace

When I speak of working environment, it is basically the tool Arduino IDE. Take the version 1.5.8+, even if it is a beta, in order to work !

It is now to be able to configure your Atmega to work with its internal oscillator (8MHz) to reduce its overall consumption. For this I advise you to load the ZIP file here. The archive must be unpacked in the sub directory hardware located with your Arduino programs. Here is what you should have :

Arduino IDE boards.txt folder mac os

At the launch of the Arduino IDE you should see new cards :

Pi Home Connect - boards atmega328 8Mhz low power

Installing an optimized bootloader

Here is the wiring to load the bootloader :

PiHomeConnect-Node bootloader atmega328

Once completed :

  • Connect the arduino UNO to your computer via its USB cable
  • Start Arduino IDE then confirm the configuration
  • Upload of the programme so that the UNO can send the bootloader. The program is available in the menu “File > Examples > ArduinoISP”. Then click on “Upload”
    ThePi Home Connect - IDE arduino ISPArduino UNO is now ready to send a bootloader to your mounting !
  • Select the type of card for your probe. We therefore choose an atmega328 on an arduino in 3.3V and the frequency of 8 Mhz
    Pi Home Connect - IDE bootloader 8Mhz 3.3V
  • Now select the card that will program the bootloader. It's our Arduino
    Pi Home Connect - IDE bootloader Arduino as ISP
  • Rest to burn the bootloader with the command “Burn the bootloader”

You have now configured your node to operate in 3.3V using the internal oscillator which operates at 8 Mhz. This is the first step to optimize the use of energy !

You can now add your sensor and transmitter. If you have a resonator, You can remove it (as well as the capacitors) :

PiHomeConnect - Arduino node temperature humidity sensor

The Arduino UNO card can be used to send the program in your new Atmega. You can connect it as shown in the drawing above or else take the Atmega's node, put it on the UNO card, load the program through the IDE then replace the atmega's node on the breadboard. Up to you to decide, personnellement je déplace l’atmega 😉

The photo of the final stage :

PiHomeConnect - Arduino node temperature humidity sensor

Installation of the sensor program

In the Arduino IDE you will need to install the following libraries :

  • The DHT library to retrieve the data of your DHT11. Available here.
  • The Narcoleptic library to put at sleep (you can say that ?) “deep” your node and thus save the batteries. Available here.
  • The Manchester Library to send the data via your 433 Mhz transmitter. Available here.

The installation of libraries is as follows :

  • Retrieve the .zip of the library
  • Import it using the import tool in Arduino IDE (Sketches > Import libraries)

Here is the program to send to your node using the Arduino IDE :

#include <Narcoleptic.h>
#include <dht.h>
#include <Manchester.h>

#define BLINK_MODE true

#define NODE_ID 1 // On 8bits so 0..255

#define MESSAGE_SIZE 6 // Number of bytes to send
#define SEND_MESSAGE_DELAY 5000 // Delay in ms between each value's extraction
#define SEND_433_COUNT 4 // How many times the message has to be send
#define SEND_433_PAUSE 160 // 16 multiple

// Define connectors used for the node
#define TX_PIN 7
#define LED_PIN 13
#define DHT11_PIN 2

dht DHT;
// Array of bytes to will make the message
// In this node : 2 bytes for voltage, 2 bytes for
uint8_t msgData[MESSAGE_SIZE] = {0, 0, 0, 0, 0, 0};

//--------------------------------------------------------------------------------------------------
// Read current supply voltage
//--------------------------------------------------------------------------------------------------
 long readVcc() {
   bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
   long result;
   // Read 1.1V reference against Vcc
   #if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
   #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
   #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);  // For ATmega328
   #endif
   delay(2); // Wait for Vref to settle
   ADCSRA |= _BV(ADSC); // Convert
   while (bit_is_set(ADCSRA,ADSC));
   result = ADCL;
   result |= ADCH<<8; result = 1126400L / result; // Back-calculate Vcc in mV ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power return result; // Vcc in millivolts } void setup() { pinMode(LED_PIN, OUTPUT); if (BLINK_MODE) digitalWrite(LED_PIN, LOW); man.setupTransmit(TX_PIN, MAN_1200); msgData[0] = NODE_ID; // Wait 1s to allow DHT11 to initialize Narcoleptic.delay(1000); } void loop() { // Read Vcc value long currentVcc = readVcc(); uint16_t uint16_currentVcc = (uint16_t)currentVcc; // Save millivolts in two bytes to keep high precision. Will be decoded by the gateway uint8_t byteData[2] = {uint16_currentVcc >> 8, uint16_currentVcc & 0xFF};
  msgData[2] = byteData[0];
  msgData[3] = byteData[1];

  // Read data from DHT11 sensor
  int chk = DHT.read11(DHT11_PIN);
  // DHT11 values can be put in a byte value due to the low precision
  msgData[4] = (uint8_t)DHT.humidity;
  msgData[5] = (uint8_t)DHT.temperature;

  // Send message SEND_433_COUNT times with a delay of SEND_433_PAUSE ms for each
  for (int i=0; i<SEND_433_COUNT; i++) {
    msgData[1] = i;
    if (BLINK_MODE) digitalWrite(LED_PIN, HIGH);
    man.transmitArray(MESSAGE_SIZE, msgData);
    if (BLINK_MODE) digitalWrite(LED_PIN, LOW);
    // Wait between each send
    Narcoleptic.delay(SEND_433_PAUSE);
  }
  // Wait before getting new sensor value
  Narcoleptic.delay(SEND_MESSAGE_DELAY);
}

And after ?

The next article will show how to receive data and send them to the Raspberry Pi that will (i hope) know what to do !

There so much to improve ! As for example :

  • Code optimization. The idea is to make a generic library, available on GitHub, that will bring together the functions of recovery, conversion, etc. Depending on the sensors connected : DHT11, DHT22, LM36, etc.
  • Other modules of emission : NRF24L01 , ESP8266, etc.
    The 433Mz modules are capricious, not always of good quality, I have the impression that this is the best choice. So, I'll continue the investigation

The project Pi Home Connect continues !

You may also like...

  • Zescientist

    Hello,
    These couples Em/Rec are not excellent quality.
    A trick to still minimize the cost : Maintain these Em/Rec on your remote modules (sensors and actuators) but investing in a single “good” torque for your master station linked to the RPi. This will greatly improve your scope.

    Otherwise the ESP8266 looks “the solution” for low-cost home automation, more need for atmega to manage sensors, no more need to arduino to transmit the information to the RPi and a scope related to the quality of the Wifi.

    • Actually I think that the Wifi is picked up all over the House so far enjoy it and the price is really reasonable. Je suis pressé de tester en remplaçant mes modules 433Mz 😉

      • mrclem.NW

        Yes but the ESP8266 consumption is really poor. It takes a max.
        Thanks for your tutorial, I wanted to redo my sensor RF with just an ATMega instead of the current microview. but mostly do sleep suddenly change the bootloader. all for dialogue with a RFXCOM module and domoticz

        • I'll watch what it gives knowing because the goal is to make sleep the transmitter node should not receive instruction. But the connection to the SSID will not take too long … I'll test

          • MrClem

            So actually this isn't too serious if we cut the transmitter each time. Tests I've seen are pretty slow when it is a LUA server running on it but hey it is evolving at a speed…
            Thanks again the customization bootloader part interests me bcp. I'll try everything.

          • MrClem

            arf du coup j’ai des questions 😉 :

            What are your bootloader optimizations ?

            as - ton this bootloader need optimized to use Narcoleptic ? (It would seem that not)

            However I just realize it will not be for my use. I do very little waiting in my loop(), everything is managed by time interval : wholesale, watching if the interval is passed to execute an acquisition and send in RF. It will take me a function of falling asleep and wake rather but with the milli() still active.. I get it, It must exist.

          • The bootloader is optiboot 5 .0a for atmega328 in 3.3V and 8 mhz.

            Narcoleptic allows the use of the watchdog so ca is not related to the bootloader

            For your concerns I believe that you can wake up your atmega based on interruption (There are 2, the 0 and the 1). You also have JeeLib which allows to track the elapsed time : http://jeelabs.net/pub/docs/jeelib/

  • s

    Finally a tutorial for exactly what I am looking for. Looks similar to the LoFi (Hackaday) project. why don't you consider lower power MCU like the ATiny84, 85 etc.? Anyway, the arduino approach is way better then ESP8266 in terms of real wireless sensors without the need to replace batteries.

    • I don't know what is the difference between atiny85 and a atmega328P (-PU version of course). Do you think that the battery life will be much more longer ?

      • S

        well, you can run a wireless sensor based on attiny for a year using a coin cell (Cr2032) or even for year (10 years on 3 x a) depending on how often do you transmit,etc.
        did you considered any encryption on the payload that you are transmitting? would be a nice future if you consider extending this project in the future to have bi-directional transmission: receive and send commands to other remote sensors.

        I am also waiting for some RFM12B and RFM69HW transceivers to test them with attiny in a similar project. they have better range and wall penetration than the NRF24L01.

        good luck! waiting for your next part of the tutorial 🙂

  • Galen

    Bravo pour ce tuto 🙂 encore un qui va rejoindre ma collection sur le sujet jusqu’a ce que je me lance
    I also have one ci http://labalec.fr/erwan/?p=1534 under the elbow it can help in the search for the transmitter and receiver reliable

  • Guillaume

    Hello,
    There is also another way to set one atmega without removing the chip is to proceed by the spi and incorporate the isp on the arduino program. But another more pleasant way is to take an arduino mini pro that is almost cheaper than an atmega as well as components to put next.

    • The arduino mini and more is very compact so ideal for probes (This is the next step after the different transmitters ;-))

  • David

    Hello,

    Thanks for the article ! Very interesting ! Especially since I have the same approach currently so I'll follow the series with great attention.

    I just spent some time trying to coir how to install a bootloader but I suffered a little …

    Looking at files that you proposed I see that unlike other links I found you don't use a bootloader provided directly with the IDE. Y' has you there a reason ?

    http://hardware-libre.fr/2014/02/fr-arduino-atmega-programmation-isp/
    http://arduino.cc/en/Tutorial/ArduinoToBreadboard

    Not yet tried yours actually, I first tried the others but even if I manage to install the bootloader (After a small correction in board.txt) I can't upload the sketch then.

    I saw that he had used “Upload with a programmer” instead of “Upload”, is it the same thing with your bootloader ? (pas encore essayé car j’avais dépassé mon quota de bricolage pour la journée 😉

    David.

    • Mine is kinda a mixture. The bootloader is that of optiboot which is now in arduino ide if I'm not mistaken. One of the archive is the atmega 168 for 328 in the bootloader of the IDE directory
      The bootloader to actually go through a programmer. Mon article essaye de resumer tout ca car j’ai aussi galeré 😉

      • David

        Hello,

        Okay I tried with your bootloader today and it works very well. I saw that you had also modified the platform.txt file ? This must explain why just by modifying the Board.txt of origin file to add your configuration and using your bootloader it does not work …

        If I do as you say in your article it works nickel so I look further for the moment. I will come back when I have more advanced on the project.
        Nevertheless, I will be very interested to understand what you did as a change. An idea for another article ?? 😉 Mais pour le moment j’attends avec impatience l’article sur la liaison entre l’arduino de réception et le RPI. Via a link series ? SPI ?

        Good continuation !

        • L’article est en ligne 😉 il manque le code pour la réception mais il suffit d’ajouter un récepteur 433 on the arduino and send the data to the raspberry

          For the boot loader is cool if it works. But changes are mainly there to have a stand-alone package that installs easily.

          • David

            Hello,

            Am glad to have managed to put your bootloader and be passed to 8 MHz internal and 3, 3V.

            Suddenly it is possible to use the serial port via the arduino UNO after ? I already noticed the need to disconnect the reset of the card, otherwise the atmega restarts all the time (probably the potential difference) But even with that I no longer see anything via the link series of FDI ….

            You're second to none ?
            Thank you.

          • I'll not guarantee it to 100% but it seems to me that it worked.

  • Pascal

    It is true that the transmitter/receiver 433 Mhz low-cost are not terrible !! but there is the Mysensors project which uses the NRF24L01 (2.4 GHz transmitter/receiver) well-functioning and managed by project home automation Jeedom, It's really good!

    • I finish my Arduino library for the Wifi ESP8266 modules and after I tested the NRF24L01. I could then make a comparison to help choose according to their needs.

  • David

    Hello,

    I have well advanced thanks to your article !
    I tested 3 reduction of current consumption libraries … Narcoleptic, Jeelib and Lowpower.

    I couldn't out me at the start and I had a 1mA even conso mode POWER_DOWN …
    It was linked to the switches that I use to set the sensor number (you have not followed the same principle as you put it directly in the code …). Problem set using the arduino output to power the switches to init only.

    Brief ! I wanted to share the consumption I get with three libraries.
    8MHz 3v. 4My about ongoing (read temperature, light and battery).

    At rest :
    – LowPower : 0.030My (either 3648 days wholesale but without the self-discharge)
    – Narcoleptic : 0.190My (either 623 days about always without the self-discharge)
    – JeeLib : 0.014My (either 6689 such days without the self-discharge)

    It is still a sacred difference … I do not know if you tried to watch the consumption …

    David.

    • Thanks for the information. I'd seen JeeLib but not LowPower. Je vais faire la bascule 😉
      I finished my tests with an ESP8266, j’attaque bientôt les NRF24L01 😉

    • Attention also with figures. Sleep with the WatchDog is 8s max so all 8s the Arduino will wake up make a loop with a test and go back to sleep.

      • David

        Jeelib accepts a value up to 65535 ms … I put 10 seconds for the moment and I don't have the impression that it wakes … I do not know how they. I plan to do a measure all the 5 minutes so I'll put the command in a loop. The arduino will wake up a little but there will be no measure so it should not consume …
        We'll see over time.

        If you have a return can be compare.

        David.

  • Arduina

    Hello Chris!! Thank you very much for this tutorial. We have tested the code on the transmitter and works perfectly, but we fail to generate a code to the receiver, We have intended but it does not work we.
    Our idea is to have two transmitters using the nodes in the code that you have done.
    We hope impatient the next tutorial!

    • Hello,

      Here is an example how to receive data on an arduino and send them to the serial port (where i plugged into raspberry pi) :

      #include

      #define RX_PIN 4
      #define LED_PIN 13

      uint8_t moo = 1;
      #define BUFFER_SIZE 6
      uint8_t buffer[BUFFER_SIZE];

      void setup() {
      Serial.begin(115200);
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN, moo);
      man.setupReceive(RX_PIN, MAN_1200);
      man.beginReceiveArray(BUFFER_SIZE, buffer);
      }

      void loop() {
      if (man.receiveComplete()) {
      uint8_t receivedSize = 0;
      Serial.print(buffer[0]);Serial.print(";");
      Serial.print(buffer[1]);Serial.print(";");
      float voltage = (buffer[2] < < 8 ) | (buffer[3] & 0xff); Serial.print(voltage/1000);Serial.print(";"); Serial.print(buffer[4]);Serial.print(";"); Serial.print(buffer[5]); Serial.println(";");man.beginReceiveArray(BUFFER_SIZE, buffer); moo = ++moo % 2; digitalWrite(LED_PIN, moo); } }

      • Arduina

        Thank you so much! We are going to spend the day working with this. Our goal is to have two transmitters Node1, Node2 sending data to a receiver that can identify the message of each transmitter node (1 & 2). With the example I've provided, I think that we can see how the data we get from a node and decide how to manage the trasnmisiones from the receiver. I think that us useful seramuy. I will start testing with one Arduino for access to the serial port; but then it will have to try other Attiny85, that is what we use for our project.
        If we implement the two transmitters nodes will share the code to a receiver.
        Thanks again!

        • With the ultra basic protocol i tried to implement you can manage multiple nodes (it's the first or second field i don't remember well) so sure you should be able to do that.
          About the Attiny85, the program is the same so should be easy to
          Good luck !

          • Arduina

            Sorry about the mess!! The TX code I provided is not the correct one. My response should have been:

            Hi again,

            Sadly, I haven´t been as successful as I hoped 🙁

            We created the TX Code and loaded into Attiny85 and the RX code loaded on UNO. The Manchester Library used is the indicated in this tutorial https://github.com/mchr3k/arduino-libs-manchester.

            The TX code doesn´t seem to be working as there is no blinking on the LED in Pin 1. Also, I can see that the RX code is not receiving anything as the ony Serial.print I get on the serial port is the first one "Inicio Loop".

            I will paste both pieces of code just in case someone is interested to have a look and maybe suggest ideas while we research from our side.

            We have succesfully using the Manchester library to have 1 transmitter sending data to 2 receivers all running on Attiny. That was also a challenge for us, and we are proud to have it working at home with inside and outside lights that come on when movement is detected. I will share all final codes once we get this next step completed!

            This is the TX Transmitter Code loaded on Attiny85:

            /*Este sketch usa la librería Manchester del siguiente enlace 
             https://github.com/mchr3k/arduino-libs-manchester
             
             Gestionar distintos nodos del transmisor que envían datos a un solo receptor
             
            */
            #include <Manchester.h>
            
            #include <Narcoleptic.h>
            
            
            #define BLINK_MODE true
             
            #define NODE_ID 1 // On 8bits so 0..255
             
            #define MESSAGE_SIZE 6 // Number of bytes to send
            #define SEND_MESSAGE_DELAY 5000 // Delay in ms between each value's extraction
            #define SEND_433_COUNT 4 // How many times the message has to be send
            #define SEND_433_PAUSE 160 // 16 multiple
             
            // Define connectors used for the node
            #define TX_PIN 0
            #define LED_PIN 1
            #define SENSOR_T A2
            
            float dato;
            float datoTotal;
            int   bucle;
            
            float y;            //señal de planta sensor dinamo
            float Temp;        //variable de temperatura desde "sensor"
            
             
            // Array of bytes to will make the message
            // In this node : 2 bytes for voltage, 2 bytes for
            uint8_t msgData[MESSAGE_SIZE] = {0, 0, 0, 0, 0, 0};
             
            //--------------------------------------------------------------------------------------------------
            // Read current supply voltage
            //--------------------------------------------------------------------------------------------------
             long readVcc() {
               bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
               long result;
               // Read 1.1V reference against Vcc
               #if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
                ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
               #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
                ADMUX = _BV(MUX3) | _BV(MUX2);
               #else
                ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);  // For ATmega328
               #endif
               delay(2); // Wait for Vref to settle
               ADCSRA |= _BV(ADSC); // Convert
               while (bit_is_set(ADCSRA,ADSC));
               result = ADCL;
               result |= ADCH<<8;
               result = 1126400L / result; // Back-calculate Vcc in mV
               ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
               return result; // Vcc in millivolts
            } 
             
            void setup() {
              pinMode(LED_PIN, OUTPUT);
              if (BLINK_MODE) digitalWrite(LED_PIN, LOW);
              man.setupTransmit(TX_PIN, MAN_1200);
              msgData[0] = NODE_ID;
              // Wait 1s to allow DHT11 to initialize
              Narcoleptic.delay(1000);
            }
             
            void loop() {
              // Read Vcc value
              long currentVcc = readVcc();
              uint16_t uint16_currentVcc = (uint16_t)currentVcc;
              // Save millivolts in two bytes to keep high precision. Will be decoded by the gateway
              uint8_t byteData[2] = {uint16_currentVcc >> 8, uint16_currentVcc & 0xFF};
              msgData[2] = byteData[0];
              msgData[3] = byteData[1];
             
              // Read data from sensor
                 
                    dato = 0;
               datoTotal = 0;
                   bucle = 0;
               while (bucle <=3000){
              
              dato = analogRead (SENSOR_T);
              datoTotal = dato + datoTotal;
            
              delayMicroseconds (10);
              bucle++;
            }
               
                y = (datoTotal / 3000); //sumamos caida de tension en el cable
              
             Temp = (5.12 * y * 100.0)/1024.0;
                 
             
              // Sensor values can be put in a byte value due to the low precision
              msgData[4] = (uint8_t)Temp;
              msgData[5] = (uint8_t)Temp; 
             
              // Send message SEND_433_COUNT times with a delay of SEND_433_PAUSE ms for each
              for (int i=0; i<SEND_433_COUNT; i++) {
                msgData[1] = i;
                if (BLINK_MODE) digitalWrite(LED_PIN, HIGH);
                man.transmitArray(MESSAGE_SIZE, msgData);
                if (BLINK_MODE) digitalWrite(LED_PIN, LOW);
                // Wait between each send
                Narcoleptic.delay(SEND_433_PAUSE);
              }
              // Wait before getting new sensor value
              Narcoleptic.delay(SEND_MESSAGE_DELAY);
            }
            

            And this is the RX Receiver code running on UNO (to be able to access serial port):

            
            /*Este sketch usa la librería Manchester del siguiente enlace 
             https://github.com/mchr3k/arduino-libs-manchester
             
             Gestionar distintos nodos del transmisor que envían datos a un solo receptor
            */
            #include <Manchester.h>
            
            
            #define RX_PIN 4
            #define LED_PIN 13
            
            uint8_t moo = 1;
            #define BUFFER_SIZE 6
            uint8_t buffer[BUFFER_SIZE];
            
            void setup() {
            Serial.begin(115200);
            pinMode(LED_PIN, OUTPUT);
            digitalWrite(LED_PIN, moo);
            man.setupReceive(RX_PIN, MAN_1200);
            man.beginReceiveArray(BUFFER_SIZE, buffer);
            }
            
            void loop() {
            Serial.println ("Inicio loop");
            if (man.receiveComplete()) {
            uint8_t receivedSize = 0;
            Serial.print(buffer[0]);Serial.print(";");
            Serial.print(buffer[1]);Serial.print(";");
            float voltage = (buffer[2] << 8 ) | (buffer[3] & 0xff);
            Serial.print(voltage/1000);Serial.print(";");
            Serial.print(buffer[4]);Serial.print(";");
            Serial.print(buffer[5]);
            Serial.println(";");
            
            man.beginReceiveArray(BUFFER_SIZE, buffer);
            moo = ++moo % 2;
            digitalWrite(LED_PIN, moo);
            }
            }
            

            Thanks!

          • You changed the value of the default values and i guess that you missed the connection. I see A2 as a value which is not a good value. Only integers are expected.
            Please look at this picture : http://fc04.deviantart.net/fs70/f/2013/038/3/7/attiny_web_by_pighixxx-d5u4aur.png
            I guess that Arduino Pin values are the one to use (10, 11, 12, 13). Not sure about that, do not have an attiny85 …
            Try to load a basic sketch that blinks a led to guess which values are correct

  • Marco

    Good evening,

    I would like to know if an article has been done for the reception on an other arduino? I searched but I found nothing.

    I hope that the author of the article can help me

    I took exactly are sketches for the show with a dht22 and atmega 8 Mhz internal

      • Marco

        J had seen this article. However I seek the approval code that goes with the code d issuance of this article for an arduino.

        • No sorry. The principle is explained missing the decomposition/approval code that I have on my computer and I can send you if I find it

          • Marco

            Hello, ca if you do not mind I am interested in the code if you can put the Ain desssus. You want my email?

            Thanks again

          • Can be adapted but should work :

            #include

            #define RX_PIN 4

            #define LED_PIN 13

            uint8_t moo = 1;

            #define BUFFER_SIZE 6

            uint8_t buffer[BUFFER_SIZE];

            void setup() {

            Serial.begin(115200);

            pinMode(LED_PIN, OUTPUT);

            digitalWrite(LED_PIN, moo);

            man.setupReceive(RX_PIN, Man_1200);

            man.beginReceiveArray(BUFFER_SIZE, buffer);

            }

            void loop() {

            if (man.receiveComplete()) {

            uint8_t receivedSize = 0;

            Serial.print(buffer[0]);Serial.print(“;”);

            Serial.print(buffer[1]);Serial.print(“;”);

            float voltage = (buffer[2] << 8 ) | (buffer[3] & 0xff);

            Serial.print(voltage/1000);Serial.print(";");

            Serial.print(buffer[4]);Serial.print(";");

            Serial.print(buffer[5]);

            Serial.println(";");

            man.beginReceiveArray(BUFFER_SIZE, buffer);

            moo = ++moo % 2;

            digitalWrite(LED_PIN, moo);

            }

            }

          • Marco

            I thank you test it.

          • Marco

            Good evening,

            I just tested the reception code (I could not before lol)

            this is what I receive:

            1;1;4.77;2;1;

            1;2;4.77;2;1;

            1;3;4.77;2;1;

            1;0;4.77;2;1;

            1;1;4.77;2;1;

            1;2;4.77;2;1;

            1;3;4.77;2;1;

            1;0;4.79;2;1;

            1;2;4.79;2;1;

            Do you have an idea or it may come

            Thank you

          • C’est dans les commentaires de l’émetteur 🙂
            – ID du node
            – No. of the frame 0 à SEND_433_COUNT (4 by default). I have not therefore set the ACK management frame is transmitted several times to pass ca. A charge of the Raspberry to sort
            – Supply voltage from me transmitter
            – Humidity of the DHT11 (connected to the pin 2 by default)
            – Temperature of the DHT11 (connected to the pin 2 by default)

            Given your past values we will have to review the connection or settings

          • Marco

            It's good I had not changed the dht11 in dht22

            the I receive:

            1.10v – 58% – 26*C

            is it normal that I see only 1.10v while it is plugged in usb.

            Another question after I leave you alone.
            When I plug the arduino with just the external its in 9v I have no data on the range of the receiver monitor. But if I plug in usb it works.

            A parameter change?

            good evening

          • No it's not normal especially since in the previous teames you had well 4.7V. Un autre paramètre a du etre changé

          • Marco

            normalement le voltage que je dois trouver c’est combien?
            là je l’alimente avec alim externe de 9v alors
            au moment de la premiere mesure j’etais avec mon usb (donc bonne valeur mesurer)
            ensuite j’ai modifier le dht11 en dht22 et du coup j’etais a 1.10v

            le reste des parametre est identique a ton code

          • Utilise la meme alimentation via ton hub. Si tu mets du 9v direct sur l’arduino alors qu’il attend du 3.3v max normal que ca ne fonctinne pas 😉

          • Marco

            Good evening,

            ca y est, everything works, par contre j’ai toujours les 1.10v.

            Dit moi sur cette partie la de ton prog, sachant que j’utilise juste la puce atmega, est ce que je dois modifier quelques choses? pour le moment elle tourne avec cette partie la entiere.

            I see that there is a line in observation or there is written; // Read 1.1V reference against Vc
            is this from a ca that I have my 1.10v on my return receipt?

            anyway thanks much, I really started with the arduino, I try to understand the prog in C, but it's not obvious, but that being said it's super interesting

            //————————————————————————————————–

            // Read current supply voltage

            //————————————————————————————————–

            long readVcc() {

            bitclear(PR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC

            long result;

            // Read 1.1V reference against Vc

            #if defined (__Avr_attiny24__) || defined(__Avr_attiny44__) || defined(__Avr_attiny84__)

            ADMUX = _BV(Mux5) | _BV(Mux0); // For ATtiny84

            #elif defined (__Avr_attiny25__) || defined(__Avr_attiny45__) || defined(__Avr_attiny85__)

            ADMUX = _BV(Mux3) | _BV(Mux2);

            #else

            ADMUX = _BV(Refs0) | _BV(Mux3) | _BV(Mux2) | _BV(Mux1); // For ATmega328

            #endif

            delay(2); // Wait for Vref to settle

            ADCSRA |= _BV(ADSC); // Convert

            While (bit_is_set(ADCSRA,ADSC));

            result = ADCL;

            result |= ADCH<<8;

            result = 1126400L / result; // Back-calculate Vcc in mV

            ADCSRA &= ~ bit(ADEN); bitset(PR, PRADC); // Disable the ADC to save power

            return result; // Vc in millivolts

            }

          • The 1.1 is a reference value to calculate the actual value of food. You fed how much ?

          • Marco

            Hello,

            J feeds my arduino USB and I am plugged into the ground and the 5v as in your last diagram on top (except that I n have a wire on the tx and rx) and at the level of the programme I have just change to qu’ He m displays values as above c is say:
            Voltage – humidity – temperature

          • Marco

            It's good I had not changed the dht11 in dht22

            the I receive:

            1.10v – 58% – 26*C

            is it normal that I see only 1.10v while it is plugged in usb

  • Alexandre SEROT

    Hello,

    J’ai tester avec un Arduino UNO, j’ai été obliger de commenter les lignes 28 and 44

    bitclear(PR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
    ADCSRA &= ~ bit(ADEN); bitset(PR, PRADC); // Disable the ADC to save power

    Car PRR n’était pas reconnu.

    Avec ces modifs ça fonctionne nikel.

    Je possède des pro micro (Chinese copy buy from Aliexpress with a ATmega32u4), I wanted to test and it is the drama ... after uploading, Arduino is no longer recognized by Windows and tells me that the device has been stopped because it has problems (code 43).

    Find the solution (in case AC happen to other):

    – To reset the Arduino (rst + gnd)
    – It will again be detect by windows for a while court, this allows see the COM port on which it is detect.
    – It will again go astray
    – Start uploading a basic sketch (blink example)
    – Repeat reset
    – Uploading resulted, is winning it is operational again.

    The thing (I know not explain), is that during reset, it is correctly detected by Windows for a short time (10barely seconds), that is why we must start a little ahead of the 2nd upload reset, uploading starting with the check code.

    My question is why my pro micro happening in this state?

    I'm rereading the code, I do not understand what puts it in this state, I find nothing specific has Atmega328

    Thanks in advance,

    Alex

    • Hello
      Is it does not come to the library Narcoleptic ? By being turned off and using the “sleep” classic it does not work better ? I see that AC could make manipulation and to register “plant” the uc

  • Jean-Michel SORET

    Hello,
    Bravo for the accuracy of your tutorial, which made me want to throw me.
    This is my first steps with Arduino.

    I have not yet received the capacitors so I tested without external oscillator.
    In the Arduino IDE, I joined the errors messages.
    Is this related to the lack of external oscillator???

    Thank you to want to respond well.

    • Hello
      No attachments
      But yes it is possible that the sketch does not load because of lack oscillator to turn the clock correctly. But it is possible to do without it but in this case we must adapt the upload speed

  • Jean-Michel SORET

    Hello,

    I added the oscillator and capacitors (20 nF and not 20 ΜF) but I get the below error when burning the bootloader:

    Arduino : 1.6.7 (Windows 10), Map : “(Pihomeconnect) ATmega328 – 3.3V – 8 MHz internal clock”

    java.io.IOException: Cannot run program “{path}/bin/avrdude”: CreateProcess error=2, The specified file can not be found

    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

    at processing.app.helpers.ProcessUtils.exec(ProcessUtils.java:26)

    at cc.arduino.packages.Uploader.executeUploadCommand(Uploader.java:123)

    at cc.arduino.packages.uploaders.SerialUploader.burnBootloader(SerialUploader.java:359)

    at processing.app.Editor.lambda$handleBurnBootloader$42(Editor.java:2754)

    at java.lang.Thread.run(Thread.java:745)

    Caused by: java.io.IOException: CreateProcess error=2, The specified file can not be found

    at java.lang.ProcessImpl.create(Native Method)

    at java.lang.ProcessImpl.(ProcessImpl.java:386)

    at java.lang.ProcessImpl.start(ProcessImpl.java:137)

    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

    … 5 more

    If you have a track…

    Thanks in advance

    • As stated in the log avrdude the program is not in the path. If you have installed must set the path variable

      • Danston Sac

        Hello, I mac osx and I do not get serious bootloader I Can not run program “{path}/bin/avrdude”: error=2, No. such file or directory.

        so I have the same problem, but does not understand how to adjust the variable path thank you

        • It will rule in the memory of the IDE interface

          • Danston Sac

            so I made the mods of the path but now I have another error,
            avrdude: stk500_recv(): programmer is not responding
            avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp = 0x00

            is this a mistake on my wiring ? I paid attention yet. I have a doubt about the meaning of polarity 2 there are capacitors in the same direction !!.

          • I think yes an error in the connection. I also remember having to hold the assets for the reset atmega is detected. It depended chips

  • Jean-Michel SORET

    Hello,

    I am running Windows 10. I changed the path and restarted my PC but I have always the same path error.
    I do not understand what is happening.
    I have the latest version of the Arduino IDE (1.7).

    If you have an idea…

    Thank you

  • Julien Geneste

    Yop,

    I saw on the picture once the finished project you do not have quartz on your Atmega. The clock is internal or her depends on the version of the microcontroller ?

    Thank you !

    • Hello,
      As I explain I am using the internal oscillator at 8 Mhz. Less “fast” but mostly consumes less

  • sidwin9

    Hello,

    I'm missing details of your editing, especially as regards the power supplies. Apparently, you nourish it with all 2 1.5volts batteries for operation of the Atmega to 3,3Volts but what do you do for TX power 433 Mhz works in 5Volts.

    Thank you to enlighten me a little all this.

    • Good evening. I connected it directly. The module operates in a Range 3.3V-12V. By cons in 3.3v la.portée is limited

      • sidwin9

        Thanks for your quick reply.
        The 2 battery 1.5 volts are therefore sufficient for the entire assembly. You want how much time without changing batteries ?

        • I speak beginning of the article with a chart that shows the evolution of the burden of 2 batteries. In this tutorial I abused a little on the frequency to illustrate the operation. By cons I have not measured discharge “natural” battery

    • Gael Dirig

      hello sidwin9 j tries in vain to contact you on the mini meteo station with display forumarduino forum on the site to get more information from your weather station with Arduino and screen 480×320 .you could share your gross apple code to see if I can understand and adapt to the hamlet of code and my function. I t was also contact on another forum. Thank you

  • Ken Addams

    Hello,
    It's great all these montages, but in a real house installation, you install your breadboards with captuers temperatures and resistance in your living room ? In fact I agree completely with the principle, but I have not yet found Implementation “not geeks” ie carrying a discreet box for integration into a harmonious interior. Please ideas ?

    • Hello. For the non geek on this site there is a project explained with housings that hide all that
      If not for this article that explains how to make oneself. The next step is the printed box 3d. Each of view for aesthetics

  • Valerie Stephane Vdb Cresp
    • superb ! Good work !
      Which components are used and what life estimated for the battery ?

  • Pingback: With an Atmega, create a wireless temperature sensor | RoboTechno()

  • This

    Hello,

    Je suis sur un montage analogue avec virtualwire ou radiohead pour le 433Mhz. j’envoie du JSON et ca passe bien (j’ai bien le message de recu sur le moniteur arduino du recpteur), seul probleme, quand je connecte mon arduino au raspberry je recois plus les println sur le serial dans ma boucle de lecteur de message radio.

    Plus etrange encore, en dehors de ma boucle ce code

    void loop(){
    //reception msg 433
    {…}
    Serial.println(“test”);
    if (msg.length()>0){
    Serial.println(msg);
    }
    }

    me genere bien “test” en boucle mais jamais le msg. Les capteurs / emmeteur sont alimenté par un circuit a part, j ai juste ma data sur l arduno.
    Dans l’ide arduino niveau du moniteur jtout est ok, juste ce serial.println dans ma boucle de lecture qui remonte pas sur raspberry -_-. Ni dans un script python, ni sur nodered.

    Je pense avoir tres clair :/

    Une idée 😀

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop