Some questions to Nick Gammon's Temperature and Humidity Logger

Hi guys,

first of all - many thanks to Nick Gammon for his nice tutorials and idears.

I'm currently working on a temperature/humidity logger I'd like to use for some environmental monitoring.

I use Nick's Guide (Gammon Forum : Electronics : Microprocessors : Temperature and humidity sensor - battery powered) as a starting-point and I am currently working just to get the Atmega328P (with 16 Mhz on 5V) working with a DS3231 RTC module powered by Nick's suggested MOSFET-powerlane.

So far I got it working. But there are some point's which are not quite logic for me.

To my background: I am a biologist - new to electronics. I have some python programming skills but just started looking into arduino-C.

First - "my" code so far:

#include <avr/sleep.h>
#include <avr/wdt.h>


#include <Wire.h>
#include "Sodaq_DS3231.h"


const byte LED = 2;
const byte P = 7;

void poweroff ()
{  
  // put all digital pins into low stats
  for (byte pin = 0; pin < 14; pin++)
    {
    digitalWrite (pin, LOW);
    pinMode (pin, OUTPUT);  
    }
  // except the power pin which has to be high    
  digitalWrite (P, HIGH);  // turn power OFF
  }  // end of powerOffPeripherals

void poweron ()
  // power MOSFET - initially off
  {
  digitalWrite (P, LOW);
  pinMode      (P, INPUT);
  }
  
void flash ()
  {
  pinMode (LED, OUTPUT);
  for (byte i = 0; i < 10; i++)
    {
    digitalWrite (LED, HIGH);
    delay (50);
    digitalWrite (LED, LOW);
    delay (50);
    }
    
  pinMode (LED, INPUT);
    
  }  // end of flash

// Real Time Clock

DateTime now;
byte lastMinute = 99;

boolean powerOnRTC ()
  {
  Wire.begin();
  rtc.begin();
  flash ();
  delay (2);
 
  Wire.read ();
  
  }  // powerOnRTC

void powerOffRTC ()
  {
  // turn off I2C
  TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

  // turn off I2C pull-ups
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);
  }  // powerOffRTC

boolean getTime ()
  {
  powerOnRTC ();

  now = rtc.now();
  powerOffRTC ();
   }  // end of getTime

  
// watchdog interrupt
ISR (WDT_vect) 
{
   wdt_disable();  // disable watchdog
}  // end of WDT_vect
 


void setup () {
poweron();
poweroff();
   }

void loop () 
{
 
  // flash ();
  poweron();
  delay(5000);
  getTime ();
  delay(100);
  // flash ();
  delay(500);
  poweroff();
  if (now.hour() == 12)
  {flash();}
  
  // disable ADC
  ADCSRA = 0;  

  // clear various "reset" flags
  MCUSR = 0;     
  // allow changes, disable reset
  WDTCSR = bit (WDCE) | bit (WDE);
  // set interrupt mode and an interval 
  WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 8 seconds delay
  wdt_reset();  // pat the dog
  
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
  noInterrupts ();           // timed sequence follows
  sleep_enable();
 
  // turn off brown-out enable in software
  MCUCR = bit (BODS) | bit (BODSE);
  MCUCR = bit (BODS); 
  interrupts ();             // guarantees next instruction executed
  sleep_cpu ();  
  
  // cancel sleep as a precaution
  sleep_disable();
  
  } // end of loop

To my questions:

1.:
For the Mosfet-Powerlane described in Nick's plan here:
https://www.gammon.com.au/images/Arduino/HHS_Temperature_Logger9.png

For me, it only works, if I don't connect the 10k resistor to 5V. (when Atmega is powered down, no current flows, too)
If I use the 10k resistor, the power is always blocked. Then it makes no difference if I set the defined power-pin to low.

It would be great if someone could enlighten me. I would like to solve this "problem" before I go on implementing the SD-Cardmodule.

2.:
In Nick's shematic are many "smoothing capacitors" involved. Accept the 2x 22pF needed for the Clock on the Atmega I currently don't have them implemented yet. He suggested to use a 100uF Capacitor for the powerlane. I have to admid - I couldn't really interpret where to connect it to. Should it be connected between the Atmega 5V-power connector and power-ground? (if yes which of both 5V pins?) Sry for this - I guess stupid - question.

Many thanks in advance

P.S. "I love the power-saving code - 6 µA are great"

Hi, From the drawing it looks like the 10k is being used as a "pull up" to insure the output is high until the pin is pulled low. If the Pin output doesn't appear to go low enough, and I'm just speculating here, the resistor may not actually be 10k. You might want to measure it with an ohm meter to be sure.
You can also put a volt meter on the pin and watch for 5v (high) and 0v low. If it doesn't go to 0v or very close to it (when the pin is called low) I'd increase the value of the resistor.

As far as the filtering capacitor goes, generally lower value caps are used to filter higher frequencies like spurious tones, harmonics,rfi etc while higher (like 100uf) values are used to filter power supply noises like 60 cycle hum or in the case of most of todays switching power supplies, the frequency of the switching circuit. That being said, It's hard to say exactly where to place it depending on the distance between your voltage source and your load IE: arduino. If it's a long distance (meaning several feet) a lot of different noise sources can infiltrate plain wiring. Generally I'd go to the source end first (filtering any power supply induced noise), and if the distance is great, run your power leads as shielded pair (grounding the shield), or at least twisted pair. Hope that helps.