Analog Arduino BJT breadboard laser Microcontrollers MOSFET Multimeter Technology

Bathroom Laser Light project — the analog version


A couple of weeks again, Redditor /u/doakey posted an insanely cool concept to /r/arduino of lighting up his rest room bowl with a pink laser in order that when he obtained up in the center of the night time to pee, he might see the place he was “shooting”, so to talk. And it was a grand success!

Stroll into the toilet. Laser shoots into the bowl. *pew, pew, pew* Lights up the goal like a spotter for some stealth plane to hit with a sensible bomb. Night time imaginative and prescient preserved. Mission completed. Laser turns off. Then you definitely return to mattress.


But, he famous that the 9v battery solely lasted a couple of days. Naturally, a number of of us identified that an Arduino is overkill and that he might have completed this utilizing analog electronics.

And I get it. Analog is fairly arduous. Arduino is comparatively straightforward. There are many assets on the market on the right way to program Arduinos, however analog… properly, it’s type of on its strategy to turning into a “lost art”.

A number of individuals in /r/arduino requested me to write-up my proposed analog verson. After a number of weeks of fiddling, right here’s the analog circuit (and rationalization) I got here up with to breed the similar results…

The circuit is pretty easy, but relying in your background, there may be lots to elucidate. Since quite a lot of individuals with totally different information ranges might be studying this, I needed to make some presumptions on base information ranges. I assumed that you simply already understood the following:

  • Voltage
  • Present (in Amps)
  • Resistance (in Ohms)
  • And by proxy, Ohm’s Regulation  (V = I/R) [V = Voltage, I = Current, R = Resistance]

In case you don’t perceive these ideas, I extremely advocate studying this Wikipedia entry on Ohm’s Regulation.

Or the TL;DR version is:

  • Voltage is like water strain
  • Present is like the quantity of water move
  • Resistance is like limiting water quantity movement (however not strain);

Besides that we’re coping with electrons as an alternative of water molecules. (This analogy holds up fairly nicely for a great deal of electronics with just some exceptions.)

The outcomes of my analog experiment have been a hit. The laser lights up when it detects motion at night time, however doesn’t do something throughout the day. And the battery continues to be going after greater than every week of testing. Voltage is holding regular at four.900v — 1.225v per cell which is about what a NiMH cell measures after a couple of days of being off the charger, however not but actually depleted. Loads of cost left!

Designing the circuit

The primary a part of this was simply determining what was imagined to be occurring. And it’s truly fairly easy.

There are 2 states: Daytime and Nighttime.

  • Throughout the Daytime, nothing is meant to occur.
  • Throughout the Nighttime, the movement sensor is powered up in search of any motion.

This results in 2 extra (sub)states of Nighttime:

  • If Movement, activate laser
  • When movement stops, flip off laser

Redditor /r/doakey chosen this Passive Infrared (PIR) movement sensor and it does an incredible job of sensing movement. It has a sensitivity dial, and a timer dial to state how lengthy to sign after it has detected movement. It additionally has the choice to repeatedly set off when it senses movement.


This PIR sensor within reason low energy (spec sheet says 1.6mA), is pretty low cost (~$1.75 per unit) and takes care of the 2 sub-states at Nighttime. So the arduous a part of this circuit is usually about reliably detecting daytime and nighttime.

Okay, time to point out you the working circuit. It might appear complicated, however it’s not too onerous to know. We’re going to work from left-to-right:


–Click on on the above picture to open an interactive circuit simulation–

(Individuals utilizing the NoScript plugin with their browser might have problem opening this simulation.)

The very first thing to level out is that +5 volts was chosen to energy the circuit. All of the main elements (PIR sensor, Laser, and so forth.) work nicely on 5v. And 4 (four) NiMH AA cells in collection produce approx four.8v. The comparator can work properly under 5v and the PIR sensor works right down to four.5v and the laser additionally works fairly nicely at that degree, too. So this was a sensible choice for batteries.

Stage 1 – The Day / Night time sensor

