Arduino & Co: Measure, Control, and Hack

Clever Tricks with ATmega328 Pro Mini Boards

By Robert Sontheimer

Foreword

This book is an Elektor Publication, a brand of Elektor International Media B.V. All rights reserved. No part of this book may be reproduced without written permission from the copyright holder, except in accordance with the provisions of the Copyright Designs and Patents Act 1988 or under a license issued by the Copyright Licencing Agency Ltd. The author and publisher have used their best efforts to ensure the correctness of the information, but do not assume liability for any loss or damage caused by errors or omissions.

ISBN (Print): 978-3-89576-515-5

ISBN (eBook): 978-3-89576-516-2

Copyright © 2022: Elektor International Media B.V.

Printed in the Netherlands.

Chapter 1: ATmega Boards

1.1 The Pro Mini Form Factor

This section introduces the Pro Mini board as a cost-effective computer, detailing 5 V / 16 MHz and 3.3 V / 8 MHz versions, the ATmega328P and ATmega168PA microcontrollers, and their pin layouts.

1.2 Uno Versions

Discussion of various Arduino Uno versions.

1.3 LilyPads and Similar

Focus on 16 MHz LilyPads and similar form factors.

1.4 The Nano Board

Introduction to the Arduino Nano board.

Chapter 2: USB Adapter with Serial Interface

2.1 USB Adapters Based on the CP2102

Details on USB adapters using the CP2102 chip.

2.1.1 Project: Universal Serial Adapter Cable

Instructions for constructing a universal serial adapter cable, including tips for neat soldering and usage.

2.1.2 Serial Micro USB Adapter

Information on serial Micro USB adapters.

Chapter 3: Buying Tips

3.1 Local Suppliers and Domestic Mail Order Companies

Information on purchasing components from local suppliers like Conrad Electronic and Reichelt Elektronik, as well as other online suppliers.

3.2 Big International Online Stores

Guidance on shopping at international online stores such as eBay and AliExpress, covering search settings, security, shipping costs, and buyer protection.

3.3 PayPal Payment Service

Details on using PayPal for payments.

3.4 Customs

Information regarding customs procedures.

3.5 Caution: Pitfalls!

Warnings about potential pitfalls, including fake items, false information, and false promises.

3.6 Buying Basic Equipment

3.6.1 The Necessary Tools

Project: The simplest soldering station in the world. This section covers essential tools for electronics projects.

3.6.2 ATmega Boards

Discussion of ATmega boards.

3.6.3 Power Supply

Details on power supplies, including mains power supplies, understanding current and voltage, disposable or rechargeable batteries, lithium-ion rechargeables, warnings about fake batteries, and charge controllers with protection circuits.

3.6.4 Standard Components

An overview of standard electronic components, including resistors (The E12 series), capacitors, LEDs, transistors, buzzers, and jumper wires.

3.6.5 Measuring Tools

Introduction to measuring tools such as multimeters, infrared thermometers, and vernier calipers.

Chapter 4: Optimal Construction

4.1 Construction on Breadboard

Techniques for building circuits on breadboards.

4.2 Point-to-Point Construction

Methods for point-to-point wiring.

4.3 The Thumbtack Technique

Explanation of the thumbtack technique for prototyping.

4.4 Perfboards

Information on using perfboards, including hole matrix, stripboard, and other grid arrangements.

4.5 Construction on Printed Circuit Board

Guidance on constructing circuits on printed circuit boards (PCBs).

4.6 Pin Header Connectors

Details on pin header connectors and coded connections.

Chapter 5: Programming

5.1 The Arduino Platform

Introduction to the Arduino programming platform.

5.2 Our First Program

Syntax: Explains setup() and loop() functions.

Sketch: Provides a first program example.

5.3 Uploading Programs

Instructions for uploading programs to the microcontroller.

5.4 Downloading the Programs

Guidance on downloading programs.

Chapter 6: Board Inputs and Outputs

6.1 Reading Inputs Digitally

Syntax: Variables.

Syntax: pinMode(), digitalRead(), and digitalWrite().

Syntax: Comparisons and conditions.

Syntax: while and do-while loops.

Details on pushbutton switches and a corresponding sketch.

6.2 Reading Analog Inputs

Explanation of reference voltage, VCC as reference, internal reference, and external reference.

Syntax: analogRead() and analogReference().

6.2.1 Measuring Voltages Directly

Syntax: Defining constants.

Syntax: Serial transmission.

Syntax: Calculations and assignments, including calculation pitfalls.

Syntax: Rounding up and down.

Sketch: Measuring voltages up to VCC, with calibration details.

6.2.2 Measuring Using Internal Ref. & Voltage Divider

Discussion of possible ranges and calibration for measuring with internal reference and voltage dividers.

Sketch: Measuring using internal reference & voltage divider.

6.2.3 Measuring Directly Using the Internal Reference

Tip: Commenting out lines.

Details on calibration for direct measurement using the internal reference.

6.2.4 Measuring Current

Sketch: Measuring current, including possible ranges and calibration.

6.2.5 Resistor Measurement

Sketch: Resistance measurement, covering swapping resistors and calibration.

6.3 Switching Outputs Digitally

Methods for switching outputs digitally.

Chapter 7: How Do You Switch Something?

7.1 LEDs

7.1.1 Calculating the series resistance.

7.1.2 LEDs in battery operation.

7.1.3 Switching direction to ground or positive.

7.1.4 Project: LED Effect Board

Instructions for creating an LED effect board.

7.2 Switching Using a Transistor

Details on BC547, BC337-40, and BD435 transistors, including heat tests.

Tip: Heat test.

7.2.4 Switching Using MOSFETs

Information on NTD4906N and IRLR8726PbF MOSFETs.

Tip: Thermally conductive adhesive.

7.2.5 ULN2003A Transistor Array

Details on the ULN2003A transistor array.

7.2.6 ULN2803A Transistor Array

Details on the ULN2803A transistor array.

7.3 Switching Using a Relay

7.3.1 Solid-State Relay

Information on solid-state relays.

Chapter 8: Controlling, Regulating, and Dimming

8.1 Pulse-Width Modulation (PWM)

Syntax: analogWrite().

8.1.1 Project: Dimming LEDs in All Colors

Instructions for dimming LEDs with various colors.

8.1.2 Quick Color Theory

An explanation of basic color theory relevant to LEDs.

8.1.3 Flowing Color Changes

Syntax: sin() and cos().

Sketch: Flowing color changes.

Tip: Small test with LED effect board.

8.2 Low-Pass Demodulation

Explanation of low-pass filters, including time constant τ, calculation, ripple, and two-stage filters.

8.3 Regulation with a Feedback Loop

Concepts of regulation using feedback loops.

8.4 Project: Adjustable Constant Current Source

Instructions for building an adjustable constant current source.

Chapter 9: Controlling Motors

9.1 DC Motors

9.1.1 Transistor Control

Methods for controlling DC motors using transistors.

9.1.2 Speed Control Using PWM

Techniques for controlling DC motor speed with PWM.

9.1.3 Forward and Reverse with an H-Bridge

Controlling motor direction using H-bridges, with details on the L9110S and L298N.

9.1.4 Full Control Using H-Bridge and PWM

Syntax: min() and max() functions.

Sketch: Full motor control.

9.2 Stepper Motors

9.2.1 How It Works

Explanation of bipolar and unipolar stepper motors, full- and half-step operation, and actual stepper motors.

9.2.2 The 28BYJ-48

Control of the 28BYJ-48 stepper motor using a ULN2003 driver board and four transistors.

Tip: Stepper motor under battery operation.

Sketch: 28BYJ-48 stepper motor control.

Chapter 10: Sensors

10.1 Analog Sensors

10.1.1 Brightness Sensor Using LDR

Using a Light Dependent Resistor (LDR) as a brightness sensor.

10.1.2 NTC Temperature Measurement

Sketch: Temperature measurement using NTC.

10.1.3 Analog Joystick

Using an analog joystick with Arduino.

10.1.4 Measuring Light with a Photodiode

Measuring light intensity using a photodiode.

10.2 Digital Measurements

10.2.1 TL1838 or VS1838B Infrared Receiver

Using infrared receivers.

10.2.2 HC-SR04 Ultrasonic Distance Sensor

Syntax: pulseIn() function.

Sketch: Ultrasonic distance measurement.

10.2.3 HC-SR501 Motion Sensor

Information on the HC-SR501 motion sensor and its power supply.

10.2.4 The I2C Interface

Explanation of the I2C interface, SCL and SDA lines, I2C on ATmega328 and 168, including libraries and functions.

Syntax: Including libraries.

Syntax: I2C functions with Wire.h.

Details on I2C sensors and breakout boards.

10.2.5 BMP180 Air Pressure Sensor

Project: Pressure and altitude sensing with the BMP180.

Syntax: Function definitions.

Sketch: Air-pressure sensor and altimeter, including accuracy from double-oversampling.

10.2.6 MPU-6050 Accelerometer

Sketch: Rotation and acceleration measurement.

Chapter 11: Other Components

11.1 RF Remote Control

Coding and antenna considerations for RF remote controls.

11.2 Seven-Segment Displays

Multiplexing techniques for seven-segment displays.

11.2.1 Basic Program for 1 to 6 Digits

Sketch: 7-segment display with several digits, covering int, float, hex, and degree displays.

Syntax: modulo operator.

Sketch: 7-segment display functions.

11.2.2 Project: Voltmeter

