Kategori: Electronics

The color mix master

A while back a friend asked me if I could build a custom toy for a little guy called Oscar. She said something in the lines of ”The little guy is crazy about knobs, button, switches and blinking lights. You know, the same stuff that you like.” Of course I could not pass up an opportunity to lead a new requite towards the world of electronics so I accepted. Now it’s finished and the Color mix master is born.


The basic function is that the six RGB diodes on the top is controlled by the knobs, switches and buttons below. The color mix master has 5 modes which can be cycled between by pushing the buttons at the bottom.

Mode 1

In mode one the three switches works as a way to input a binary number. The LED that correspond to the number set by the switches is lit up correspondingly. The three knobs that are colored red, green and blue can be used to set the hue of the LED.

Mode 2

In mode two the three switches works as a way to input a binary number just as in mode one. But what is different in mode two is that the all LEDs up to the number that correspond to the number set by the switches are lit up. The three knobs can be used to set the hue of the LED.

Mode 3

In mode three the switches works just like in mode two but LED color is a fading rainbow and the knobs have no function.

Mode 4

In mode four the switches works just like in mode two. The LED color is a some random sparkles in different colors and the knobs have no function.

Mode 5

In mode five the switches works just like in mode two. The LED color is a dot moving back and fourth between left and right with a fading rainbow trail and the knobs have no function.


The case of the color mix master is an old router that I have spray painted red. It had plenty of room inside after ripping out the old circuitry.

The LEDs are through hole APA106 LEDs and they function in all essence like the WS2812B that is sold by Adafruit under the name Neopixels. They have the nice ability that you can address each diode individually using only one output from the microcontroller. Each diode has a data in, data out, GND and 5V. The diodes are connected one after another where the output from one diode is the input for the next. To make the spacing between the LEDs match the holes I had drilled in the case I made a little jig with the same spacing between the holes as in the final case to use while soldering.

The microcontroller is an Pro Mini, it has the same Processor as the Arduino, ATmega328P, but it doesn’t have USB or a voltage regulator, this makes it bit cheaper but you have to take care of the usb communications and power control your self. To provide 5V power I used a standard LM7805 voltage regulator and a 9V battery. The LEDs shouldn’t be powered from the microcontroller directly because they consume quite a lot of power and you would risk damaging your microcontroller. Instead you can run power to the LEDs directly from the LM7805 as long as you remember to connect the ground to the same rail as the microcontroller is using. If you would like to build a similar device based on my code any microcontoller that can be programmed with the Arduino IDE can be used just as long as it has at least 6 Digital IO pins and 3 analog input pins.


The software is a real hack. It was done in haste to be ready for christmas and can be improved greatly. I had problems to get the debouncing library to work so every time I pressed the button it registered as two presses. There are also unused methods etc. but hey it works! The LEDs are controlled by the excellent fastled.io library. The code is available at my github: https://github.com/clarholm/Color-Mix-master

T-1000c, Killer robot chickens from the future

This easter the city has placed two giant chickens made from twigs outside my house as an innocent easter decoration. I however immediately recognized them for what they were; T-1000c:s, killer robot chickens sent back from the future! All I needed to complete the transformation was the telltale red glowing eyes.

I set out to complete the transformation. Since I did not expect to get what ever i built back again, I decided not to use any expensive components. I also wanted the eyes to turn off during the day to save battery.

What I came up with was a simple circuit, where a transistor acts as a switch and switches depending on the resistance of an LDR (Light dependent resistor). This way the eyes turn on at night when it´s dark outside, and off during the day.


  • 1 x 2n2222 Transistor
  • 1 x LDR that varies between ~6k ohm when exposed to light and ~60k ohm when it’s dark
  • 2 x red LEDs
  • 1 x 20k ohm resistor
  • 2 x 48 ohm resistor
  • Some perfboard and wires
  • 1 x 50 cm (20 in) stick
  • 2 x 1.5V alcaline batteries
  • Duckt tape

I taped together the two batteries with some aluminium foil, and placed them between the poles to make solid contact . I then waterproofed everything with duct tape and installed the whole thing by showing the stick through the head of the chicken.

So happy easter from jenslabs and the T1000c!


I have always wanted to use an accelerometer in a project, so when my daughter Beatrice was born I knew exactly what to build; The Hypno-Jellyfish! The Hypno-Jellyfish is a jellyfish-shaped toy filled with RGB LEDs that changes color when you move it. So if you have just become a father, (or want to give someone else a very personal/strange gift), this is the project for you.

