Post topics, source code that relate to the Arduino Platform

User avatar
By torntrousers
#25173
Barnabybear wrote:
torntrousers wrote:That is interesting. I've wanted to do the same - having a PIR sensor trigger an ESP to wake up, but i didn't find a way to get it working very well.

I've not tried this yet but i wondered if you could connect the PIR output to the ESP CH_PD so when the PIR is triggered it sets CH_PD high so the ESP starts up and then have the ESP set a spare GPIO high and have that also connected to CH_PD so the ESP stays running after the PIR resets, and then when the ESP has done its stuff set the GPIO low and so the ESP powers down.

If you connected the PIR and an GPIO via a diodes to CH_PD you could pull it independantly of the other:
PIR output -->|- ESP CH_PD
GPIO -->|- ESP CH_PD

The PIR should be able to pull CH_PD high to wake the ESP, then the GPIO should be able to take over holding CH_PD high even if the PIR returns to low untill the task is completed.
We proberbly need some resistors (deffinatly if using a -01); a pull down on CH_PD and a something on the GPIO to hold it high for boot up, not enought to deliver a logic 1 after it has passed through the diode during sleep.
I have parts to test if someone wants to wip up abit of code (I haven't used sleep functions yet). Should be able to post a diagram later.


That would be great. The code to test it could be really simple initially, just something like this which should always output just 10 x "loop" even when the pir output goes low before its done:
Code: Select allvoid setup() {
  Serial.begin(115200);
  Serial.println();
 
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
 
  Serial.println("setup"); 
}
void loop() {
  Serial.println("loop");
  delay(1000);

  if (millis() > 10000) {
    digitalWrite(5, LOW);
  }
}
User avatar
By Barnabybear
#25175
That would be great. The code to test it could be really simple initially, just something like this which should always output just 10 x "loop" even when the pir output goes low before its done:

As soon as I finish work today I'll test that & let you know the outcome.
User avatar
By certeza
#25191 I wasn't aware that you could get the esp-12 out of deep sleep by detecting a level change on a gpio pin.
I thought the only way to do that was by resetting the esp-12.
One thing I know is that the esp-12 resets anyway when it wakes up from deep sleep.
User avatar
By Barnabybear
#25204
torntrousers wrote:
I've not tried this yet but i wondered if you could connect the PIR output to the ESP CH_PD so when the PIR is triggered it sets CH_PD high so the ESP starts up and then have the ESP set a spare GPIO high and have that also connected to CH_PD so the ESP stays running after the PIR resets, and then when the ESP has done its stuff set the GPIO low and so the ESP powers down.

Barnabybear wrote:
If you connected the PIR and an GPIO via a diodes to CH_PD you could pull it independantly of the other:
PIR output -->|- ESP CH_PD
GPIO -->|- ESP CH_PD

The PIR should be able to pull CH_PD high to wake the ESP, then the GPIO should be able to take over holding CH_PD high even if the PIR returns to low untill the task is completed.
We proberbly need some resistors (deffinatly if using a -01); a pull down on CH_PD and a something on the GPIO to hold it high for boot up, not enough to deliver a logic 1 after it has passed through the diode during sleep.
I have parts to test if someone wants to wip up abit of code (I haven't used sleep functions yet). Should be able to post a diagram later.


Hi, I can confirm that this does work (on an ESP8266-01 anyway).
Needed: 1x diode, 2x 1K & a 10k resistor.
Applying 3.3v (from the PIR) to the circuit (CH_PD via a diode) booted the ESP, GPIO 0 then holds CH_PD high as long as needed even if the PIR then drops low. When the ESP has compleated its tasks GPIO 0 can be taken low shuting down. As a bonus I was able to read the output of the PIR with GPIO 2, which means I could report it had gone low before shutting down and it gets rid of the problem of needing to invert the PIR output.

Image

I used this code by 'torntrousers', slightly modified.
int val = 0;
int pin2 = 2;

void setup() {
Serial.begin(115200);
Serial.println();

pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
pinMode(2, INPUT);

Serial.println("setup");
}
void loop() {
val = digitalRead(pin2);
Serial.println(val);
delay(1000);

if (millis() > 10000) {
digitalWrite(0, LOW);
}
}


On to the next bit now to mod my code to get this to report to thingSpeak.

EDIT:
Code: Select allpinMode(0, OUTPUT);
digitalWrite(0, HIGH);

needs to be moved up the order to be infront of
Code: Select all  Serial.begin(115200);
  Serial.println();

so that the inital trigger high doesn't need to last untill after the serial connection has been established.
Last edited by Barnabybear on Thu Aug 06, 2015 4:33 pm, edited 4 times in total.