项目作者: MShokry

项目描述 :
Rat nest project
高级语言: C++
项目地址: git://github.com/MShokry/rat_arduino.git
创建时间: 2018-03-25T10:38:49Z
项目社区:https://github.com/MShokry/rat_arduino

开源协议:

下载


References

By :: Mahmoud Shokry ::

reducing power consumption almost by 87% (1.7mA) of normal operation consumption(13mA)

AtmegaPIR motion detector sensor with Arduino Nano in ultimate power saving mode

Thanks to : A full project for PIR + Arduino

Thanks to:- for information about sleep.h library and modes

for useful explanation of “Low Power Arduino! Deep Sleep Tutorial” for bare Arduino Uno chip

The Atmega 328p Datasheet

NOTE : when coming back from POWER-DOWN mode, it takes a bit until the system is functional at 100%!! (typically < 1sec)

ESP

ESP Data sheet

ESP NODEMCU PIN

ESP PIN default state

Ideas

PIR -(int)-> Nano <—(Wake,Motion,config,Update)—> ESP

3btn ———-^

ToDo

Project started 07Feb2017

Spex


  • Motion sensor
  • Battery powered
  • Battery Level
  • Buttons, Update, Config, Test, Reset
  • Buzzer feedback

Battery


:negative_squared_cross_mark: LDO (SPX3819, HT7333, XC6203) [Battery Serial Resistor]
:negative_squared_cross_mark: High Capacitor LOW ESR
:negative_squared_cross_mark: Buck/Boost MC33063 ( 0.9:6v => 2.37$/Unit)
:negative_squared_cross_mark: LiFePo4 batteries 3.6V 5$
:negative_squared_cross_mark: Battery Shield USB-Lithium 3.3V

  • Direct connect battery 3 bat

Rat Arduino Atmega Part


  • PIR Sensor Connected to interrupter
  • Motion detected 1st time Wakeup ESP
  • wakeup on change of btn PCINT used LIB
  • Feedback Unit Buzzing(2 if not activated, @Config 1 Buzz OK, )
  • btn as interrupt in Power_down mode only (INT0,INT1,WDT) is working. Source
  • [x] change F_CPU to 1MHZ or 4MHZ => PROWN, Delay and speed check Using MiniCore

  • [ ] ?Sleep until ESP is DONE

  • ?Delay with Timer or WDT LightSleep() or setupWatchDogTimer() :negative_squared_cross_mark: Not important If clock is 1 MHZ no need

Limitations


  • Arduino @16MHZ normal + POR @ 2.7v
  • motion stable @ > 4V

Rat Arduino ESP Part


  • Wakeup init WIFI and connect Sleeping Modes
  • send to server (Battery level,Alarm) <==> [MAX17043 || Read_VCC function] NEEDS Some testing
  • WIFI OFF
  • Moderated sleep 10uA @ Sleep
  • Raise Flag for nono operations ok
  • Power off from arduino
  • Names online not local Domain + URL => to be tested
  • Modify the lib Remove No Scan , :heavy_exclamation_mark: WIFI Manager Change HTTP_PORTAL_OPTIONS :next_track_button: Removed Scan button
  • Label Names before input , :heavy_exclamation_mark: WIFI Manager Change HTTP_FORM_PARAM :next_track_button: add name {p} :
  • msg=Test @ Test
  • Rename place to name
  • 5 Min for config as a max 3 for sending
  • Update Config Button to request the data from the server
  • Esp light Sleep to keep flag high
  • [ ] Default Name and servers for update and Max Len

  • [ ] Lower WIFI RF Power 120mA @ Tx 13dpm, 56mA @ Rx 1024byte

  • [ ] Password for login,

  • [x] What if server not connected => Buzzing twice or Wrong response => No alarm set,…
    :bangbang: What if esp raised the flag and not off or dealy to answer max retry time 10 minutes

Wifi configuration wifi config OR Wifi-Multi

