element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Merry Boxes & LEDs
  • Challenges & Projects
  • Project14
  • Merry Boxes & LEDs
  • More
  • Cancel
Merry Boxes & LEDs
Blog Motion Sensor on Wemos
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Merry Boxes & LEDs to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ntewinkel
  • Date Created: 5 Jan 2019 2:18 AM Date Created
  • Views 2108 views
  • Likes 12 likes
  • Comments 8 comments
  • wifi
  • merryboxesledsch
  • holidayspecial19ch
  • xmas
  • motion
  • arduino
  • wemos
  • sensor
Related
Recommended

Motion Sensor on Wemos

ntewinkel
ntewinkel
5 Jan 2019
image

Merry Boxes & LEDs

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!

Back to The Project14 homepage image

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 image 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:

image

 

Previous posts:

Connected Christmas Trees

Assembling the Trees

Finally! Two Trees Assembled

Two Trees by a Tree

Connecting the Tree to the Internet

 

Next post:

Trees! one with motion sickness...

Motion Sensor Issues, continued

The Connected Trees are Working!

Merry Boxes - A Project Within a Project

Connected Christmas Trees - Finished!

  • Sign in to reply

Top Comments

  • ntewinkel
    ntewinkel over 6 years ago in reply to mp2100 +4
    Hi Allen, It's a Wemos D1 Mini, with ESP-12 module. Those seem to be more up to code for interference, compared to the ones where all the chips are exposed (ie, no metal cover). I think for them it's best…
  • ntewinkel
    ntewinkel over 6 years ago in reply to mp2100 +4
    oh sorry, missed your other question: > How good is the wemos documentation? Assuming the information is accurate, I did find a LOT of support available online through Google searching. Seems this is a…
  • mp2100
    mp2100 over 6 years ago +3
    Thanks for this Nico. Which wemos board is this? I can’t see details from the pictures. How good is the wemos documentation? Trial and error pull-down resistors makes progress slow. I’ve been planning…
Parents
  • mp2100
    mp2100 over 6 years ago

    Thanks for this Nico. Which wemos board is this?  I can’t see details from the pictures.

     

    How good is the wemos documentation? Trial and error pull-down resistors makes progress slow. I’ve been planning to buy some wemos / lolin from ali express but would like to know how much trial and error I’ll have to go through.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 6 years ago in reply to mp2100

    Trial and error pull-down resistors makes progress slow.

    Good engineering practice is to ALWAYS ensure your inputs are in a known state.

     

    I prefer to use Pull-ups in most of my stuff, simply because you can drive the input from a switch or open collector.

    BUT it also means you aren't switching voltages ... which means no possiblity of shorts or feeding 5v into a 3v3 input.

     

    It does mean your logic is inverted/upside down or opposite, but it's just code.

     

    Arduino and other micros tend to have very high input impedances, which is where you get this 'floating' issue from.

     

    Mark

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • mcb1
    mcb1 over 6 years ago in reply to mp2100

    Trial and error pull-down resistors makes progress slow.

    Good engineering practice is to ALWAYS ensure your inputs are in a known state.

     

    I prefer to use Pull-ups in most of my stuff, simply because you can drive the input from a switch or open collector.

    BUT it also means you aren't switching voltages ... which means no possiblity of shorts or feeding 5v into a 3v3 input.

     

    It does mean your logic is inverted/upside down or opposite, but it's just code.

     

    Arduino and other micros tend to have very high input impedances, which is where you get this 'floating' issue from.

     

    Mark

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube