<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Bits and PCs - Matt's Blog - 2026.05.15

Previous pageReturn to chapter overviewNext page

This blog section contains miscellaneous Arduino/AVR/ESP32/STM32/SAMD code, libraries, sensor evaluations and electronic designs.

Questions and [polite] comments can be sent to info@muman.ch. Generous donations and lucrative business proposals are welcome. And, of course, invitations to wild parties!

New!

Some of the code you will find in this blog is now available on github, and some has been released as official Arduino libraries which you can install from the Arduino IDE. Look for the github author mumanchu. More mumanchu libraries will be available soon.
https://github.com/mumanchu?tab=repositories

death-risk-by-electrocution

See Disclaimer. If using mains power connections, to prevent electrocution you must always use a sensitive residual current circuit breaker (RCD/RCCB) or earth leakage circuit breaker (ELCB). I use a Hager ACA910C Residual Current Circuit Breaker (RCCB), which switches the power off when there's a >10mA imbalance - this is the model they use in hospitals to protect the patients (in case someone is sick or bleeds on the electrical equipment).

 

Tip: Click the blue underlined title to open the blog page

 

Serial RGB LEDs, WS2812   2026.05.14

A while ago, I started a project with a new microcontroller board and wanted use the on-board LED as an indicator. Naturally, I used the familiar digitalWrite(LED_BUILTIN, 1), loaded it into the controller, and suddenly...   Nothing happened!

Looking at the board I realized it was one of those fancy 3-colour LEDs, a WS2812. These are fantastic, but they must be programmed...

 

The Violet (Death) Ray Generator   2025.12.13

In the 1890's, Tesla developed his infamous resonant coil which generated thousands or even millions of volts. When a high voltage is presented to a glass bulb (a Geissler tube) containing a low-pressure gas (air, neon, argon, nitrogen etc.), the gas is ionized and a plasma is generated. The plasma glows with an eerie light, varying from blue to purple to pink, depending on the voltage, current and the gas in the bulb. This is the same effect that drives modern neon lamps, fluorescent tubes and plasma globes.

By the 1920's, the perceived therapeutic effects of high voltage plasmas led to the development of the Violet Ray Generator. This [potentially deadly] device generated a plasma inside various uncomfortably-shaped glass electrodes, which could be applied to the body both externally and internally. I bought an original device made in 1920. When I opened it up, what I found was shocking... ⚡☠

violet-ray-1

 

Reusing LCD Display Panels from Old 3D Printers  2025.11.20

Old 3D printers usually have a nice retro LCD display panel with a rotary encoder, a beeper and an SD card reader/writer. Some also have Reset/Stop and Kill push buttons. The LCDs are usually 128 x 64 pixel graphics displays, or sometimes 4 lines x 20 character text displays. By making a simple adapter and using the Mattlab's code, you can reuse these in Arduino and ESP32 projects.

3d-printer-displays

 

VEML7700 and VEML6030 High Accuracy Ambient Light Sensors  2025.11.01

The Vishay VEML7700 and VEML6030 chips are among the best I2C ambient light sensors. They return very accurate Lux readings over an incredibly wide range, from 0 to over 140000 lux with a resolution down to 0.0042 lux-per-count using the built-in 16-bit A/D converter. (The range is almost as good as the Cheap LDR Lux Sensor :-) They are sensitive to the same range of light as the human eye, so you don't need code to remove the infrared light component from the readings. They also contain a separate wide-range 'white channel' sensor, have 100Hz and 120Hz flicker noise rejection, and excellent temperature compensation.

This post also presents an improved VEML7700 library with non-blocking methods so your program doesn't hang for up to 2 seconds while a reading is taken.

 

AS3935 Lightning Detector Application  2025.10.25

After reading the dramatic AS3935 Lightning Sensor exposé, you will undoubtedly be tempted to write a Windows application for AS3935 configuration and logging, since no such application exists. But to save time, you can use this one...

lightning-detector-app-3

 

MR24HPC1 mmWave Presence Sensor and Application  2025.10.12

