Sensors for Arduino — A sensor turns a physical quantity into an electrical signal. Pick the right interface, give it a clean supply and convert the raw reading into.

Projects

Sensors for Arduino

Sensors for Arduino — A sensor turns a physical quantity into an electrical signal. Pick the right interface, give it a clean supply and convert the raw reading into.

A sensor turns a physical quantity into an electrical signal. Pick the right interface, give it a clean supply and convert the raw reading into something meaningful.

22 November 20267 min read

Bu projeyi gerçekten kurmak istersen parçaları hobidevre.com'dan temin edebilirsin →

Get the parts

If you want to build a real circuit, you can get the parts from hobidevre.com → hobidevre.com →

More build guides: hobidevre.com/blog

Analog, digital and bus sensors

A simple analog sensor produces a voltage that varies with the quantity being measured. The board’s analog-to-digital converter turns that voltage into a number, so the reading depends on the reference voltage as well as the sensor.

A digital sensor gives a clean high or low, often for a threshold such as presence of light. A bus sensor, using I2C or SPI, sends numbers over a shared pair or small group of wires and usually needs a library. Each type asks something different of your wiring and code.

Match the sensor to the question

Start with the question, not the part. Temperature, humidity, distance, light level and motion each have several sensor options, and they differ in range, accuracy, response time and interface.

Check the range against the values you expect. A sensor that is very accurate over a narrow band can be useless for a wide one. Also check how the value is delivered: an analog voltage needs a converter input, while a bus sensor needs a free bus and address.

Power and logic levels

Some boards run at five volts and others at 3.3 volts. A sensor powered from one level may return a signal at that same level, which can be a problem if the input expects the other. Check the logic levels in the datasheet before wiring.

If levels differ, use a suitable level-shifting method. Also confirm that the sensor’s supply current is within what the board can provide; a power-hungry module should have its own regulated supply with grounds connected.

Pull-ups and floating inputs

A digital input that is left unconnected has no defined state. A button is usually wired so that it pulls the input to ground when pressed, and an internal or external pull-up holds it high otherwise. The logic then reads low for pressed.

I2C buses also rely on pull-up resistors on both lines. Many modules include them, but adding a second set in parallel can change the bus behaviour. Check what the module already provides before adding more.

Reading and calibrating values

Raw converter numbers are rarely the final answer. Map them to the range you need, and constrain the result so an out-of-range reading cannot produce a nonsense output. Take several samples and average them when the signal is noisy.

For better accuracy, measure two known conditions and derive an offset and scale from them. A two-point calibration corrects both zero error and gain error. Record the constants in your notes so you can repeat the calibration later.

Wiring and noise

Keep sensor leads short and twist signal with ground where practical. Long wires act as antennas and pick up noise from motors and relays. A small capacitor across the sensor supply, close to the module, often settles an unstable reading.

Every supply in the system must share one ground reference. A sensor with its own adapter still needs its negative terminal joined to the board, otherwise the signal has no meaningful voltage relative to the input pin.

Common mistakes

  1. Expecting a percentage from a raw converter value without mapping it.
  2. Leaving a digital input floating and reading random changes.
  3. Mixing 3.3 V and 5 V logic without checking tolerance.
  4. Powering a noisy motor and a sensitive sensor from the same unregulated rail.

When a reading looks wrong, measure the sensor output with a meter first. That tells you whether the problem is in the wiring or in the code.

Frequently asked questions

Why does my sensor reading jump around?

Noise, a floating input or an unstable supply are the usual causes. Shorten leads, add a decoupling capacitor and average several samples.

Do I need a library for every sensor?

No. A simple analog sensor can be read directly. Complex bus sensors are much easier with a library that handles the protocol.

What does calibration actually change?

It maps raw values onto known physical values by correcting zero offset and scale, so the number you print matches reality.

Can several sensors share one bus?

Often yes, if they support different addresses. Check the address options in each datasheet to avoid a conflict.

Related reading

Practise in the browser

Open a circuit in the simulator and follow the checks. Sign in to save your work.