Design requirements

When designing a toy for a baby you need to understand the intended users modus opperandi.

1. If it fits in the mouth, it will go in the mouth.

  • Has to be free of toxins
  • No small parts that can be swallowed
  • All parts that can be touched by the user has to be waterproof

2. If it can be pulled it will be pulled with as much force that can be achieved by a 0 year old.

  • Needs to be built to handle some serious pulling.

3. If it can be dropped on the floor it will be thrown on the floor repeatedly and you have to pick it up over and over again.

  • Make it undroppable or very sturdy.

4. Blinking lights are beautiful and will be stared at intently.


Step 1

To remove as much sensitive parts out of Beatrices reach as possible, I decided to go with a two part design. The first part contains the Arduino and the battery, this part will sit on top of the babygym and out of baby reach. The other part is the jellyfish, constructed from polymorph plastic, that contains the Neopixel ring and the accelerometer.

To achieve a sturdy connection between the two parts that would hold for design requirement 2, I made use of some paracord where I replaced the center strands wires from an ethernet cable. I could only fit two wires in each paracord mantle, so to get the 6 connections I needed, I had to use three pieces of paracord with two wires in each mantle. I then braided the paracords to make one wire. This way all mechanical stress will be picked up by the paracord and the wires will hopefully stay soldered in place.

Step 2 – Electronics

The accelerometer (MPU6050) is connected to the Arduino Nano with five wires.

  • MPU6050 – Arduino
  • VCC – 3.3V
  • GND – GND
  • SCL – A5
  • SDA – A4
  • INT – D2

The NeoPixel ring only needs VDD (PWR), GND and a DATA in. I chose to power the Neopixel ring from the 3.3V output on the Arduino. In a worst case scenario the Neopixel ring could draw to much power from the Arduino, but to save on the number of parts, and also number of wires, I decided to try it and it worked. Ideally I should have used a power regulator circuit to provide power to the Neopixel straight from the battery to avoid overloading the Arduino.

  • Neopixel Ring – Arduino
  • PWR – 3.3V
  • GND – GND
  • IN – 100 ohm resistor – D5

 Step 3 – Making the jellyfish

The jellyfish is made from Polymorph plastic which I bought of BLRTronics on ebay. Polymorph plastic is a really cool material. In room temperature it is hard and durable, but if you heat it to above 60 C it becomes translucent and soft, and can easily be molded by hand. It is non-toxic and is often used in medical implants. However it is not super easy to work with, and when it is soft it tends to stick to itself.

My first approach was to mold body and tentacles from one pice of plastic. As I was almost finished I decided to heat up only the tentacles to give them a final twist. This was a bad decision and all the tentacles got tangled and stuck to each other so I was back to square one again.

To avoid making the same misstake again, I decided to mold the tentacles and the bottom part of the body, (that houses the neopixel ring), as separate parts. I then heated the bottom part of the body and made little knobs with a pair of tweezers where I planned to attach the tentacles. Finally I attached the tentacles to the body by heating only the knobs on the body in some hot water and only the top of the tentacles to avoid a sticky tangly tentacle mess again.

This method turned out to be much more successful. After successfully attaching all tentacles, I attached the Neopixel ring and accelerometer to the bottom part of the body with a small pice of polymorph plastic across the ring and accelerometer. The top part of the body was molded around the paracord to avoid any joints to the body. To make sure all mechanical stress is picked up by the paracord, and not the wires, I made a big knot inside the jellyfish that is to big to pass through the hole. Finally I joined the top and bottom part of the jellyfish with another piece of polymorph plastic that I had heated thoroughly so that it was rely sticky and acted as a glue.

Step 4 – Code

The code is based on the i2cdevlib by Jeff Rowberg and Adafruits neopixel library. The basic concept is to read the position of the accelerometer every 300 ms and compare the result. If there is a big enough change between the current and last value it is considered as a ”movement detected” and the color changes. The code can be found at my github in the Hypno-Jellyfish repo.

If you don’t have any kids or know anyone who has and still want to build one, you can always claim you are going to use it for light painting.

Stockholm Mini Maker Faire 2014

Here are some pictures from the Stockholm Mini Maker Faire 2014. I didn’t have much time to look around during opening hours so most of the pictures are taken before the faire opened on Sunday morning.

The most impressive build by far was done by Jonny Eriksson with his creation popmaskinen (The pop machine). Popmaskinen is an electromechanical one man band. Not suprisingly Jonny Ericsson was awarded maker of the year 2014.