Human presence sensors, using millimetre-wave radar technology, are becoming more common and prices are falling. A cheap entry-level sensor is the "MR24HPC1 24GHz mmWave Sensor Human Static Presence Module Lite" from Seeed Studio, which has a detection range of up to 5m. This post describes this Seeed Studio module and provides an improved Arduino library and Windows Configurator to help you get started.

mr24hpc1-app-6

 

AS3935 Lightning Sensor  2025.09.16

Benjamin Franklin nearly electrocuted himself by flying a kite into a thunderstorm. This is not recommended (see Disclaimer, again). Now you can use the Franklin Lightning Sensor™ chip for lightning detection. "Lightning is a leading cause of storm deaths and causes $ billions of damage." But not if you have a Franklin Lightning Sensor™ chip, which gives you precious time to move yourself and your real estate out of the way of the oncoming storm!

lightning-1     as3935-gravity

 

Ambient Light Sensors  2025.09.12

Want to know if it's dark? Is it bedtime? Are the pubs open yet? To help answer these pressing questions, you could use an "ambient light sensor". But there are better applications for this new technology...

lux-sensor-saturation

 

An accurate Lux meter using a cheap LDR  2025.09.10

Real Lux meters can be expensive. So here are several simple circuits that use an ultra-cheap Light Dependent Resistor (LDR), with C++ code, to measure light and return a reasonably accurate lux value over a wide range. From high power flood lights (>100000 lux), direct sunlight (>50000 lux), down to almost absolute darkness (<0.001 lux). This goes way beyond the range of most lux meters. It's done using a simple voltage divider with a "range selector" resistor to extend the accuracy of the LDR, especially at low light levels.

ldr-3

 

What can I do with an old 'CooCox Embedded Pi' board?  2025.06.26

<i think i'd rather not answer that - ed>

I recently acquired an old CooCox Embedded Pi board. This board made it possible to use a Raspberry Pi to drive Arduino Shields. The board is actually quite nice, with an STM32F103RBT6 MCU (Arm™ Cortex™ M3 core) running at 72MHz, 128KB flash, 20KB SRAM (a bit small), 12-bit ADCs, a JTAG/SWD debug port and 5V-tolerant inputs. It has standard Arduino headers, plus a set of parallel "EPI Extension Interface" headers that provide access to almost all the other pins of the STM32F103. It's a useful board. I decided to find out if I could program this board with the Arduino IDE...
 

embedded-pi-1

 

MCP23xxx 8/16-Bit I2C/SPI GPIO Expander  2025.06.23

So your microcontroller only has 10'000 inputs/outputs and you need 10'016? Well, here's an easy solution, with streamlined source code in C++ and solutions to the chip's "idiosyncrasies". There is also source code for the 8-bit PCF8574 expander, and a super-fast super-cheap example using a bit-banged Shift Register chip.

mcp23017-1 mcp23017-2

 

Mains A/C Voltage Zero-Crossing Detector   2025.05.09

When doing Triac phase control with a microcontroller, the turn-on or turn-off points are timed from the zero-crossing point of the A/C mains signal. If you're switching large loads on or off it's best to switch them at the zero-crossing point. For these applications you'll need a reliable way to find the zero crossing point of the rising and falling edges of the A/C mains waveform. This post describes an easy way to do it using minimal hardware and a small amount of microcontroller code (C++). I also found an Arduino SAMD problem when calling micros() from an interrupt handler - it sometimes returns a time which is -1000 microseconds out!!!

zero-crossing-11

 

TTP229 Touch Pad   2025.05.06

