Wednesday, June 6, 2018

TriNegistor, a Triple Negistor oscillator noise box

-- ref. 2010


This box I present here is a triple negistor oscillator. This is basically a noise box I use to make sounds.


The orignal schematics cames from Charlie Barth trinegistor, you can find it here http://moosapotamus.net/trinegistor.html.


I just change some components and add a few switch to his schematics.
First of all, what's a Negistor? It's a a NEGative dIfferential resistance oscillaTOR, it's an oscillator built using his NDR effect. The negistor I use it's build using a 2N2222A NPN transistor wired in reverse mode. Please find more information here: http://www.keelynet.com/zpe/negistor.htm.
The tri-negistor is built putting in series three negistor oscillator.


Notes
  • read risk disclaimer
  • excuse my bad english

Wednesday, May 2, 2018

UV Sensor ML8511 AVR Atmega library


Ultraviolet (UV) is an electromagnetic radiation with a wavelength from 10 nm to 400 nm.
The ML8511 is an ultraviolet sensor that output an analog signal correlated to the amount of UV light detected. By datasheet the sensor detects wavelength from 280nm to 560nm.


Here I've implemented a driver for AVR Atmega, portable to other microcontrollers, that correlates the sensor output to light intensity, it also computes the UV index based on the sensor input.
The ultraviolet index or UV index is an international standard measurement of the strength of sunburn-producing ultraviolet (UV) radiation at a particular place and time. It is a linear scale, with higher values representing a greater risk of sunburn. The purpose of the UV Index is to help people effectively protect themselves from UV radiation.
Not all the energy of the UV spectrum has the same "damage" power, due to this the power spectrum is multiplied by a weighting curve known as the erythemal action spectrum, and the result integrated over the whole spectrum.

The correlation function I propose here is derived by the datasheet graph of "Output Voltage over UV intensity".


From this graph we can get the correlation function. This graph is clearly a linear function. We have Output voltage on the y axis and UV intensity on the x axis.
Because we want to obtain the UV intensity using the voltage that we can read from the sensor, we are going to flip the graph.


Once we have flipped the graph we can now get the point from the graph using a tool like WebPlotDigitizer.
We can now use liner regression technique to obtain the function we need to convert voltage output to UV intensity.
Also notice that this graph has four functions for 75degree, 25degree, -5degree, -25degree temperature condition.
If we perform linear regression on points of that function we get 4 correlation functions.

@75deg UV mW/cm2 = 8.158154634V -7.77772054
@25deg UV mW/cm2 = 7.9816914V-7.921745308
@-5deg UV mW/cm2 = 7.853758854V - 7.934095316
@-25deg UV mW/cm2 = 7.743732684V - 7.978602568

Note thate the accuracy of this method depends on the accuracy of your point extraction.

More in general we can say that the correlation function looks like this:


If we are going to use this sensor under different thermal condition we can simply interpolate beween those function to get the correlation function slope "s" and intercept "i".

Also, that graph is for a wavelength of 365nm.
We may find the responsivity function of this sensor on the datasheet. Responsivity measures the input–output gain of a detector system. We can use again the WebPlotDigitizer to find points from the "Responsivity Characteristics" curve.


We may notice that for the 365nm light the responsivity is 1. It means that on that light condition the sensor correlation function we have seen before has a gain of 1.
If we suppose to apply a filter over the sensor UV detector that passes only just a single wavelength we can adjust the correlation function according to the gain of the sensor responsivity. That function is inversally proportional, so if our sensor has responsivity 0.3 on a 400nm wavelength, the correlation function have to be multiplied by 1/0.3, cause the voltage output measured is 0.3 times less than the voltage output at 365nm.
We are not going to use this most of the time, because we are going to use our sensor to measure the total UV intensity.

Now let's take a look at the UV index.
The UV index is defined as:


The function that defines the susceptibility of the human skin to sunburn (erythema) and of generalised DNA damage due to UV radiation is called erythema function, you can find it below.


Given the erythema function w(lambda)


And the irradiance spectrum I(lambda), we may note that the 1/25 coefficients makes the UVI dimensionless.

We have tell that the sensor we are using measures ultraviolet intensity between a range.

We are going to consider just:
  • Ultraviolet A (UVA): wavelength between 315nm and 400nm
  • Ultraviolet B (UVB): wavelength between 280nm and 315nm
We can assume a fixed ratio between UVA and UVB because we know that more than 95% of the ultraviolet radiation that reaches the Earth's surface is the UVA. So we can say


And, because this sensor measure just UVA and UVB, we can also say


and


Our sensor gives us a voltage output.

To make math simpler we can average the erythemal function w(lambda) for UVA and UVB as follows:


Now, we can take a look to the UV index function, we notice it as a mW/m2 index, so we have to covert the correlation function to mW/m2


Then we can substitute things in there:


We finally get


As example, if we consider a fixed temperature of 25degree, we get:


If you have a calibrated UV index meter you can correlate that function with the meter and adjust the offset of this equation.


Where o is the offset calculated using the equation


Reference: "Ultraviolet Sensor IC with Voltage Output by ROHM and LAPIS semiconductor". Note that on that paper they use a different method of correlation to find out the correlation curve.

In conclusion we have take a look at this UV sensor, trying to correlate the sensor output to the UV intensity, eventually considering also the environment temperature.
We have then looked at the UV index function, which is fairly usefull as an index for UV impact on health.

This library have been developed on an ATmega8 running at 1Mhz.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Monday, April 2, 2018

A web configurable ThingSpeak logger, build on AVR ATmega328