Jonny is a musician/electrician/furniture carpenter and building Popmaskinen was a way for Jonny to put all his skills to the test. The heart of Popmaskinen is the spinning metal barrel called ”taktverket” which translates loosely into the pace keeper. The taktverk was designed by Jonny and then manufactured using a CNC-lathe. Taktverket contains a myriad of little holes into which little bolts can be inserted. As the taktverk spins the bolts that has been inserted into the taktverk hit little switches that in turn trigger one of the instruments to play a note. The function is similar to how a music box works. What note that gets played is controlled by the keys on the main unit and the strumming action is controlled by at what pace the the spinning cylinder is turning at.

To be able to play both in major and minor scales Jonny has built a custom two necked guitar where one of the necks is tuned to a minor chord and the other neck to a major chord. To control the guitars Jonny has mounted electromagnets all along the guitars necks and for the strumming actions. He had to rebuild the guitar three times before he finally got it just right. The casings that houses the mechanics of popmaskinen is built from MDF and the absolutely stunning finish of the surface has been achieved by using car enamel. The estethics of Popmaskinen makes me think of cars from the 1950s and the whole build screams hard work and quality.


Today I have been trying out StippleGen2 by Evil Mad Scientist. Stippling is when you create an image from little dots of the same color but with different sizes and with different density. StippleGen2 is built in Processing and uses an algorithm written by Adrian Secord. To try it out I used this classic picture of Louis Armstrong playing the trumpet. Once you load the picture you want to stipple the StippleGen2 starts crunching numbers and the algorithm continues to refine the result by applying the algorithm over and over again and the resulting image gets better and better.

After letting StippleGen2 crunch the numbers for a while I imported the resulting vector graphic file into inkscape and generated the G-code so that I could use my laser cutter to cut the image into a black paper. 2 hours and 23 minutes later I had a 20×20 cm piece of paper with about a 1000 holes in it and it looks awesome! Would be perfect for a lamp shade or just nice to put up in a window and let the sun shine through. I can highly recommend StippleGen2 it’s super easy and a lot of fun.

What can you cut with a 300mW DIY laser cutter?

I built this laser cutter after being inspired by this laser cutter and the design is almos identical, there for I will not go into details about my build but will instead focus on what you can do with it.

Since the diode (LPC-826) I have used is from a DVD burner and have an output power of 300-400 mW, it can’t be considered very powerful when it comes to cutting lasers. It should not be confused with a CO2 laser which have an output power of 50W, which is the type of laser that is normally is used in professional laser cutters.

The materials I have tried so far are:

  • Adhesive plastic (stickers) – Cuts right through
  • Art Foam/EVA foam – Cuts right through
  • Wood – It burns the wood but does not cut. Can be used for engraving.
  • Paper – Black copy paper can easily be cut but thicker paper does not work. White paper does not work.
  • ABS Plastic – The surface melts so it is possible to engrave but it can’t be cut.
  • Plexiglass – Not a mark.
  • Plasticard – The thinnest sheet I tried could be cut at low speed but only after having been painted black.

Adhesive plastic

This is what I find by far the most useful application for this laser cutter. So far it has been able to cut through any type and color of the adhesive plastic that I have tried. It is quite easy to cut stencils or stickers. I often use it for cutting custom drilling and cutting templates for other projects. If you want to know how to use photoshop to create stencils from pictures stencil revolution has a good tutorial.

I did some experimentation with masking off parts of a steel plate with laser cut stencils and then I created rust by using Hydrochloric acid and Hydrogen peroxide. It worked pretty well however I need to work some more on the proportions between the Hydrochloric acid and the Hydrogen peroxide to get a nice rust coating on the unmasked metall. A word of caution, do NOT do this inside. I did and now I have a nice rust coat on every un protected piece of metal in my lab. Also wear gloves and eye protection. If you want more details about on the method I used to create these look in the comments for the video.

Art Foam/EVA foam

I have not done much cutting in EVA foam, mainly because I have not had any use for it. But if you are building small models and need laser cut parts this laser will get the job done for you.


Wood can be burnt but not cut. So if you are the woodworking type you might have a use for it. Sometimes I have seen that the laser does not start to burn instantly and that it takes a darker part of wood for the laser to get started, once it has started to smoke it goes on burning from that point.

ABS Plastic


When it comes to hard plastics like ABS it can melt the surface but not burn through. So just like it is with wood it is possible to engrave on ABS. The picture shows a quick test and is not the most beautiful thing I have done but it gives you an idea what to expect.


