SimpleCV…too fun

My family lives in Fresno, which is a fantastic place to live, except that our air quality is quite poor.  I’m sure you can look up how poor and why it is on your own.  I recently discovered that California’s Central Valley has one of the best air quality monitoring networks in the country!  Various agencies collect air quality monitoring data at stations throughout the Valley, including 7 stations in Fresno County and 3 in the City alone!  The stations provide data which is used to predict air quality for the following day at schools, and to support a Real-Time Air Advisory Network (RAAN), which posts hourly ozone and PM2.5 data to a webpage.  Every morning, schools raise a flag indicating the air quality for the day.  The predicted air quality index determines the color of the flag.

It seems odd to me that the school warning system is based on a prediction and does not change with the air quality through the day.  The diurnal cycle of smog production results in huge fluctuations in ozone, which can creep up to very dangerous levels, even on a green flag day.  The static flag system at schools does not inform teachers and parents of these trends.  I don’t think very many people are even aware that State and local agencies (public servants) are producing all this air quality data, and I doubt that most people have the means to look it up.

As a Arduino-equipped disciple of Christ, I can’t help but consider how all the wonderful data being gathered might be better utilized to serve our community, my low-tech neighbors in particular.  A couple of web queries later, I’m well on my way to building a Real-Time Air Advisory Network People-Alerting Machine (RAANPAM)!  I figure I’ll use python script on a computer to look up the data online and tell an Arduino UNO how to display the current air quality data on some sort of big display (like a big color wheel) and sound a horn.

So far, I’ve learned enough python (VERY little required, cuz python is AWESOME!) to grab data from the California Air Resources Board (CARB) website.  CARB actually has more data, like hourly NOx, than the local Air District.  Here’s what I did in python to download the current ozone data (screws up if no data has been posted yet for the day):

This is my first time using python, so let me know if you have any pointers for me.  The idea is simply to download the HTML files from the CARB website that have the air quality data we’re looking for, parse it out with basic string functions like find(), and then somehow deliver that data to the next step for further processing/decision-making.  I imagine there’s a better way to access CARB’s data (SQL database) that wouldn’t depend on CARB maintaining the exact HTML format they use today, but this seems to work right now.  Probably to minimize redundant data pulls, the air quality query results page includes all the data for each pollutant, day, and monitoring station as a comma-separated list in a link to graph the data – a really convenient single string to grab all the data I’m looking for.

# library with now() function for getting date and time import datetime

# library with urlopen() function for loading a web page
import urllib

# Get the current time as a string
now = str(datetime.datetime.now())

# Convert current time to three ints (month, year, day)
year = int(now[0:4])
month = int(now[5:7])
day = int(now[8:10])

# Create the URL that will load today’s CARB ozone monitoring data at the Fresno-First monitoring station
ozoneurl = “http://www.arb.ca.gov/aqmis2/display.php?param=OZONE&units=008&year=” + str(year) + “&mon=” + str(month) + “&day=” + str(day) + “&hours=all&county_name=10-Fresno&basin=–AIR+BASIN–&latitude=–PART+OF+STATE–&report=HVAL&order=basin%2Ccounty_name%2Cs.name&submit=Retrieve+Data&ptype=aqd”

# Get a file-like object for the ARB web page with today’s ozone data.
f = urllib.urlopen(ozoneurl)
# Read from the object, storing the page’s contents in ‘ozonehtml’.
ozonehtml = f.read()

# GOAL OF NEXT FEW STEPS: Find and store the latest ozone data for processing

# Find the comma-separated ozone data (starting/ending place in the HTML)
# (the file has it embedded in a link to plot the data – pretty convenient!)
ozonedatafinish = ozonehtml.find(“Fresno-1st Street,3009″)
ozonedatastart = ozonehtml.find(“value=’”, ozonedatafinish – 500, ozonedatafinish) + 7

# Store the comma-separated ozone data
ozonedata = ozonehtml[ozonedatastart:ozonedatafinish]

# Show the data!

The other day I posted about progress on an aerial photography project.  At the end of the day, my auto-picture-snapping circuit didn’t work.  It’s my first project using a 555 timer (NE555P).  I finally measured the capacitance of the timing capacitor and found it was WAY smaller than I’d thought.  The circuit output seemed to be always high because the frequency was really high.  This also explains the low voltage (averaged over duty cycle)!  I swapped the capacitor with one closer to my design and it flashed LEDs just right!  When I connect the camera up to the MOSFET (2N7000) that is controlled by the output of the 555, I got pictures!  Woohoo!  You should have seen my excitement when it finally worked…actually you can!

it works!

