Making Motion Detector Clock


My son is trying to create a digital clock with a motion sensor for a project. He has figured out how to program the arduino to count by minutes (and he hopes to add a second one for hours). He would like to be able to keep the number display off except when the motion sensor turns it out but have it continue to keep time.

Is this possible at all? I have a very frustrated kid in a snowstorm with a mom that doesn’t quite follow all the programming!

Hello @rosiegirl,
Unfortunately, this is not possible with Littlebits.
It’s how they work together.
Each bit has 3 connections, +5V, signal ant ground.
For your project to succeed, you would need to power the number bit apart from the other bits, by keeping the signal and ground connections.
The only way to work around this is to splice a Littlebits wire, cut the +5V line and use a standard switch to reconnect or disconnect this 5V wire.
If you are in electronics, you could use the protobit to “break” the wire and make on a breadboard a circuit that will power the number bit when you want it to.

Thanks so much! That’s definitely beyond our capabilities.

Hi @rosiegirl :wave:
Maybe you can use the servo? Set the servo + servo hub + a mechanical arm and some paper in front of the number module. When motion is detected, set the servo to HIGH to expose the time.

Also, since you are using the motion trigger Bit, this article will be useful:

Please keep us updated on your progress.

@JackANDJude So funny, that’s exactly what he’s doing! He was having some trouble with the servo but he seems to have overcome it so i think that’s where we’re headed!

Thank you!

1 Like

hi again @JackANDJude…he has managed to program the server with a piece of fabric to cover and uncover the time. but we haven’t figured out how to program the motion trigger bit yet. we read through the tips and tricks but that doesn’t help with the arduino portion?

1 Like

Try putting an led after the motion trigger so you know when it is triggered. in arduino code, you can use digitalread. Just keep in mind that the motion trigger stays on for around 3 seconds each time it detects human or animal movement. I hope that helps!


Okay, great…tried that and the motion trigger definitely triggers the LED. In the final design that doesn’t have to be there, though, right? Sorry, I’m letting my son figure it all out on his own but I need to be able to steer him if he has questions!

So, he has power --> motion trigger (i18) --> LED (o14, but hopefully we’ll take this out) --> arduinio --> servo

The problem is that the servo stays on the whole time even when the motion isn’t triggered (and now I can tell that because of the LED you suggested). I’m guessing that means he has to program the arduino with the motion sensor somehow?

Right, the led is temporary. Can you please share your commented code and the exact circuit or picture?

This is the current circuit (I’ve also attached a picture in case I’m saying something wrong).

power > motion trigger (i18) > LED (o14) > arduinio > servo

I’m attaching his current code right now, but he hasn’t tried adding code for the motion trigger yet. He said he plans to use an “if” statement with sensor value?

void setup() { //sets up code for loop section

Serial.begin (9600); //begins serial connection at 9600 bits per second

void loop() { //repeats over and over

int pos; //varable for position
int sensorValue= analogRead (5); //variable for next line of code
Serial.println (sensorValue); //reads in on potentiometer value on pin d5
for (pos=50;pos<220;pos+=1) // tells servo to move up 1 degree until position=145
{ analogWrite(5,150); //makes servo go at medium speed

for (pos=50 ;pos<220;pos-=1) { //tells servo to move up one degree until position is at 0 again
analogWrite(5,150); //makes servo go at medium speed

Hi @rosiegirl,
I used the motion sensor a few times and found it is extremely sensitive. You could experiment with covering the sensor with a piece of tape, a paper cone or something else for better result.
See this topic:

Thanks for posting your picture and commented code. It’s really helpful. Definitely limit the motion trigger’s range of sensitivity by using the link @alexpikkert listed.

Let’s simplify things and focus on the servo turning ON only when the motion trigger is on. See the slide switch on the servo? Switch it to “turn” mode.

From the servo product page:

The servo has 2 modes. In TURN mode, the input from other Bits determines the position of the hub – try using a dimmer to set the angle you want. In SWING mode, the servo will move back and forth on its own like a pair of windshield wipers – the input signal controls the speed of the swing. The servo’s range of motion is about 110 degrees.

To get this result:

Try this code:

const int motionTrigger = A0;
const int servoPin = 5;

void setup()
Serial.begin (9600); //begins serial connection at 9600 bits per second
pinMode (motionTrigger, INPUT); // make the motion trigger’s pin an input
pinMode (servoPin, OUTPUT); // make the servo pin an output

void loop() { //repeats over and over

int motionSensed = digitalRead (motionTrigger); //
Serial.println (motionSensed);
if (motionSensed ==1)digitalWrite (servoPin, HIGH); // if motion is sensed, turn servo on to highest position.

else if (motionSensed ==0) digitalWrite (servoPin, LOW); // if motion is not sensed, turn servo off to lowest position.


1 Like

hi again @JackANDJude ! he’s been working on it on his own and the trouble he’s having is that the servo doesn’t always go back to the original starting position and sometimes it moves for longer or shorter times (even with the motion sensor almost completely covered up and no one moving!) here is the code he is using:

void setup() { //sets up code for loop section


void loop() { //repeats over and over

int pos; //varable for position

for (pos=50 ;pos<220;pos-=1) { //tells servo how to move and for how long
analogWrite(5,150); //tells servo how fast to move

for (pos=50;pos<220;pos+=1) { //tells servo how to move and for how long
analogWrite(5,150); //tells servo how fast to move