If you are still interested in the hardware here is a quick rundown of the parts.


The whole frame is made from wood and the sliding tray slides on drawer sliders. Both x and y-axis are propelled by an M6 threaded rod.

The coupling between the frame and threaded rod consists of a M6 extension nut that I have incased in Polymorph plastic, Polymorph plastic softens enough to be molded by hand if you put it into boiling water and after it cools down it feels as hard as vinyl, very handy for motor mounts and this type of applications.


Both motors are NEMA17 stepper motors, 200 steps per revolution.


The laser is a MITSUBISHI/658nm-660nm 300-400mw CW Red Laser Diode/LPC-826 that I bought from eBay. It is mounted in a standard 5.6mm Laser Diode housing with a round heat sink. It is powered by a LM2596S based power module with built in current limitation. This way you will not risk feeding the laser to much power.

The LCP-826 diode should be run at an operation current <400mA and operation voltage <2.2V. To achieve this I started by connecting the 12V I use to drive the stepper motors to the IN on the DC-DC step down module. Then I connected a multimeter in Voltage measuring mode to the output on the board and adjusted the potentiometer closest to the input terminal on the card until I had 2.2V on the output. After I hade the desired voltage I changed the multimeter setting to Ampere measuring mode, remember to move the cable, and then adjusted the potentiometer closest to the output until I had a current output of 400mA. The middle potentiometer controls one of the diodes on the charger circuit and you can adjust it to set at what current the diod should light up.

LM2596S DC-DC Step-Down power supply. Picture made by coachlam.

LM2596S DC-DC Step-Down power supply. Picture made by coachlam.


The laser is turned on and off from the spindel on/off pin of the Arduino nano. Spindel on/off is connected to an Logic level Mosfet which enables me to control a 12V signal from the Arduino.

Remember that you should always wear laser eye protection when using this kind of lasers. When I started to build this laser cutter I decided to buy a pair of laser protection glasses. After doing some reading I decided on a pair from dragonlasers.com called LSG08. The LSG08 are designed to block light at the frequency 190-450nm and 598-752nm which covers this laser. I am no expert but from what I found after some reading I wanted a pair that was OD5-6 certified. OD stands for optical density and each step on the scale is a factor of ten. So OD1 will reduce the amount of light of a specific frequency by 10, OD2 would reduce it by 100 etc. Here is a diagram of the LSG08 light blocking properties.

LSG08 OD diagram

I am not saying that the really cheap glasses that you can buy of e-bay for around won’t work but I didn’t want to take that chance. The ones I got from dragon lasers does seem to work very well since I can still see! What is important is that the laser protection glasses are designed to block the frequency of your laser. If you are using a infrared laser then this is extremely important since the light is not visible to the naked eye.


The stepper motors are controlled by two Easy driver stepper motor drivers. The Easy drivers are connected to an Arduino nano which is running grbl 0.8. They are connected as described on the grbl wiki page. Power to the laser is turned on and off using a logic level mosfet.

Limit switches

I have connected two micro switches to both sides of the x-y table, the limit switches as they are called serve two purposes.
1. Stop all movement if the end of the x-y table is reached.
2. Serve as indicators for the homing sequence.
The homing sequence is used when starting up the cutter to find the starting point every time you start. When you initiate the homing sequence the machine will run both motors until both switches in the negative directions are triggered. Then the motors will reverse direction and run slowly until the switch is released and that is the starting point. The homing sequence is initiated by sending the command $H to the controller and most G-code sender applications has a button to initiate the homing sequence.
One very very important thing to have in mind when using grbl as a base for a laser engraver is that you have no z-axis. However the homing mechanism used in grbl expects the limit switches for all three axis to trigger, there for you have to wire a pushbutton to serve as your z-axis during the homing sequence. If you don’t have the faked z-axis limit switch, which you manually push, the homing sequence will never finish. An option to get around this would be to wire one of the x or y axis limit switches to the z-axis pin so that it serves as switch for both.
The limit switches are simple normally open micro switches that you wire from ground to pin 9 (x), 10 (y) and 11 (z) on the Arduino.


For software I use UniversalGcodeSender-v1.0.6 to send the gcode to the Arduino that has been loaded with grbl 0.8. To create the gcode from an image I use Inkscape together with the LaserEngraver plugin. The whole procedure is very well documented in this instructable written by Groover.

Ketosense – An Arduino based ketosis detector

In this post I will go through the hardware and software of the instrument I have made. If you are curious to why I have made it, I would recommend that you start reading the other posts I have done about this project and work your way forward. Just click on Ketosis detector under categories.


The instrument´s purpose is to detect the amount of acetone gas that is present in a persons breath.

By measuring the amount of breath acetone gas present in a persons breath, it should be possible to determine wether or not a person is in a state called ketosis. Ketosis is, very simplified, when the body runs on fat rather then carbohydrates. If you eat a ketogenic diet, your ketone levels will be elevated. Currently, the only way to monitor your ketone levels are either to take a blood based test or a urine based test, with test strips that changes color depending on the amount of ketons that are present. Both methods work fine but the blood method is very expensive, about 2$ per test, and the urine method is not very precise. Being the curious type of person, and getting inspired by a podcast where Steve Gibson was talking about building an instrument like this, I decided to give it a shot myself.

On a very high level, the instrument consists of an electrochemical gas sensor that is sensitive to various types of gases, a combined hygrometer/thermometer and an Arduino Uno board. The electrochemical gas sensor and hygrometer/thermometer has been placed in a plastic case that serves as a ”gas chamber” that you blow into to collect the gas sample. If there is gas present in the air, the resistance of the sensor will decrease. The decrease of resistance is dependent on three factors; gas concentration, humidity and temperature. If these values are known, it is possible to calculate the gas concentration in PPM (parts per million) using the data sheet provided by the manufacturer.

Does it work?

I don’t normally eat a ketogen diet, but in the name of science and curiosity I gave it a shot. Over the last two weeks I have and taken measurements with the Ketosense and compared them to the results from urine test strips. During the first 10 days, I ate a strict ketogen diet consuming less then 50 grams of carbohydrates a day. I took a reading each morning before breakfast, and one right before going to bed. However, the urine test strips does not have a very granular scale, so it is difficult to say what the exact concentration is  when you go above 1,5 mmol/l. The steps of the Keto-Diastix are 0, 0.5, 1.5, 4, 8 and above 16.

The measurements taken with the Ketosense actually correlates a lot better then I expected to the reference measurements from the Keto-Diastix. This means that the hypothesis that it is possible to calculate ketone levels based on the amount of acetone present in a persons exhalation, seems to be sound. One realization I had was that you have to eat very large amounts of fat to really get the ketones going, it was not until I started to eat a few spoons of 100% coconut fat a day that I reached higher levels of ketones, (witch can be seen around measurement 17 in the graph).


Main Unit


Total price for the components is about 30$.

TGS822 – Electro chemical gas sensor

This sensor works like a resistor, the higher the gas concentration is, the lower the resistance gets. It has 6 pins, the two middle pins are the power to the internal heater and the other are the resistor connections. There are two pairs of resistors connectors called ”A” and ”B”, but they are essentially the same so I just soldered them together. It is very important that the power provided to the internal heater is exactly 5 Volts, or else you risk damaging the sensor. I used an LM7805L voltage regulator to provide the power for both the TGS822 and the DHT11 sensor.

This sensor is far from ideal to be applied in an application as this, it is slow to start, sensitive to humidity and temperature, sensitive to many other gasses other than acetone, and almost impossible to calibrate without special equipment. A wisdom I can pass on, is that one of the gasses the TGS822 is sensitive to is ethanol so don’t try to demo or measure your breath acetone during a dinner where there is wine served. The sensor is so sensitive that it goes bananas if you just have a glass of whine next to it.

The TGS822 is connected to the Arduino on analog pin 0 in parallel with a 10k resistor to create a voltage divider circuit.

DHT11 – digital temperature and humidity sensor.

I added the DHT11 sensor because the characteristics of the gas sensor changes depending on temperature and humidity. Since a persons breath is both humid and warm, it was necessary to factor that in when trying to determine the gas concentration. At first I had placed both the gas sensor and the temperature and humidity sensor close to each other. This turned out to be a mistake since the heater in the gas sensor heated the air around it, thus drying out the air and elevating the temperature. To avoid this, I moved the temperature and humidity sensor to sit as far away from the gas sensor as possible.

The DHT11 is not very fast, especially when it comes to humidity. It can take about 2-3 minutes before the humidity reaches it’s max value. This presents a bit of a problem when it comes to scaling the reading from the gas sensor, depending of humidity from the DHT11. The gas sensor reaches it’s max value just seconds after you finished blowing into it. So if you read the DHT11 at the same time as the gas sensor reaches it’s max value, the humidity value will be to low because the DHT11 is slow.

