Instructions: SOLAR EXPERIMENTERS KIT FOR MICRO:BIT V1 V1/V2 compatible By David Whale
TABLE OF CONTENTS Introduction................................................................................................................ 2 Parts........................................................................................................................... 3 Using Alligator Clips................................................................................................... 4 Solar Board Reference.........................................................................................
PARTS Quantity Item 1 Solar Panel 1 Solar Store 1 Bulb 1 Motor and fan 10 Set of alligator clip leads Picture You will also need: * A BBC micro:bit (this kit is compatible with both a V1 and a V2 micro:bit) * A USB data cable to connect to a computer * A computer (PC, Mac, Linux including Raspberry Pi) and access to the internet.
USING ALLIGATOR CLIPS When using the alligator clips to connect your micro:bit to the MonkMakes boards, you have to be a bit careful how you connect the clips to ensure you get a good connection. The best way is to connect the clips vertically, as show below: Connecting the alligator clips like this prevents any accidental connections between the large connectors with the holes in and the much smaller connectors (gold lines in the photo above).
SOLAR BOARD REFERENCE To micro:bit To Solar Panel To attached device Charge% (output) – stored charge indicator. A voltage between 0V and 3V that can be connected to a micro:bit pin. Level (output) – stored charge (raw). A voltage between 0V and 5V that can be looped directly to the enable pin, to auto-enable when charged. Note: Do not connect to micro:bit Enable (input) – enables the power output, so that any stored energy can be used by the attached device.
PROJECT 1 – SUN FINDER In this project you will build a device that finds where the sun is. It uses a solar panel (photo-voltaic cell) and a low energy bulb to build a device that lights the bulb when enough sunlight is nearby. It demonstrates limitations of directly connecting the Solar Panel to a device that uses the energy harvested from the sun. Connecting Up The Solar Panel will provide up to 10V but it won't provide a lot of current at that voltage, so it is safe to connect to the Bulb.
How it Works The sun finder project directly connects the Solar Panel to the Bulb, and shows you immediately how much energy is being harvested as light falls onto the Solar Panel. The Solar Panel converts the light into voltage by the photo-voltaic effect. This is a physical and chemical process that excites the electrons to a higher energy state, and a small voltage is generated.
PROJECT 2 – GARDEN LIGHT In this project you will build a device very similar to those stick-in-the-ground self charging garden lights, that charge up an energy store that then powers a bulb, and is the first project where you use the energy storage board. By storing the harvested energy, the Bulb will stay on even when it gets dark. Connecting Up The loop cable between the Level and Enable connectors on the Solar Store will make the board work in standalone mode.
How it Works The Solar Panel converts light into electrical energy, and supplies a voltage to the left hand terminals of the Solar Store. The Solar Store transfers this energy into its super-capacitor (the big black component), which stores the energy until it is used.
PROJECT 3 – SELF CHARGING COOLING FAN In this project you will use your harvested and stored energy to power a bigger device: a motor that spins a fan. This device will charge up the Solar Store when the sun is out, and uses a simple home-made switch to allow you to decide when to transfer the stored energy to the motor to spin the cooling fan. Connecting Up By using two separate alligator clips, you can make your own simple switch.
How it Works This project is similar to project 2, but by using the two alligator clips, you have made a simple switch that allows you to decide when you want the fan on. If there is enough energy stored in the Solar Store when you connect the alligator clips together, the fan will spin.
THE BBC MICRO:BIT The next projects will use the BBC micro:bit to control the Solar Store. This will allow you to build more complex projects where the energy harvesting and the energy use is further separated into distinct phases, and your micro:bit can both monitor the stored energy as well as turn things on and off intelligently.
https://github.com/monkmakes/mb_solar_kit Click on the CODE button, then on DOWNLOAD ZIP. The file will download into your downloads folder. Unzip the zip file to a folder on your computer, and you will find all the Python programs in there. You can open these directly in the Python web editor as well as using the Python web editor to convert the code into a form that will run on the micro:bit.
PROJECT 4 – ADDING AN ENERGY METER In this project you will build a device that shows an energy meter on the display of the micro:bit, so that you know how much energy is available to power anything attached to the output. In all your previous projects it has been really hard to decide how much energy is stored, because it is hard to say accurately how bright the sun is, or how bright your Bulb is.
Code for a Simple Bar-Chart (MakeCode) The link for the MakeCode version of this project is here: https://makecode.microbit.org/_R1D337cbTPe1 How it Works Pin P0 of the micro:bit is connected to the Charge% pin on the Solar Store. This connection provides a voltage in the range of 0V to 3V that represents the stored charge in the super-capacitor on the Solar Store. The micro:bit analog_read_pin command reads this voltage, and turns it into a number in the range of 0 to 1023.
Experiments 1. Time how long it takes to charge, and record the pattern you see on the display when it is fully charged. (hint, it will charge faster in bright sunlight). 2. Disconnect the Solar Panel and press button B to make the fan spin. Time how long it takes to discharge (i.e. until the fan stops spinning). Record the pattern you see on the display when the fan finally stops. 3. See if it is possible to charge up to full charge while the fan is spinning (hint, try really bright sunlight for this).
Code for a Simple Bar-Chart (MicroPython) MicroPython doesn't have a barchart feature built in, so you have to provide the code for it yourself. This program is called 04_meter.py. from microbit import * P0_MAX = 812 def barchart(y, v, vmax): v = min(v, vmax) leds = int(v * 5 / vmax) for x in range(leds): display.set_pixel(x, y, 9) # main program while True: reading = pin0.read_analog() display.clear() barchart(4, reading, P0_MAX) if button_a.was_pressed(): pin2.write_digital(0) # off if button_b.
How It Works The P0_MAX constant sets the maximum value expected from pin P0, and this is the value that represents 100% charged. You might have to experiment with the value here to get the best performance from your barchart. barchart() draws a horizontal line on the display, by turning on a different number of LEDs. 'y' is the position on the display where the barchart will appear, 'v' is the value to display, and 'vmax' is the maximum value to expect.
sumd = 0 prevval = None def trend(newval): global prevval, sumd if prevval is not None: olddiff = diffs.pop(0) newdiff = newval - prevval diffs.append(newdiff) sumd = sumd - olddiff + newdiff print(prevval, newval, newdiff, sumd) prevval = newval if abs(sumd) >= SIGNIFICANT: return sumd return 0 # no change def barchart(y, v, vmax): v = min(v, vmax) leds = int(v * 5 / vmax) for x in range(leds): display.set_pixel(x, y, 9) while True: reading = pin0.read_analog() display.
How it Works The two new images are set up in the constants CHARGING and DISCHARGING. Each number represents one pixel on the micro:bit screen, 0 is off and 9 is full on. These names are upper case because Python programmers use this convention to remind them that they are constant and shouldn't change throughout the program.
Experiments 1. Try different light sources. How bright a light is needed before the CHARGING indicator lights up? 2. When you have a lot of charge stored, press the B button to turn the fan on. How long does it take before the DISCHARGING indicator appears? 3. Leave the fan running for at least 10 seconds then press the A button to stop the fan. How long does it take before the DISCHARGING indicator disappears? 4.
PROJECT 5 – ENERGY LOGGER In this project you will build a device that can be connected to your personal computer, and it will allow you to draw graphs of energy usage in real time. This will make it easier for you to measure and understand how long it takes to both harvest and consume energy.
Code for the Energy Logger (MakeCode) The code for this project can be accessed here: https://makecode.microbit.org/_Avq2HMMfp2gp How it works The code loops round once per second and takes a reading from the P0 pin. This reading is sent via the serial port, which transfers the data over the USB lead to your computer. A reading will be somewhere between 0 (for 0V) and 1023 (for 3V), and the voltage at the P0 pin will change as the amount of stored charge changes.
Connecting to Your PC MakeCode has a useful feature that allows you to stream live data from a micro:bit, and it will draw a live graph of that data. It also allows you to store the same data in a file that can be loaded and analysed in other programs. Pairing Your micro:bit With MakeCode To use the graphing feature, you first have to pair your micro:bit with MakeCode. Click on the pair device link on the MakeCode page and follow the on-screen instructions.
Capturing Data From a Charge and Discharge Cycle In order to work out the key parameters of your system, you need to do a complete charge and discharge cycle. 1. Charge your system up completely by arranging for the Solar Panel to be near a bright light or in sunlight. As the system charges up you will see the graph line in MakeCode increasing and the number at the top right of the graph will get bigger and bigger before it stops. On our system, the charging stopped at about 800. 2.
Getting Data into a Spreadsheet Program You can now open this file with either LibreOffice or Excel. Let's look at how to do that in LibreOffice, which is a free program that can be downloaded from: https://www.libreoffice.org/ (but the steps in Microsoft Excel will be similar). Open LibreOffice and choose FILE then NEW/SPREADSHEET, then FILE followed by OPEN from the menu. Find the downloaded microbit-data.txt file in your downloads folder.
Graphing the Data A picture is always much easier to understand, so you can also use your spreadsheet to draw a graph of the data to help you visualise the charge and discharge cycles. Select column A in the spreadsheet then use INSERT/ CHART from the menu. Choose a line graph without points and press FINISH, and you will see something like this: In the above graph, you can see a charge cycle, a discharge cycle, and a second charge cycle.
Understanding the Data So, why is all this data important? Remember, the numbers you calculate here will be unique to your environment and lighting conditions. The duty cycle of a system, refers to how long you are charging for, and how long you are discharging for. So a duty cycle of 50% spends half of its time charging, and half of its time discharging.
HOW THE SOLAR STORE WORKS There are a number of components and parts to the Solar Store, and knowing a little bit about how a circuit works can help you to decide how to best use it in your projects. Let's take a look at the three main parts of the board and what they do. 3V GND D1 5 1 D3 2 3 3V 4 6 Filling Storage 7 GND Release Filling Stage A voltage from the Solar Panel appears at the board, and a one-way valve (1) prevents damage to the circuit if the panel is wired up the wrong way round.
PROJECT 6 – INTELLIGENT COOLING FAN In this final project, you will use all the measurements you took from the previous project, and build an intelligent cooling fan. This cooling fan will only turn on when things are warming up, and it will turn off automatically when things cool down. As a final modification, you will also add some code that estimates how much longer the fan will run for and display a count-down on the screen.
Code for the Intelligent Cooling Fan (MakeCode) You can access this code from this link: https://makecode.microbit.org/_ATgfJtK9fMa5 How it Works Using the numbers for TOC and BOC from project 5, fill in the CHARGED and DISCHARGED constants in this program, to calibrate it for your specific environment.
The main loop of this program senses the temperature and stored charge once per second, and consults two functions fan_needed and fan_notneeded to decide whether the fan is needed or not. The logic inside these functions could have been used directly without a function, but using a function makes it easier for you to fine tune this detection logic independently of the main program. Both functions return a TRUE or a FALSE depending on the desired outcome.
Code for the Intelligent Cooling Fan (MicroPython) This is program p6-intelligentfan.py. from microbit import * CHARGED = 818/2 DISCHARGED = 220 HOT = 23 COLD = 20 override = False temp = 0 def read_temp(): global temp temp = temperature() if override: temp = HOT def fan_needed(): return stored >= CHARGED and temp >= HOT def fan_not_needed(): return stored <= DISCHARGED or temp <= COLD def fan_on(): pin2.write_digital(1) display.show(Image.YES) def fan_off(): pin2.write_digital(0) display.show(Image.
if fan_needed(): fan_on() elif fan_not_needed(): fan_off() print(stored, temp) sleep(1000) Adding Time Estimation In project 5, you also calculated how long it takes your system to charge up to top of charge, and discharge down to bottom of charge. These times significantly affect the duty cycle of the system and will limit how long and how often you can use the fan, based on your specific lighting conditions.
("99","09","09","09","09"), ("99","99","00","99","99"), ("99","99","99","09","99") ) def img(n): lg = FONT[int(n/10)] rg = FONT[int(n%10)] c = "" for r in range(5): c += lg[r] + "0" + rg[r] if r != 4: c += ':' return Image(c) def digits(n): if n > 99: display.show(Image.CHESSBOARD) else: display.
# main program while True: # sensing stored = pin0.read_analog() if button_a.was_pressed(): override = True if button_b.was_pressed(): override = False read_temp() # control if fan_needed(): fan_on() elif fan_not_needed(): fan_off() # display digits(remaining(stored)) print(stored, temp) sleep(500) How it Works This is a really simple estimator that makes a number of quite broad assumptions about the system, but it is good enough as a rough indicator to the user of how long they can use the fan for.
This graph shows the discharge cycle that you captured earlier in project 5. When the Solar Store is fully charged it is at the Top of Charge (TOC). Turning on the fan then consumes the energy in the Solar Store, and this powers the fan and slowly discharges the Solar Store, as shown by the downwards diagonal line.
TROUBLESHOOTING The Bulb is not lighting – make sure you have enough charge stored in the Solar Store, as the Bulb has a minimum turn-on voltage. Also make sure you have connected the Enable signal of the Solar Store. Check that the Bulb is connected the right way round. The fan is not turning – the motor used in the fan is quite low power, but it is not as low power as the bulb.
ABOUT THE AUTHOR David Whale is an embedded software engineer and a STEM ambassador who volunteers in schools in the UK. He has been an active member of the micro:bit community since its inception. He contributed to the original BBC micro:bit project, advising The IET and BBC and helping to write and deliver training courses to teachers around the UK.
MONK MAKES KITS For more information on this kit, the product's home page is here: https://monkmakes.com/mb_solar As well as this kit, MonkMakes produce all sorts of kits and gadgets to help with your maker projects. Find out more, as well as where to buy here: https://www.monmkakes.