Rat Eagle PCB Design


  • ESP EN by default low by resistor 10K to ground
  • add 5V power source LDO and 3.3 Normal
  • add Jumper for power source
  • [x] Buzzer for feedback or server

  • [ ] CAP to the button, Button to ground

  • Keep out the programming CHECK code
  • Power off the PIR ??? Transistor

PCB Prototyping and Assembly

Testing

Other

  • API documentation
  • 100 Unit Price


:heavy_check_mark: Done

  • Done
    :negative_squared_cross_mark: Not accepted
    :black_square_button: Todo
    :bangbang: Top Urgent
    :heavy_exclamation_mark: Urgent

Sleeping Modes helper function Hibernate

set_sleep_mode

  1. SLEEP_MODE_IDLE - the lowest power saving mode
  2. SLEEP_MODE_ADC
  3. SLEEP_MODE_PWR_SAVE
  4. SLEEP_MODE_STANDBY
  5. SLEEP_MODE_PWR_DOWN - the highest power saving mode

The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions
until the next interrupt or hardware reset.” text from ATMEGA328P datasheet

AttachInterrupt(A, B, C)

  1. A can be either 0 or 1 for interrupts on pin 2 or 3.
  2. B Name of a function you want to execute while in interrupt A.
  3. C Trigger mode of the interrupt pin. can be:
  4. LOW a low level trigger
  5. CHANGE a change in level trigger
  6. RISING a rising edge of a level trigger
  7. FALLING a falling edge of a level trigger
  1. In all but the IDLE sleep modes only LOW can be used.
  2. here since PIR sensor has inbuilt timer to switch its state from OFF to ON, we are detecting its CHANGE IN STATE to control our LED/relay at pin 13.
  3. therefore, we will not need to use arduino delay timer to Set "ON time" of our LED/relay, it can be adjusted physically using potentiometer provided on PIR sensor board.
  4. This further helps in using SLEEP_MODE_PWR_DOWN which is ultimate lowest power consumption mode for ATMEGA8328P chip
  5. (please note - because of onboard power regulators of arduino boards, power consumption cannot be reduced to predicted few microAmps level of bare chips.
  6. To achieve further reduction in current consumption, we will need bare ATMEGA328P chip)

WDT

The MCU Status Register (MCUSR) is used to tell the cause of the last
reset, such as brown-out reset, watchdog reset, etc.
NOTE: for security reasons, there is a timed sequence for clearing the
WDE and changing the time-out configuration. If you don’t use this
sequence properly, you’ll get unexpected results.

Configure the Watchdog timer Control Register (WDTCSR)
The WDTCSR is used for configuring the time-out, mode of operation, etc

In order to change WDE or the pre-scaler, we need to set WDCE (This will
allow updates for 4 clock cycles).

Set the WDCE bit (bit 4) and the WDE bit (bit 3) of the WDTCSR.
The WDCE bit must be set in order to change WDE or the watchdog pre-scalers.
Setting the WDCE bit will allow updates to the pre-scalers and WDE for 4 clock cycles then it will be reset by hardware.

WDTCSR

  1. Setting the watchdog pre-scaler value with VCC = 5.0V and 16mHZ
  2. WDP3 WDP2 WDP1 WDP0 | Number of WDT | Typical Time-out at Oscillator Cycles
  3. 0 0 0 0 | 2K cycles | 16 ms
  4. 0 0 0 1 | 4K cycles | 32 ms
  5. 0 0 1 0 | 8K cycles | 64 ms
  6. 0 0 1 1 | 16K cycles | 0.125 s
  7. 0 1 0 0 | 32K cycles | 0.25 s
  8. 0 1 0 1 | 64K cycles | 0.5 s
  9. 0 1 1 0 | 128K cycles | 1.0 s
  10. 0 1 1 1 | 256K cycles | 2.0 s
  11. 1 0 0 0 | 512K cycles | 4.0 s
  12. 1 0 0 1 | 1024K cycles | 8.0 s