After blowing into the instrument a couple of times I noticed that the temperature and humidity of a persons breath was stabile at around 60% humidity and 28-29ºC. After realizing this I hardcoded the temperature and humidity to those values to get the scaling right without having to wait for the DHT11.

The DHT11 sensor is connected to digital input pin 10.

16 x 2 Character LCD Display Module

The display is wired as such:

RS: Pin 2
EN: Pin 3
D4: Pin 4
D5: Pin 5
D6: Pin 6
D7: Pin 7

I used the LCD crystal library by David A. Mellis, Limor Fried,  and Tom Igoe to control it.


There are three switches on the Ketosense. One to trigger a reset cycle of the gas sensor, one to reset read max value and one to toggle between the result being displayed as PPM or mmol/l.

resetMaxSwitchPin = 13;
resetSensorSwitchPin = 12;
toggleModeSwitchPin = 11;

Mouthpiece case

When choosing a case to use as a mouthpiece, make sure it is easy to open to be able to ventilate all gas in between readings.

Breadboard view of the whole circuit



This is my first time doing anything with an Arduino so I learned as I went along, the code is not very pretty and I am sure that there are many better ways to get it done, but this way works good enough for me. The code is available at my Github, it is perhaps not super clean but I will try to explain the concepts in words here to perhaps make it a bit more understandable.

Initiation and reset sequence

As I mentioned in the hardware section, the TGS822 sensor is quite slow. When you power on the Ketosense it can take up to 10 minutes before the sensors resistance is stabile, so to determine if the sensor is stabile, readings are taken continuously every second and compared. If the reading changes less then 5 steps over 20 seconds, the sensor is determined to be stabile otherwise the sequence restart.

After a person has blown into the Ketosense it takes a few minutes for the sensor to reset, so the same method as described above is used to determine if the sensor is able to do another reading. This is triggered by pushing one of the buttons.

On the left you can see the Ketosense while it is in startup mode waiting for the sensor to become stabile. On the top row H = current humidity, T = current temperature and i = what step in the 20 second cycle the algorithm that determines if the sensor should be considered stabile is at. On the bottom row the Max and Min value detected on when reading the voltage from the sensor, if the sensor is to be considered stabile and ready to use to take a measure the difference between these two values has to be less then 5. After the sensor has been considered stabile the user is prompted to start the measurement by blowing into the mouthpeice.

Making sense of the readings from the TGS822

The only info I had about the TGS822 was what was written in the datasheet. I wrote a post a little while back called ”Calibrating a Figaro TGS822 sensor, by drawing…” so take a look at that if you want to know more about my thoughts on how to use the info in the data-sheet.

Since I feed 5V to the sensor and it is connected in a voltage divider circuit with a 10k resistor the voltage going into the A0 port of the Arduino is between 0-5 volts. The Arduino then divide it into 1023 parts so the value I actually read from the sensor is a voltage where every step is a change of 5/1023 = 0,0048V.

To get the resistance of the corresponding to the voltage read use this formula:


To find the relation between resistance and gas concentration I did some regression analysis using libre office. I found out that a reasonable approximation to the ppm vs voltage can be achieved with the functions:

if resistance is between 50kΩ & 3600Ω
logPPM = (log10(tempResistance/R0)*-1.5512)+2.5911
PPM = pow(10, logPPM)

if resistance is below 3600Ω
logPPM = (log10(sensorResistanec/R0)*-0.9768)+2.4906
PPM = pow(10, logPPM)

How I went about calculating my sensors R0 is described in the post called ”Calibrating a Figaro TGS822 sensor, by drawing…” I noticed that in the graph for gas vs resistance in the datasheet, it stated that in Air the resistance is ≈ R0 * 19, so I simply divided the startup resistance of the sensor  after it had stabilized with 19 and went with that.

calculated value vs datasheet graph


I applied the same reasoning for temperature and humidity graph and there the function is:

scalingFactor = (((Temperature * -0.02573)+1.898)+((Humidity*-0.011)+0.3966))

The last thing to do is to convert from PPM to mmol/l since that is the most common unit when talking about ketone levels. Im not entirely sure that I got it right but it seems to give reasonable results.

float ppmInmmol = (((float) PPM / 1000) / 58.08);
ppmInmmol = ppmInmmol * 1000;

58.08 is the molar weight of acetone.

Fine tuning the scaling function

After doing the 14 day journey into ketosis I had enough data so tune my original scaling functions to fit the reference of the Keto-Diastix.

