YouTube player

In this project you’ll take two simple ideas — a classic “cricket” noisemaker and a solar battery charger — and combine them into something great. Along the way you’ll also learn how to use the Arduino microcontroller as efficiently as possible for minimal power consumption.

Solar panels create electricity, of course — we’ll take that raw power and add a battery charging circuit to top up a 9V NiMH battery that powers the Arduino. But you can also use solar panels to detect ambient light — so in this project we’ll also use them as sensors to trigger the Arduino to perform a task when it detects that night has fallen.

What task? Making cricket noises! Your Solar Cricket will draw its power from the sun during the day and then use it at night to do its stuff. It’s fun for your garden, or for pranks — the circuit can be hidden away and used to drive someone crazy looking for the source of the sound!

To complete this project you should be comfortable using a soldering iron, following a simple schematic, and programming an Arduino board.

wp08_solar-cricket

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Assemble the parts.

All the components for this project are available at RadioShack, including the latest Arduino Micro microcontroller. You can also use the older Arduino Nano if you have one.

Two 5K potentiometers are used: one to trim analog voltage to a safe level (under 5.5V) for signal input to the Arduino, the other to adjust the LM317 constant current source.

You can substitute a 1K pot such as RadioShack #271-280 to adjust the LM317 output (the current pot) if you want finer control, but if you do, you’ll want to substitute a 100Ω resistor for R3.

Test the solar panels.

The solar panels have a positive (red) connection and a negative (black) connection. Just like batteries, you can connect them in series to get more voltage, or in parallel to get more current.

For our needs here, we’ll connect them in series. This will give us up to 12 volts (V) with 100 milliamps (mA) of current in full sunlight.

Since all NiMH batteries charge best when you give them 10% of the battery rating in current, we’ll need to reduce that 100mA current. Here we’re using a 170mA/H battery, so this means we need to limit the current to about 17mA. (We could of course just use a resistor for this, but that’s not as efficient as using a regulator and Ohm’s Law.)

Modify the case.

Choose a case large enough to host the 2 solar panels on top. Drill 2 holes to pass their red and black wires through.

Mount the panels on top with epoxy and pass the wires through.

Then attach the solar panel wires to the prototyping board as shown. The “middle” red and black wires are connected together.

Build the constant-current charging circuit.