The TTP299-BSF is a capacitive sensing chip for touch pad controls. You can buy ready-made modules from between CHF1 and 5. These run on 3.3 or 5V. However, there is a small problem. The serial communications is not I2C or SPI, it is a 2-wire interface with clock and data signals but no I2C address frame. To start, it toggles the data line low/high, then each data bit must be clocked in on the falling edge of the clock signal. The start pulse is only 70..100µS (it is 70µS on my module). This is much too short to be polled - most pulses would be missed if the microcontroller is doing anything else at all. The few Arduino libraries that I found all use polling, so they do not work if your microcontroller is doing something else when a key is pressed or released. Polling means you can just clock out the bits at various intervals to get the current state of the keys, ignoring the 'data valid' DV signal (the start pulse). To solve this problem, the code in this post uses an interrupt to detect the DV signal.

ttp229-4

 

Infra-red Reflective Sensor TCRT5000  2025.04.17

Circuits, C++ code and a calibration procedure to improve the accuracy and stability of the incredibly cheap TCRT5000 sensor. There's also a few utility functions, such as a debouncer, and float- and double-to-string converters which are faster and smaller than the Arduino's dtostrf().

IR reflective sensors have a IR LED and an IR sensor transistor which senses the reflected infrared from the LED. These can be used for proximity sensing, crude distance measurement, limit switches or RPM measurement.

tcrt5000-1

 

Temperature Sensors 2025.03.12

This post provides circuit details and C++ code examples for several temperature sensor types: NTC thermistor, PT100/500/1000 sensor, LMx35 precision analog sensor, DS18xxx 1-wire digital sensor, LM75x digital temperature sensor, MCP9808 maximum accuracy digital sensor, D6T1A01 MEMS thermal imaging sensor, ... With C++ example code for Arduinos, easily adapted for ESP32, etc. I'll add more sensor types whenever I use a new one.

If you are working with MOSFETs and other components that can overheat, it's a good idea to use temperature sensors in your prototypes to monitor the components. MOSFETs and chips can operate safely at temperatures up to 160ºC or higher, so high temperature sensors must be used. High-voltage high-current projects are prone to overheating if they are left running for too long, so permanent temperature monitoring is mandatory. Low-cost RTD sensors (Resistance Temperature Detectors or Resistive Temperature Devices) are ideal for this, some with ranges up to 600ºC (but hopefully your MOSFETs won't get that hot).

Sometimes temperature compensation is needed for sensitive circuits. Precision calibrated integrated circuit sensors are best for this, like the analogue LM135/235/335 or the DS18B20. These have a smaller range and a lower maximum temperature, something like -30..+125ºC, so you can't use these to prevent overheating...

 

5V to 3.3V Logic Level Translator Using 74HC4050N  2025.03.13

Many microcontrollers run with 5V logic, like the Arduino Uno and the ATMEGA 2560, but these days most chips and modules use 3.3V. Unless the 3.3V device has '5V tolerant' inputs, you cannot connect a 5V device to these 3.3V inputs without risking damage. To connect these together you need a logic level translator like the 74HC4050 to drop the signal's voltage from 5V to 3.3V.

mm74hc4045n

 

Insanely High Voltage! (See Disclaimer.)

Coming soon. The most deadly project you could ever imagine, with a TV flyback transformer...
https://muman.ch/muman/arc-discharge-from-flyback-transformer-a.mp4

and a smaller version with a 555 timer, a MOSFET and a 20kV transformer from ebay...
https://muman.ch/muman/arc-discharge-from-555-a.mp4

 

Mains Voltages and Isolation Transformers - WARNING!

An isolation transformer is often recommended when working with mains-powered electronics - but if you use an isolation transformer, then YOUR SAFETY ISOLATOR* WILL NOT OPERATE if you accidentally touch a live part of the circuit!

Most of the time you will be far safer with a safety isolator instead of an isolation transformer!

* Safety Isolator = Residual current device RCD/RCCB, earth leakage circuit breaker ELCB, ground fault interrupter, etc. I use a Hager ACA910C Residual Current Circuit Breaker RCCB, which switches off with a >10mA imbalance - it's the model they use in hospitals.

Everyone who works with mains-powered devices should read this article
https://sound-au.com/articles/iso-xfmr.htm

 

Making a single-sided PCB using a cheap CNC 3018 router (a 2-transistor TTL-RS232 converter)  2024.11.09