logPPM = (log10(sensorResistance/R0)*-2,6)+2.7
PPM = pow(10, logPPM)

I also updated the R0 from 3000 to 4500.


Collecting the measurement

After the Ketosense has started and is stabile, the display prompts to the user to blow into the mouthpiece to start. Actually the measuring has already started, even before that point, however the screen is only updated once the sensor is reading changes and thus indicating that someone is blowing into the mouthpiece. The samples are taken three at a time with 5ms between them and compared to each other. For a measurement to be considered valid, all three samples has to have the same value. This is to minimize the risk for an unexpected voltage rise that would give a false indication as a max value. If a sample is considered valid it is then scaled based on humidity and temperature. As I wrote in the hardware part, the humidity is hardcoded to 60 and the temperature to 28 due to the DHT11 sensor being much slower then the gas sensor, thus causing the scaling to be wrong if both sensors are being read at the same time.


Every time the collected value is valid, (3 samples after each other that are the same), the screen is updated. The current reading is displayed on the bottom row as ”Now:” If the current value is greater then the last one, the ”Max:” is also updated. Typical behavior is that during the first 30 seconds after someone has blown into the Ketosense mouthpiece the max value keeps increasing, therefor the gas collection chamber is crucial to give the gas sensor time to react. It is possible to tell when the actual max value has been reached since the ”now value” is decreasing and is lower than ”max value”.

To reset the instrument to make it ready to use for another measurement, remove the cover of the mouthpiece to ventilate the current sample and then push the reset button to trigger the same sequence as during startup to detect when the sensor has been reset. The reset button is actually the little nut (button) in the middle beneath the dispalay, (the microswitch was not tall enough to reach out of the case, so I extended it by gluing a nut on top of the switch). The nut on the left is to switch between displaying the result as PPM or mmol/l and the one to the right to reset the current max value.


I would not go as far as to claim that my instrument works, It is tricky to decide if it does since I don’t have a reliable way to get a reference other then the keto-diastix, (and those are not exact enough). But I will go so far as to say it looks promising.


If I had access to an instrument reading blood ketone levels, it would be possible to further improve the scaling functions relative to that. Take one measurement of blood ketone levels, and then blow into the Ketosense and write down the raw voltage from the TGS822 rather than the scaled value. Do this for a couple of different values and do some regression analysis on the results and I would have a function that was entirely adapted to my sensor and to displaying ketone levels. However I am not prepared to spend money on a blood ketone level measuring device, but perhaps someone else will after having being inspired by this post.

Another application for this device is actually a breath alcohol detector, since the sensor is actually sensitive to ethanol as well as acetone.

Sources and additional information

I found three different data sheets for the sensor while searching:

DIY graphene videos

In the recent days videos from people who actually made some DIY graphene has started to pop up on youtube and in this post I will introduce you to a few of them.

Robert Murray-Smith

One of the very first people who I think deserves a mentioning is Robert Murray-Smith. Robert is a MacGyver of DIY chemistry and he would of course not be doing something as trivial as buying graphite oxide when you can make it your self from graphite. Robert has posted a whole series of movies where he makes graphite oxide and components necessary for making your own DIY super capacitor. The first videos have terrible sound picture and sound quality but along the way Robert has bought a new camera and more recent videos look and sound much better. Robert has also written some books you can buy online at kobobooks.

Additional videos about graphene and super capacitors from Robert.


Super capacitors

Eric Goeken

Eric Goeken is the first DIYer to post a video where he successfully produce some light scribe graphene the same way I discussed in my first post about DIY graphene. He bought some graphite oxide powder online and went from there.

Additional videos about graphene from Eric.


The user behind unitedstatesgraphene doesn’t go out with his real name in public but he seems to be on his way to make light scribe graphene all the way from graphite as described by Robert. He has gotten to the point where the graphite oxide is drying on the CD-substrate waiting to go into the light scribe burner.

I wish them all the best of luck and I look forward to follow their progress.

Calibrating a Figaro TGS822 sensor, by drawing…

After consulting with the boys and girls at chemicalforums.com about how to produce an ethanol gas with a 300 ppm without having to buy a lot of fancy gear and thus finding out that it was more difficult then I initially thought I have reluctantly decided that I don’t think I will be able to pull it of. There for I have decided to work with what I got. What I got is air and a datasheet.

The data sheet provided by Figaro for the TGS822 only goes down to 50ppm, however the graph looks pretty logarithmic linear to me so I decided to add the 10-50ppm part my self making a bold assumption that it will be logarithmic linear in that interval as well.