laser-bathroom-schematic-stage1To detect when it’s mild and darkish, a photocell (also called a CdS cell) can be utilized. The photocell modifications its resistance as kind of mild hits it. Particularly, when vibrant out, the resistance is low and when darkish, the resistance is excessive.

Since we’re making an attempt to make use of as little energy as potential, the selection got here right down to utilizing a CdS cell with a excessive resistance. On this case, the photocell has a variety of 500 ohms to 1 Megaohm (1 Million ohms.) As a way to create a sign from this photocell, we have to make a “Voltage Divider” out of the cell by putting a resistor subsequent to it.

As talked about beforehand, resistors solely resist CURRENT movement, however when you could have two resistors in collection, the center level between them creates a “Voltage Divider”. The linked Wikipedia entry explains it properly.

The CdS photocell is represented on this schematic by a potentiometer with one finish not hooked up and the inexperienced arrow. It ought to in all probability be proper about right here on a full-screen net web page ======================>

(Apologies to individuals studying from their telephones…)


On this circuit, we use the photograph cell and a 33kohm resistor to create the divider. Since the photocell can range its resistance, the 33okay resistor on the backside can create a most of ~four.2v and a minimal of round zero.5v. In line with calculations, the circuit on common will draw a mere 60 microAmps (properly, a variety of 5 – 130 uA, relying on how darkish/mild it’s.) Proven right here, the voltage divider creates 1.9v, which is someplace between daytime and nighttime.

That is stage 1 of the circuit. It alerts whether or not it’s daytime (high-ish voltage) or nighttime (low-ish voltage).

However the pure query is: What defines day from night time? The place’s the threshold?

Stage 2 – Evaluating the Day / Night time sign

laser-bathroom-schematic-stage2To resolve this, we transfer to stage 2 of the circuit the place we use a element generally known as a “comparator”. And it does precisely what it feels like: it compares an enter “signal” voltage to a reference “threshold” voltage.

The comparator is represented by the triangle with the (+) and (-) signal. What’s NOT proven right here is that the comparator is powered. Sure, there are literally 2 pins not proven in the schematic that join the comparator to our +5v and Floor (GND) to be able to give it energy.

In the schematic, it’s *implied* that it’s getting energy from someplace. (In our case, +5v and Floor — 0v.) This is a vital idea to know as a comparator solely outputs two voltages: the excessive and low voltages that it’s powered by. In our case, since we feed it +5v and GND (0v), it may possibly solely output +5v and 0v.

You’re in all probability nodding by now since you’re realizing that a comparator can create a HIGH and LOW state (like a 1 or a zero in digital logic.) Cool, proper? Though on this case, we’ll be immediately driving the subsequent stage (the movement sensor) with the 5 volts that it outputs. However we’ll get to that in a minute…

One other factor that must be stated about the (+) and (-) of the comparator is that these inputs are NOT constructive and unfavorable. The plus (+) image represents “non-inverting” enter and the minus (-) image represents “inverting” enter.

So what does this imply?

For what we’re doing right here, this is essential. When it’s daytime (HIGH voltage) we don’t need something to occur. When it’s nighttime (LOW voltage), we would like the magic to occur. That is the actual reverse of the voltage values that we want. An “inverting” enter outputs the reverse worth of the threshold whereas a “non-inverting” enter will output a voltage of the similar “side” of the threshold.

In different phrases, with the “inverting” enter, if the enter worth is LOW-ish, the output can be absolutely HIGH (5v). And if the enter worth is HIGH-ish, the output might be absolutely LOW (0v). In constrast, with the “non-inverting” enter, if the enter voltage worth is LOW-ish, the output worth shall be absolutely LOW (0v). And vice-versa.

We’ll use some numbers to elucidate. Let’s assume that our comparator is utilizing +5v and 0v (GND) for energy:


If we use a reference voltage of two.5v and put it on the (-) enter, if the sign voltage on the (+) is ABOVE 2.5v, we get a HIGH voltage (5v). Whether it is under 2.5v, we get a LOW voltage (0v) out. This is called “non-inverting“.



