Wearable Tech

Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

James Young on twitter mentioned that a UV monitor was something he'd find really useful as he has sensitive skin.

James Tweet

So my thought was to use the PocketBeagle to log the UV exposure using a https://www.element14.com/community/view-product.jspa?fsku=2373588&nsku=NULL&COM=noscriptML8511 chip. It could indicate a warning or send a message to a phone when the levels are too high for too long.

Sensor

The ML8511 produces an output voltage proportional to the UV level, so I needed to use one of the PocketBeagle's ADC pins to record the level. The PocketBeagle has 6 pins that take 0-1.8v and 2 that can take upto 3v, so I needed to use one of the later pins. The chip also has an "enable" pin which needs to be set high before a reading is taken.

 

The World Health Organisation have defined a simple index which we can use the determine some colour coded outputs. I was also thinking that the duration of exposure would be significant and the WHO have a second value called the daily UV dose which is calculated as the integral of the UVI over the day.

Input

The ADC inputs on the BeagleBones is typically 0 to 1.8v. However the Pocket Beagle Bone has some pins that can cope with 3.3v. One of these is A6. So I attached a potentiometer between 0v and 3.3v and fed it into the A6 pin. So although the documentation does not explicitly mention it, it would appear that the output 0 -> 1 represents voltages 0 -> 3.3v.

 

{gallery} Analogue In

Potentiometer

Testing: Wiring up a potentiometer to check the A6 input

Test 1 Floating

Test 1: Floating

Test 2 1v

Test 2: 1v

Test 3 3.3v

Test 3: 3,3v

Output

To test the output I wired up an RGB LED as below, and checked it using the blink LED demo to confirm the pin I was using for the enable for the ML8511. This turned out to be P1_04.

LED Pins1

The System Reference manual for the Pocket Beagle mentions that it supports "4 Pulse Width Modulation outputs accessible with 2 enabled by default"

 

I checked with the config-pin command to confirm that the pin P2_3 that I wanted to use was enabled for PWM and it appears to be ok.

https://zeekhuge.me/post/a_handfull_of_commands_and_scripts_to_get_started_with_beagleboneblack/

 

debian@beaglebone:~$ config-pin -l P2_3
default gpio gpio_pu gpio_pd gpio_input pwm

 

I wired up PWM1A, PWM0A and GPIO23 to the LED and checked that it could dim these using analogWrite

Pocket Beagle Pins

var b = require('bonescript');
var f = 0.1;

rampLED = function() {
 f=f + 0.1;
 if (f>1) { f=0.1; }
 b.analogWrite('P2_1', f, 2000.0);
 b.analogWrite('P1_36', f, 2000.0);
 b.analogWrite('P2_3', f, 2000.0); 
};

timer = setInterval(rampLED, 100);

stopTimer = function() {
 clearInterval(timer);
};

setTimeout(stopTimer, 30000);

 

https://github.com/beagleboard/pocketbeagle/wiki/Peripherals

 

Simple demo

When I combined my code together I found that the analogRead was quite slow to return so I adjusted my code to only check every 10s to avoid reading the value faster than the API could handle.

 

To test the levels I used the potentiometer and the following simple code:

 

var b = require('bonescript');
console.log('Starting UVMonitor');


function writeLED(err,value) {
    var col = [0,0,0];

     if (value < 0.3) { 
         col = [0,1,0];
     }
     else if (value < 0.8) {
         col = [1,1,0];
     }
     else if (value >= 0.8) {
         col = [1,0,0];
     }
     
     b.analogWrite('P2_1', col[0], 2000.0);
     b.analogWrite('P1_36', col[1], 2000.0);
     b.analogWrite('P2_3', col[2], 2000.0); 


     b.digitalWrite('P1_4', b.LOW);
}


function checkSensor() {
     b.pinMode('P1_4', b.OUTPUT);
     b.digitalWrite('P1_4', b.HIGH);
     setTimeout(checkInput, 500)
}


function checkInput() {
 b.analogRead('A6',writeLED );
}


timer = setInterval(checkSensor, 1000);

 

Using the cloud9 IDE saved the file into the cloud9/autoruns directory so it would start on bootup.