From the data sheet we get the relation between RL and RS which is a voltage divider circuit.


From the graph in the data sheet we can also see that the resistance of the sensor in air is RS (air) = R0 * 19.

If we combine these two facts we can express R0 as a relation of RS (air) and the value of RS (air) can be deduced by reading the voltage of the sensor and using the voltage divider formula.

RS (air) / 19 = R0 in my case RS (air) = 78kΩ. => R0 = 4105Ω

When we have R0 we can make a table to relate resistance (RS) to ppm by reading the scaling factor of RS/R0 from the graph for different gas concentrations.

Rs in air = 78000   Ro = 4105,26315789474
ppm Scaling factor Rs = Ro * Scaling factor
0 19 78000
10 15 61578,947368421
10 10 41052,6315789474
20 9 36947,3684210526
20 7 28736,8421052632
30 6 24631,5789473684
30 5,7 23400
40 4,7 19294,7368421053
50 4 16421,0526315789
60 3,5 14368,4210526316
70 3,2 13136,8421052632
80 3 12315,7894736842
90 2,7 11084,2105263158
100 2,5 10263,1578947368
150 2 8210,5263157895
200 1,6 6568,4210526316
300 1,2 4926,3157894737
400 0,9 3694,7368421053
500 0,75 3078,9473684211
600 0,67 2750,5263157895
700 0,58 2381,052631579
800 0,52 2134,7368421053
900 0,47 1929,4736842105
1000 0,4 1642,1052631579
2000 0,2 821,0526315789
3000 0,15 615,7894736842
4000 0,1 410,5263157895

The TGS822 sensor is affected by both temperatures and humidity and it should be complemented with a thermistor and hygrometer so that it is possible to compensate for temperature and humidity. I don’t have any thermistor or hygrometer yet but if we use the ”calculate R0 from RS (air)” every time we start the sensor then perhaps we will also compensate for temperature and humidity, this is something further experimenting will tell.

Hi, I’m Ketosense


During the weekend I have managed to put together a first very early prototype of my ”Ketosense”. It does register when a person is blowing in to the ”gas chamber” where the sensor is located and something that feels encouraging is that my wife gets significantly higher readings then me. Since I’m still a carbohydrate junky and she is not that is exactly what we want. However we do have some hurdles to cross before this thing is useful.


  • Calibrate the sensor
  • Determine sensor characteristics for gas concentrations between 0-50 ppm
  • Build a better moth piece

Calibrating the sensor

Calibrating the sensor is the major thing that needs to be done. In the sensor data sheet there is stated exactly how the resistance of the sensor behaves at different gas concentrations but everything relates to one calibration point, the sensor resistance Rs = Ro at 300 ppm of ethanol. Based on this value we can calculate the relation between sensor resistance and gas concentration for all other gas concentrations. Further in the data sheet it is stated that Rs at 300 ppm of ethanol is between 1-10 kΩ and that is quite a wide range and I don’t want to make a generalization of 5k before I even tried to calibrate it. Right now I don’t rely have a clue how to create a 300 ppm ethanol gas mix but hey, thats just another problem to solve.

Sensor characteristics for gas concentrations between 0-50 ppm

The datasheet for the TGS822 doesn’t have any data for how the sensor behaves at low gas concentrations between 0-50 ppm. In the graph displaying the Rs/Ro relation it looks like the function for the sensor resistance follows a Log-linear model so if I can determine the Ro (Rs at 300 ppm ethanol) of my sensor and also have the Rs for < 10 ppm of gas, which I presume is the ethanol content of normal room air, then I should be able to deduce some info for how the sensor should behave in that range as well.

Moth piece

I quickly understood that to get a good reading you needed to give the sensor some time to take the reading. This means we have to trap the gas around the sensor in some sort of chamber for a while to get a good reading. Right now I have a plastic cup with a tube and some tape over the opening and it does the job. However it is actually to air tight and I have to remove the tape from the opening to vent out the gas after getting a reading for the sensor to be able to reset it self. Another issue with the cup design is the condensation. Breath has quite a high moisture level and after just a few readings with this moth piece you start so see condensation on the inside of the cup and readings from the same person are different from time to time which they obviously shouldn’t be. Both humidity and temperature affects the sensor resistance so I am thinking of getting a humidity/temperature and add that so I can compensate for those factors but I believe that a better design of the moth piece can be just as or even more effective.