If we (once more) use a reference voltage of two.5v. This time on the (+) enter, if the sign voltage on the (-) is ABOVE 2.5v, we get a LOW voltage (0v). If under 2.5v, we get a HIGH voltage (5v) out. This is called “inverting“. (The output voltage is on the reverse aspect of the threshold in comparison with the enter voltage.)

As you possibly can see, the comparator makes robust and clear sense of issues (HIGH & LOW) out of issues that could be weak and obscure (HIGH-ish & LOW-ish)

Since we would like LOW (nighttime) to sign HIGH (energy to IR sensor), we ship our enter to the “inverting” enter (-) and we apply our reference threshold to the (+) enter.

Creating the “reference” (threshold) voltage

trim-pot-voltage-dividerAs proven in the schematic, the reference voltage going to the (+) enter is lots like stage 1 the place we created a voltage divider, besides that we’ve used a potentiometer to create a various threshold (as an alternative of the photocell.) Particularly, this can permit the consumer to set a threshold between 1.25v and three.75v.

Perhaps you need the laser to activate when it’s nonetheless considerably mild out, say simply earlier than nightfall. Perhaps you solely need the laser to activate when it is extremely darkish. It’s as much as you. Simply spin the screw on the trim-pot and set the threshold.

Proven at the proper as a inexperienced arrow, the trim-pot (a kind of potentiometer) is about to the center of its vary and is producing a voltage of two.5v for the comparator to make use of as a threshold (or “reference”) voltage.

Stage three – Detecting movement when it’s darkish

At this level, we will assume that it’s darkish out, and levels 1 and a couple of have set the comparator such that we’re getting 5 volts from the output pin. This comparator can solely provide as much as 40mA of present. This isn’t sometimes lots of present, however thankfully for us, our Passive IR (PIR) sensor module solely wants a most of 1.6mA — that is nicely inside the talents of the comparator. Good!


The PIR module has its personal circuitry with 2 potentiometer dials. One to tweak the movement sensitivity and the different to regulate the “hold time” after it has sensed motion. There isn’t a lot to elucidate at this stage as this can be a self-contained module. Simply fiddle with the dials to get the proper sensitivity and an extended sufficient maintain time.

Stage four – Switching on the laser

laser-bathroom-schematic-stage4bThe PIR module outputs a sign of three.3v (HIGH) when movement is sensed and 0V (LOW) when nothing is occurring. To regulate energy, my choice is generally to make use of an influence MOSFET, however once I began studying up on lasers, I noticed that they’re “current controlled” units very similar to LEDs. So I made a decision to make use of a (cheaper) Bipolar Junction Transistor (BJT) in “saturation mode” right here.

Like a MOSFET, the BJT in saturation mode acts identical to a change: On or Off. Though, it nonetheless left me with a simple choice later to restrict the present if it was wanted. (It wasn’t. The laser module had a present limiting resistor on it already.)

A transistor has three pins in contrast to most elements you’ve encountered to date which usually have simply 2. The Bipolar Junction Transistor (BJT) has a Collector (C), an Emitter (E), and a Base (B).

A simplistic method of taking a look at that is that the bulk of the present flows between the Collector (C) and the Emitter (E). And the quantity of present flowing between the Base (B) and the Emitter (E) is what controls whether or not present is allowed to move between the Collector and the Emitter.

The output from the PIR module connects to the base of the NPN transistor. When the sign goes HIGH (three.3v), the transistor turns ON and permits present to circulate from the Collector to the Emitter. When the Sign goes LOW (0v), the transistor turns OFF and present stops flowing.

So we wire the +5v supply to the constructive enter on the laser and we join the floor pin of the laser to the BJT’s Collector. From there we join the Emitter pin of the BJT to Floor. Now the BJT instantly controls the laser relying on the sign it will get from the PIR module.


It ought to be famous that the laser shouldn’t be positioned between the Emitter and Floor as a result of it will forestall the transistor from permitting present to circulate and the laser wouldn’t actually activate. Actually, on this schematic, we’ve got a 100 ohm resistor to restrict present to about 20mA. Although, as talked about earlier than, the laser module already had a present limiting resistor on-board, so this 100 ohm resistor is type of pointless, however it definitely doesn’t harm both.