Since our church is not too strong in the revenue department, we try to get creative with fund raisers in order to bring as many people as we can to camp.  This year, we collected stuff for a yard sale and did pretty well.  Our enchilada sale was a success, too.  But we’re still coming up pretty short.  I got the idea to sell personalized aerial photographs that we could take using a tethered balloon.  I’m still not finished with the setup and camp is this weekend, but I think it could be a pretty good little racket.

The plan is to get a cheapo camera that I can wreck without too much heartache (craigslist camera – CHECK!) and send it up with a helium balloon and a picture-taking circuit.  I estimated (assuming ideal gas law and spherical balloon) that a 36-inch balloon could lift about a pound.  I found a website with 36-inch balloons six for $10.  This seems so easy and simple!

I spent a few hours in the middle of last night working on the picture-taking circuit part.  I made progress, but in the end I was pretty disappointed.  I was able to crack open the camera after an hour of ridiculously excessive straining with the wrong-sized screwdriver.  I poked around with some wire to figure out which metal pieces need to connect to trigger the shutter.  Then I soldered wires onto each side of the connection that worked.  After running the wires out of the camera and closing the camera back up, I tested it out by touching the loose ends of wire together and BAM!  There you go – it worked!  This is great, because now it should be really easy to trigger photos with an easy-to-generate signal from a simple circuit or a microcontroller like the Arduino!

I recently bought a hundred 2N7000 MOSFETs from Jameco.  It seems to me that one of these is perfect as a switch to short my two shutter-control wires together.  I also bought a hundred 555 timer chips…because I’m crazy.  But one of these should come in handy to send a shutter-control signal to the MOSFET switch every few seconds when the camera is in the air.  I referenced a handy LM555 calculator website to build this circuit (powered by an ATX power supply for testing):

555 timer circuit for camera shutter control

I tried to size the resistors and capacitors for the 555 timer to generate a periodic square wave signal with about 0.15 seconds of “on” followed by 15 seconds of “off”.  It didn’t work!  When I tried it with 5V supply, my multimeter shows what seems to be a constant 1.9V output from the 555 (Vgs on the 2N7000), which results in a partially on MOSFET with channel resistance around a k-ohm instead of just a couple of ohms.  With 12V supply, I get Vgs of 6V but it seems to have 100% duty cycle (the “pulse” to signal the camera is always on).  I might as well not have a 555 chip in there – no good.  This is the point in the story when I realized the sun had come up and it was time to go to work.  Will need to face this later, as well as the issue of supplying power at 5V or higher when the camera has a 3V supply.

I’m so crazy that I went ahead and bought some op amps (LM741) and other stuff from Jameco before actually planning anything (typical late-night purchase).  Jameco seems to beat Digikey in price for most things I’ve been looking for.  And I usually get everything the next day or in two days at the latest.  Pretty good.  Anyway, I figure I’ll use an op amp to amplify the signal from LED photosensors like Tanya does.

Then I just need a circuit to enable the motors (through my SN754410 h-bridge) to turn over some voltage range, discharging from like 16V to 8V or something.  I don’t know the first thing about how to do that, but hopefully can adjust the voltage regulators I got to use hysteresis or whatever to get that effect.  I’ll try using various motors to operate it at various voltages to check the performance.

I’m thinking I can use a 74HCT245 and some capacitors to make a simple/easy charge pump so the tracker can run intermittently off a tiny, low voltage solar cell.  I figure with a duty cycle of 2.5%, I should be able to run the motors for 12 minutes of an 8-hour sunny day.  If I use my 0.3W solar cell, that comes to over 100 ft-lbs (maybe lift 20 lbs 5 feet, eh?) of energy per day, with power used at 12W when on.  Super-rough numbers, but makes some sense.  It’ll be fun to experiment.

Of course I need to build a thing to mount whatever it is that will be pointed toward the sun (like a tripod/pole, hinges, and some the threaded rod and bolts as a linear actuator).

Here I restate the goal of this endeavor both to motivate myself and prevent this from becoming a mere time and resource-wasting selfish hobby:

I am in the research and development phase of a project to identify products that we can manufacture locally for profit or to offset local cost of living/business.  The goal is economic development in the form of local jobs, influx of money from outside our community,  or reduction in expenses for locals.  The project has the side benefits of being extremely fun and potentially helping out my family in the same way I hope to help out my community.

We’ll see how it goes, eh?



Success indeed!  I controlled a DC motor through an Arduino UNO and a SN754410 h-bridge chip.  I can’t say I totally understand what my problems were before.  I think what happened is that I didn’t have a common ground for the Arduino, SN754410, and the motor power supply.  At one point, I measured 32V between the ground for the motor power supply and the Arduino!  That voltage went away when I plugged my power supply into the power strip as my computer connected to the Arduino – at that point I felt safe to connect all the grounds together.  I also neglected to connect 5V power (pin 16) to the SN754410 at first.