By default, a voltage regulator keeps a voltage constant. We can use this to our advantage when creating a constant current source by putting a fixed resistance on the output (Vout) pin, and connecting the Adjust pin to the Vout, after the resistance. Ohm’s law dictates that constant voltage + constant resistance = constant current. (More info on the LM317 is here: http://en.wikipedia.org/wiki/LM317 .)

Solder the circuit on the proto board following the photos here and the schematic diagram in Step 1. I used the following wire colors: 3.3V orange, 9V yellow, 5V red, Ground black, Signal white. Green wires connect the current pot.

The 100µF electrolytic capacitor is connected directly across the 2 series solar panels. This filters out power fluctuations and extends battery life. Polarity is critical: the cap’s positive lead goes to the positive solar panel lead, and its negative lead goes to the other panel’s negative lead.

To use one of the solar panels as a light level sensor, you have to be sure the signal voltage doesn’t exceed 5.5V, which is all the Arduino’s analog input will tolerate. Attach the 5.1V Zener diode across the positive and negative wires, as shown in the first photo here. Polarity is important here, so be sure to install it the right way. This will limit or “clamp” the voltage at 5.1V — you lose some power, but you protect your Arduino. Solder a red wire to the positive side of the Zener diode — you’ll connect this to the Arduino A0 pin later.

Add the variable regulator (LM317) and put a 5K or 1K potentiometer and the 10Ω fixed resistor in series with the output (middle, Vout) pin. Then connect the Adjust pin (left) to the output after the resistance. By adjusting this potentiometer, you can get a constant 17mA current output in full sunlight. There will be a small voltage drop from using the regulator, but as long as it stays above 9V, it’ll charge the battery. You can vary R3’s value to adjust the range of the current control; its value must be between 0.8Ω and 120Ω to protect the LM317. With the 10Ω resistor we got about 70mA that we could adjust down to the correct range using the current pot.

The 5K potentiometer marked R1 on the schematic is used as a potential divider. The solar panels are rated at 6V and the Zener diode should limit voltage to 5.1V, but not all diodes are created equal. By adjusting this pot you can reduce the signal voltage further if needed, to protect the Arduino. It’s a “belt and braces” approach: the first pot limits the voltage absolutely, the second limits it relatively.

Adjust the current.

Before you connect the Arduino or battery, test and adjust the current output from the charging circuit in full sun, using the following method:

Place the black lead of your meter to ground and the red lead of the meter to the connection in-between the regulator’s Adjust pin and the output of the 5K current adjustment potentiometer.

Our charging circuit produced about 70mA in full sun; yours should produce something similar. Adjust the current pot until the current on your meter reads about 17mA. It’s a little touchy — a small twist of the pot produces a relatively large swing in current. Be patient until you get it dialed in around 17mA.

Again, the only things that should be hooked up in the circuit at this point are the 2 solar panels, the LM317, capacitor, diode, 10Ω resistor, and potentiometers. Do not hook up the battery or the Arduino.

Install the battery and potentiometers.

Next, you’ll connect the charging circuit’s positive and negative wires to the positive and negative wires of the battery, and also to the voltage-in (Vin) and ground (GND) pins of the Arduino. This allows the battery to act as a reserve to “catch” any unused charge being generated by the charging circuit. When the Arduino needs power, mostly at nighttime, the battery kicks in and supplies the juice. Think of this step as connecting the Arduino to the charging circuit, and then “tapping” the positive and negative lines with the battery which is acting as a battery backup power supply. It sounds complicated, but it isn’t difficult. Just follow the schematic in Step 1 and the connections shown in the second photo of this step.

First mount the 2 potentiometers on the bottom of the enclosure lid and wire them as shown.

Then connect the output of the charging circuit to the battery terminal connector. Here the yellow wire is the charging output, the orange wire is the light sensor output, and the black wire is the GND or negative terminal.

The third photo here shows an alternate build of the circuit board that we developed for the video shoot — it’s the same circuit, but this design makes it easier to follow the power and ground connections.

Hook up the Arduino.

The wiring for the Arduino is quite simple. First run the red and black wires from the charging/battery circuit to the Vin (yellow) and GND (black) connectors on the Arduino board.

Then run the white light sensor signal wire to the A0 connector.

Finally hook up the piezo speaker, connecting its black wire to Arduino GND and its red wire to pin D3.

Program the Arduino.

First, install the JeeLib library from github.com/jcw/jeelib. This library provides power management functions that we’ll will use to keep battery consumption as low as possible. (If you’ve never installed a library before, see arduino.cc/en/Guide/Libraries.)

Instead of utilizing a standard delay, we’ll use a JeeLib delay that powers down as much of the Arduino as possible while the board is waiting. A device that would normally exhaust a 9V battery in days can now run for weeks. Couple this with a solar charging circuit and you have a device that can run for months on a single battery!

Download the project code here, then use a USB/Serial connector cable to upload the program to the Arduino.

The code is well commented, and works as follows: At the start is it assumed to be daylight. If we read 5 low light levels in a row, we switch to night mode, and call the chirp routine a fixed number of times. Then we wait for 5 high light levels and switch back to day mode. All the delays use the low power Jee library calls to conserve battery power.

There is a line in the code that reads: #define DEBUGLOGGING // Do serial logging if in DEBUG mode - remove this when live to save power. While this line is intact, the Arduino will output debug messages on the serial port. This is useful for testing. Once you’re happy that the system is working, you can remove this line and the system will work for real — chirping through the speaker and using the power management code.

NOTE: The low-power delay library and calls can interfere with the serial port connection. Since you’re using the computer for power during testing, you can “comment out” these calls and the associated include statement. That’s another good reason to keep the line

#define DEBUGLOGGING // Do serial logging if in DEBUG mode - remove this when live to save power intact while testing and debugging, and remove it when you’re ready to set the device live.

Test!

One of the first tests you should do is with the DEBUGLOGGING line intact. Hook up the device to your computer and open the serial monitor. Then run the device and cover the solar panels with a sheet of paper to ensure that (a) the light level is being measured and (b) the device switches mode when 5 low light levels have been recorded. Once the device has switched you should remove the cover and make sure it goes back into daytime mode.

You can watch my video of this process at youtube.com/watch?v=kF489_j1O2A.

You can adjust all the parameters by tweaking the control constants at the start of the code:

  • LOWLIGHTCOUNTTHRESHOLD 5

    The number of (consecutive) times to register a low light event before we activate the chirp

  • LOWLIGHTTHRESHOLD 100

    The analog voltage level that the panel has to drop by, before it is counted as low light

  • NUMBEROFCHIRPS 30

    The number of times the chirp routine is called

  • PAUSEBETWEENCHIRP 10

    Number of seconds between chirp (this will be slightly randomized to give a more ‘analog’ feel)

  • SAMPLEINTERVAL 1

    Number of minutes to sleep before sampling the light level

  • NOOFCHIRPS 6

    The number of ‘beeps’ in a chirp

  • CHIRPFREQ 2600

    The frequency of the chirp tone

  • SENSORPIN A0

    Analog input for light level

  • LED 13

    Pin to control the built in LED

  • SPEAKERPIN 3

    Pin with the piezo speaker attached

Deploy.

Once you’re satisified with the circuit’s operation, mount the Arduino with a dab of hot glue and close up the enclosure.

Set your Solar Cricket somewhere in the sunlight, protected from moisture. When the sun goes down, the code will recognize the failing voltage from the solar panels and start the chirping routine — just like real crickets! You can set it outside in the garden or inside in a bright window.

If you’d like to hide the piezo buzzer in the house as a practical joke, just drill a small hole in the enclosure and extend the piezo wires 10 or 20 feet. Leave the enclosure outside and pass the wires through a window or other opening, then stash the buzzer somewhere hard to find. Try adjusting the tone frequency and chirp delays to make it even harder to find — high frequencies are notoriously difficult to locate!