Sketch: Voltmeter with 7-segment display.

11.2.3 Project: Thermometer

Sketch: Thermometer with 7-segment display.

Details on thermostat functionality.

11.3 Text Displays with Back-lighting

Information on text displays, including pinouts, functions, controlling text displays, and user-defined characters.

Syntax: Controlling text displays.

Sketch: Example with user-defined characters.

Text display with I2C interface.

11.4 Mini Lasers

Application examples for mini lasers.

11.5 SD Card Module

Connecting an SD card module to the Arduino.

Syntax: SD.h file functions.

Sketch: Reading and writing files.

Chapter 12: Rechargeable Batteries and Accessories

Tip: Soldering round cells.

12.1 Functionality and Handling

Proper handling and functionality of rechargeable batteries.

12.2 Protection Circuit

Information on battery protection circuits.

12.3 Connecting Rechargeables in Series

Methods for connecting rechargeable batteries in series.

12.4 Balancers

Explanation of battery balancers.

12.5 USB Charging Regulators

Details on USB charging regulators.

Chapter 13: Clever Hacks and Tricks

13.1 Measuring Battery Level Without Components

A method for measuring battery level without additional components.

Sketch: Measuring battery voltage without components.

13.2 Arduino in Deep Sleep

Techniques for putting the Arduino into deep sleep mode.

Sketch: Sleep mode (bare template).

Information on waking the Arduino from sleep mode.

Sketch: Sleep mode (with wake-up pin).

13.3 Low-Battery Switch-Off

Implementing a low-battery switch-off mechanism.

Sketch: Low-battery switch-off.

Integrating low-battery switch-off into projects.

13.4 Pro Mini Battery Operation

Reducing current consumption for Pro Mini battery operation.

13.5 Project: Electronic Die

Syntax: EEPROM functions.

Sketch: Electronic die.

Tip: LED effect board as a die.

Dice for cheaters.

13.6 Analog Measurement Without Waiting

Techniques for analog measurement without delays.

Sketch: Continuous analog measurement.

13.7 Project: Universal Remote Control Receiver

Building a universal remote control receiver.

Sketch: 10-channel universal remote receiver.

Tips for accurate clocking of the loop.

13.8 Project: Extreme Altimeter

Sketch: Extreme altimeter.

Details on settings, possibilities, measuring small altitude changes, and weather trend barometers.

13.9 Project: Infrasound Recorder

Sketch: Infrasound recorder.

Weather recorder functionality.

Index

The index provides a comprehensive list of topics covered in the book.

PDF preview unavailable. Download the PDF instead.

Contents Arduino Co ?v=1709136448 iLovePDF

Related Documents

Preview Arduino Uno Experimenting Kit: Programming and Projects Guide
Explore the Arduino Uno Experimenting Kit with this comprehensive guide covering programming fundamentals and practical projects. Learn hardware and software skills through over 60 engaging projects involving LEDs, displays, sensors, motors, and more.
Preview Arduino-Compatible Experimenting Kit: Programming & Projects Guide
Explore the Arduino-compatible experimenting kit with this comprehensive guide covering programming and over 60 diverse projects, from basic LEDs to sensors, displays, and motors. Ideal for learning Arduino hardware and software.
Preview The ESP32 Cheap Yellow Display Book: Projects Using Arduino IDE and LVGL
A comprehensive guide to building projects with the ESP32 microcontroller, Arduino IDE, and the LVGL graphics library. Features practical examples for TFT displays, sensors, and user interfaces.
Preview MakePython ESP32 Development Kit: Programming & Projects Guide
A comprehensive guide to the MakePython ESP32 Development Kit, covering programming and various projects. Learn to master the ESP32 microcontroller with this enhanced guide from Elektor.
Preview IoT Get U Going: Projects with Raspberry Pi and Arduino
A comprehensive guide to building Internet of Things (IoT) projects using Raspberry Pi and Arduino, covering setup, software installation, and various practical applications.
Preview Basic Electronics for Beginners: Analogue Circuits and Microcontroller Projects
A comprehensive guide to basic electronics, covering analogue circuits and microcontroller projects, with a focus on practical applications and learning.
Preview Raspberry Pi Pico W: Program, Build, and Master 60+ Projects
A comprehensive guide to programming, building, and mastering over 60 projects using the Raspberry Pi Pico W and its RP2040 microcontroller. Covers hardware, programming with MicroPython, and various applications including LED projects, displays, sensors, PWM, Bluetooth, Wi-Fi, and RFID.
Preview Raspberry Pi Pico Experimenting Kit: Programming and Projects Guide
A comprehensive guide to the Raspberry Pi Pico Experimenting Kit, covering hardware, programming environments, and 42 diverse projects using MicroPython. Learn to master the RP2040 microcontroller with hands-on examples for electronics enthusiasts.