I used a 12V lead from an ATX computer power supply for the motor supply (SN754410 pin 8) and the Arduino 5V output for SN754410 pin 16.  With the enable pin (pin 1) of the SN754410 at 5V, the output (across pins 3 and 6) was about 10.5V, I think.  I put some resistors (like 2 ohms) between the motor and the SN754410 to try to protect from voltage spikes induced in the motor (back EMF?).  I didn’t want to have a voltage drop of more than a couple of volts or the motors might not turn much.  Anyway, it worked great!  I got a screaming motor that tried to run off the table instead of a near-ultrasonic whining and a slight twitch.

This is really exciting.  Not only can I now make a robot that the Arduino can control, I’m sure I can control the SN754410 (motors!) with a simpler/cheaper circuit with digital output!  I think the output from the suspended bicore circuit may be just right for connection to the direction pins (2 and 7) of the SN754410.  A small, solar cell could charge a capacitor with a circuit to energize the enable pin (pin 1) of the SN754410 when it’s ready to power the motors.  Then we’ll have short bursts of solar-powered sun tracking!  I honestly don’t even fully understand what the suspended bicore is, but it looks like an easy way to get a digital signal telling my circuit which direction to turn toward the sun.



Dear Diary,

I enjoy the feel of the sun on my face and love to see blue sky after a long winter, but sometimes that all gets overshadowed by frustration about how little my community and I take advantage of the abundant, free power pouring down on us.  Actually, pretty much my longest-running, most nagging, nearly most exciting dream has been to concentrate solar energy to do amazing, awesome things.  I recently had my 5th anniversary, my daughter and son turned 4 and 2, and I turned 30 years old.  I can’t help but reconsider what’s important to me and what I have done and plan to do with my life.  I embrace the life God has called me to, including the passions I have for so long dismissed as selfish ambition and indulgence.  I commit to buckle down and really do something rather than only dream.

I bought myself an Arduino UNO electronics prototyping board to facilitate the process of developing science/tech ideas into some real stuff.  I don’t want to get stuck on Arduino, but if you don’t know already, the Arduino is incredibly awesome – so much so that when I consider its outrageous opensourcedness and what the Arduino enables us to do it triggers a near-cataclysmic avalanche of happy/creative/hopeful neuron blasts in my brain that effectively white out my consciousness for significant periods of time.  I’m sure it’s not healthy for me to linger in that exploded-mind state for two long, so let’s get down to the first efforts toward doing something.

Below is a list of things I’ve collected recently to experiment with basic suntracking circuits and maybe doing some experiments.  Most of the stuff is commonly referred to on hobby robotics and DIY solar websites (primarily this BEAM website).  At first I hoped to save a bunch of money by buying the most basic components and assembling all my circuits from scratch.  Then I realized that my patience and spare time don’t allow me to work that hard.  Anyway, here’s what I’ve got:

  • Arduino UNO SMD
  • a breadboard
  • lots of NPN/PNP transistors (2N3904 / 2N3906)
  • CMOS 1381J Voltage Detectors
  • SN754410NE quadruple half H-bridges
  • Some 74HCT240, 74ACT240, 74ACT245
  • a bunch of resistors, capacitors, potentiometers, LEDs, etc.
  • lots of different kinds of rechargeable batteries
  • some supercapacitors and various regular capacitors
  • a 3W (24V/0.1A) solar panel
  • some little 3V solar panels
  • cadmium sulfide photocells
  • lots of DC motors from TINY to big honkin’ scooter-types
  • lots of junk electronics I can strip for parts

I struggled for a couple hours last night just trying to get my Arduino to tell the H-bridge to drive some motors.  At first I didn’t think it worked at all.  Then I realized there was a high-pitched squeal surging on and off at the frequency I told the Arduino to change the motor direction.  When I looked more closely at the motor, I noticed it was moving very slightly.  The voltage across the motor was as I had expected (around 12 V), but it drew a current of only about 45 mA.  That’s similar to what you might get from the output of an Arduino directly!  What the heck is going on?  I couldn’t figure it out.

Here’s a series of smaller goals I hope to attain along the way to the larger goal of tracking the sun in order to concentrate tons of light into a tiny spot:

  1. Learn how to protect the circuit components from crazy inductive load (motor)
  2. Get H-bridge to work w/ Arduino
  3. Set up phototropic suspended bicore (BEAM robot concept) to see what it does (test output)
  4. Try to run a motor using the H-bridge w/ bicore output – might need amplification (transistor)
  5. Try to run two motors on the one H-bridge chip, signals from pair of suspended bicores (2 on one chip?)
  6. Solder it together!
  7. Build a thing that can rotate toward the sun under the direction of the motors.