I recently purchased two PCD7.D100 industrial terminals and two PCD7.D200s. I designed the D200 back in the early 1990s, and wrote the firmware for it, so it was nice to find some for sale. These are RS232 devices (the prehistoric ±12V serial protocol), so an adapter was needed to run them from 3.3 or 5V microcontrollers. People usually use a MAX3232 chip for this, but I discovered a simple 2-transistor circuit that works very well. I made the PCB with a cheap 3018 CNC machine, using KiCad, FlatCAM and Candle software. This section describes how to make simple single-sided PCBs using a CNC machine, so I don't forget how to do it. It's also useful for beginners, so they won't make the same mistakes that I did.

ttl-rs232-pcb-populated

 

Optically Isolated Ignition Coil Spark Generator (30kV)  2024.02.10

If you have an old ignition coil lying around, it's very easy to make a 30kV continuous spark generator. Perfect for your Frankenstein laboratory in the basement.

ignition-coil-driver-3

 

The Mighty Ohm Geiger Counter Kit and other stories (updated 2025.03.06)

Everything you will ever need to know about Geiger counters, featuring the Mighty Ohm kit. Plus my own ESP32-based Geiger counter design, with circuits and code.

nuclear-ex-plosion

 

Using Frequency Modulation to regulate a DC control voltage - FEZ Duino C#

A PWM-driven R/C circuit can be used to produce a feedback-controlled DC voltage (0..~2V), which can be connected (usually via an opamp for high to low impedance) to a controlled circuit. It was written in C# for the GHI Electronics FEZ Duino microcontroller. It's been very useful for projects like intelligent power supplies, motor speed control, and anything that needs an analogue voltage to control it, when you don't have enough D/A outputs. Very similar code can be used to control MOSFET switching. It's also very easy to isolate via an optocoupler.

 

M5Stack 8ANGLE Potentiometer and LED module - Arduino C++

This module has 8 potentiometers, 9 multi-coloured LEDs and a toggle switch. It has an I2C 2-wire interface ("Grove" connector), and works with 3.3 or 5V controllers. It's been particularly useful for manually tuning PID loops, with coarse and fine controls.

m5stack-8angle-1

 

LCD Character Display with I2C interface using PCF8574 - Arduino C++ and FEZ Duino C#

For LCD1602 and LCD2004 displays. These displays are very cheap, and very easy to use. The display usually runs on 5V (but now you can get 3.3V versions). If you add the I2C adapter, you can connect it to a 3.3V controller if you replace the 5V pull-ups, as described in the article.

lcd1602

 

Yet Another Universal Motor Speed Controller - Arduino Zero

Want to do something interesting with your old washing machine motor?
Circuit diagrams and C++ code for Arduino Zero, coming soon!

universal-motor-controller-1

 

Infrared Remote Control receiver with repeat key handling - Arduino

IR remote control of your controller is very easy to implement with a cheap IR receiver module. Instead of just using a bare LED, use a module that contains the photodetector, preamplifier and filters in the same package, like the Vishay TSOP4838 which works on both 3.3V and 5V controllers. There is a very nice Arduino IRremote library which handles almost all remote controller types. But it doesn't handle "repeat keys" very well, or keys which should not repeat. Here you'll find some simple code to do this for you.

 

Incorrect pinouts for Chinese TL431 SMD Shunt Regulator chips. The Reference and Cathode pins are swapped!

I recently bought a box full of MeanWell 9V power supplies. When I drew the circuit, I couldn't understand how it was working...

 

A Computer-controlled Precision Coil Winding Machine for less than $50

A cheap CNC router or 3D printer provides almost all the components you need to build a computer-controlled coil winding machine.

 

Retro...

WinForms: How to center a MessageBox over its parent window C#

Windows Forms is old, but is still widely used. The MessageBox.Show() method puts the message box in the center of the screen instead of in front of its parent window. This is very annoying, especially on a large screen. Many people have struggled with this problem over the years. Here is a very simple solution.

 

 

<to be continued, when they let me out>