ThingSpeak is an open source Internet of Things (IoT) application and API to store and retrieve data from things. It is an on-line database service allowing developers to connect sensor-derived data (e.g. energy and environment data from objects, devices & buildings) to the web and to build their own applications based on that data.

This embedded platform is a modular and configurable ThingSpeak data logger, built on an ATmega328 micro, usefull to send datapoints to your ThingSpeak feed.


This project is an update to the Xively logger presented here: http://davidegironi.blogspot.com/2014/12/a-web-configurable-xively-logger-build.html.
LogMeIn will retire this legacy version of Xively, that is Xively Personal, on January 15, 2018. For this reason I've made an update to my previous logger in order to update my products logger to ThinkgSpeak.

If you are going to use this logger, please read the linked post link about the Xively version. This version is almost identical to the Xively one, just a few things has been changed to meet the ThingSpeak RESTful API.

The POST method it is used to send data to Thinkgspeak.
Even this version has a network interface you can use to configure the Ip address and connection mode, and your ThingkSpeak API key and feed number.

If you are using the priouse version you have to update the main.c and main.h code files, and the _xivelygetdata methods of you sensors implementations, this function has been renamed to _thingspeakgetdata. Also, all the previous reference to xively has been renamed.

The hardware used is an ATmega328, running at 16Mhz, for this reason one can also use an Arduino board. The network board used is based on the EC28J60 IC.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Sunday, March 4, 2018

An AVR ATmega R/C control signal reader - Method/02


The Radio Control (R/C or RC) is the method of controlling remote devices using radio frequencies.
Most of the time the RC signal uses RC servo signals.
Servo signal is a square PWM signal, usually with a period of 20ms and a duty time between 1ms and 2ms. More info on the wikipedia page here: https://en.wikipedia.org/wiki/Servo_control.

This library implements a method to read an RC signal and eventually map this to a 0..100 number.

There are a few methods of performing this task of course. Another alternative method i propose can be found here: http://davidegironi.blogspot.com/2017/04/an-avr-atmega-rc-control-signal-reader.html


It's developed on an ATmega8 running at 16Mhz.
It makes use of the external interrupt PIN and a timer to count the duty period time.
It's customizable to fit the user preferences. Configuration can be found in rcin2.h header file.
This is slighly less accurate than the Method/01 proposed in the link above, but it uses less resources due to the slower timing needs.
Theory of operation: each time a rising edge interrupt it is raised the timer counter is stored, When the falling edge happens the difference between the actual timer counter and the stored one it is used to compute the duty time.
Input PIN is INT0.
The RC signal it is measured, eventually filtered using an exponential moving average filter, and then mapped to a speed value from 0 to 100.


Code
Notes
  • read risk disclaimer
  • excuse my bad english

Monday, February 5, 2018

esp8266/Arduino 74HC4051 library


The 74HC4051 is a high-speed Si-gate CMOS device and is pin compatible with Low-power Schottky TTL (LSTTL).

The 74HC4051 IC can be used to expand the single ADC input port of the ESC8266, to 8 ports.
The ESP8266 comes with a 10bit ADC, 0 to 1V, the datasheet doesn't tell much more than this about the internal analog converter.


The output pin of the 74HC4051 is controller by 3 pins, by setting those pins high or low an analog input of the 74HC4051 is selected.
It can be driven by the same 3.3V that powers up the ESP8266.


This library was developed on Atom+PlatformIO, compiled esp8266/Arduino.



Code

Notes
  • read risk disclaimer
  • excuse my bad english

Tuesday, January 2, 2018

esp8266/Arduino NTC library


A thermistor is a type of negative coefficient resistor whose resistance is dependent on temperature, more so than in standard resistors. The resistance of a NTC Negative Temperature Coefficient thermistor (https://en.wikipedia.org/wiki/Thermistor) decreases as temperature rises. The Steinhart-Hart Thermistor Equation or the Beta Model Equation can be used to correlate the thermistor resistance to temperature to which the sensor is exposed.

The library implements the Steinhart-Hart Thermistor Equation or the Beta Model Equation to convert adc value read from analog input to temperature.
It output temperatures in Celsius or Fahrenheit.

The ESP8266 comes with a 10bit ADC, 0 to 1V, one can use the ESP8266 ADC for this library.
Suppose you are going to the internal ADC, and that NTC is going to be used between -20 and +100 degree Celsius. The NTC resistance by datasheet at -20 degree is 100k, and at 100 degree 100. To evaluate the pullup resistor you have to consider that the Voltage output at the ADC pin will be
Vout = Vpullup*(Rntc/Rntc+Rpullup)
We have to consider the max Vout, that comes from the max resistance given by the NTC
Voutmax = Vpullup*Rntcmax/(Rntcmax+Rpullup)
We have to chose a Rpullup such that Voutmax < 1V, so:
Rpullup = Vpullup*Rntcmax/Voutmax - Rntcmax
Subsitute with the sample NTC we are considering:
Rpullup = 3.3*100000/1 - 100000 = 230000.
A 220k resistor would do the job.

In the example i propose here I am using a ADS1015 12 bit analog to digital comparator, that is much more accurate than the internal ESP8266 ADC.
I am using the Adafruit ADS1X15 library for this IC, on top of that library I've build an helper to just convert the ADC raw value that comes from the ADS1x15 to a resistance or voltage value.


Once we've acquired the NTC resistance we can use the Steinhart-Hart Thermistor Equation or the Beta Model Equation to convert the resistance value to temperature.

A digital iir filter is implemented to remove unwanted reading errors.

This library was developed on Atom+PlatformIO, compiled esp8266/Arduino.

Code

Notes
  • read risk disclaimer
  • excuse my bad english