Measuring the circuit’s present utilization

When designing this circuit, it was pretty straightforward to estimate the energy utilization based mostly on Ohm’s Regulation and studying from the spec sheets, however discovering out the fact of the matter wouldn’t be potential till constructing the circuit. The outcomes from my digital multimeter have been:

  • Daytime, Laser Inactive: ~zero.2mA
  • Nighttime, Laser Off: ~zero.2mA
  • Nighttime, Laser On: ~20mA

As you’ll be able to see, the circuit attracts little or no present when simply sitting round idle. The lion’s share of the present draw is when the laser activates. Thus if utilizing a 4 pack of 2000mAh AA Eneloop rechargeable batteries, this circuit ought to have the ability to idle for 10,000 hours. That’s over a full yr!

Naturally, when the laser is on, it will increase the energy utilization 100x! However when operating 24 hours a day, that’s nonetheless four+ days!

What I discovered fascinating was that the present draw between daytime and nighttime didn’t actually change. Throughout the day it was zero.19mA and at night time is was zero.18mA. Though I used to be not stunned by the CdS photocell drawing much less energy at night time (resistance goes up when darkish), I used to be stunned at how little energy the PIR movement sensor truly used. The spec sheet stated 1.6mA, nevertheless it turned out to be extra like zero.1mA.

What was notably spectacular was how little energy the comparator used:  2.4µA (which was proper about what the spec sheet stated it will draw: 2.1µA)


Yup, 2.four Micro amps. Contemplating the comparator is what we’re utilizing to exchange the Arduino with, properly, now you see why the Arduino (which usually makes use of 45mA per hour) killed /r/doakey’s battery so shortly. The Arduino makes use of 18,000x extra present than the comparator.

Getting present draw even decrease

For those who learn up on Gammon’s Arduino Energy utilization web page, you’ll shortly discover you can get the Arduino right down to tremendous decrease energy utilization modes — similar to what was designed right here utilizing analog circuitry.

Though, it must be identified that you simply do lose a good quantity of performance in a few of these low-power Arduino modes. For instance, disabling Analog-to-Digital conversion (ADC) saves a great deal of energy, however, properly, you’ve simply disabled ADC which you want for the CdS cell to detect the mild ranges.

All the time up for a bit problem, this led me to considering how one can save extra energy in the analog circuit:

  1. Substitute the CdS cell, the 100okay trim-pot, and the different sign producing resistors and voltage dividers with even greater resistance elements. Proper now, they’re utilizing far an excessive amount of present simply to supply easy sign voltages for the comparator. The LTC1440 comparator wants virtually no present to take correct measurements, so this may be a simple option to save extra energy. This might save 50µA or so.
  2. The PIR sensor doesn’t use loads of present when sitting round. 90µA isn’t that a lot, however I’m positive a unique but equally efficient circuit could possibly be discovered that makes use of even much less. This might additionally save 50µA.
  3. The LTC1440 comparator makes use of 2µA. I suppose you can discover one which makes use of 200 and even 20 nanoAmps, however it’s in all probability not value chasing…
  4. After which there’s the laser. That’s the 800-lbs gorilla in the room. (Am I mixing metaphors? Meh, who cares…) That stated, I don’t assume there’s a lot you are able to do about this. It attracts 15 to 25mA.  Perhaps there are extra environment friendly lasers. I’m not a laser skilled. ¯_(ツ)_/¯

Let’s evaluation

laser-bathroom-schematicStage 1: Use Photocell and resistors to make a voltage divider. Provides a variety of 1 to four volts as a “signal” of day or night time.
Stage 2: Join day/night time “signal” to “inverting” enter and set the threshold voltage to the different pin of comparator.
Stage three: The output of the comparator instantly powers the Passive IR (PIR) movement sensor throughout the night time time.
Stage four: When the PIR sensor detects movement, it sends the sign HIGH (three.3v) to the NPN transistor which activates the circuit and shines the laser.


And that’s it! ?

Should you favored this text, please assist unfold the phrase utilizing certainly one of the social networking websites under. Thanks!