Enter Your Project for a chance to win a Maker Tool Kit, an Oscilloscope Grand Prize for the project that brings the Most Joy to the Heart, and Gift to Gives! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
As you may recall from a previous blog post about my Connected XMas Trees, I was having some trouble getting the motion sensor to behave properly.
So a few days ago I soldered some headers onto a new Wemos board to test out the motion sensor, and... turns out the board was bad! boooo!
It would not boot up. Connecting the serial monitor showed some sort of startup exception. Not sure if I broke it, or if it came to me that way (I didn't test it beforehand), but considering the $3 price tag, it's not too heartbreaking when the occasional one is a dud. I did drop a tool on it earlier, so it could very well be my fault. The manufacturer didn't specifically mention not dropping tools on them, but it's probably frowned upon.
So last night I had a bit more time at night and soldered headers onto another Wemos board, which I cleverly tested *before!* the soldering. Blink is a handy sketch for that.
Today I was finally able to hook wires up to it and started testing just the motion sensor with the Wemos, and just was not having any luck. The examples don't really mention any need for pull-up or pull-down resistors, so I thought all should be well there, until I saw a datasheet where the example used an Arduino Uno with the sketch using an internal pull-down resistor! hmmmm....
So I hooked up a 10k resistor, because using the Wemos pull-down didn't seem to make a difference. The Wemos seems to have only 2 pins with internal pull-up and pull-down capabilities. From what I found online in random places, it looks like D8 has a built-in 10k pull-down (which didn't work for me), and D3 has a pull-up.
So to make sure, I just used a physical external resistor instead.
And it worked! Looks like I just need a 10k pull-down resistor on the input pin for the sensor and all is happy.
So now I just need to solder a few resistors into that mess of connections and the project should be close to complete!
ps, the other thing I noticed is that I was originally using D4 for the sensor input pin, and then realized that's the built-in LED for the Wemos board oops.
This is what my test setup looks like:
The code:
I've purposely kept it very simple for testing. The LED goes on when motion is detected, and lots of serial output to help debug things.
#define SENSOR D3 int sensorState = 0; void setup() { Serial.begin(115200); Serial.println(); Serial.println(); Serial.println("\n\nStarting...\n"); // initialize the LED pin as an output: pinMode(LED_BUILTIN, OUTPUT); // initialize the pushbutton pin as an input: pinMode(SENSOR, INPUT); } void loop() { // read the state of the pushbutton value: sensorState = digitalRead(SENSOR); // check if motion was detected. if (sensorState == HIGH) { Serial.println("Motion detected!"); digitalWrite(LED_BUILTIN, LOW); // LED on } else { Serial.println("No motion"); digitalWrite(LED_BUILTIN, HIGH); // LED off } delay(1000); }
The hardware:
Previous posts:
Connecting the Tree to the Internet
Next post:
Trees! one with motion sickness...
Motion Sensor Issues, continued
The Connected Trees are Working!
Top Comments