Solar Powered Mbed

The aim of this project is to operate an Mbed application in a low power mode. For this purpose, we power the Mbed using a solar e-power II cell. The USB powered Mbed draws current typically in the range of 160 mA. The figure below shows the reduction and power saving in the current drawn-in the order of 66mA.


The application that is run is the interfacing of an IR sensor which periodically logs in a time stamped data into a SD card and also displays the same on the PC through the RS 232 interface. Typical appications of this type of IR sensor could be in batch monitoring or counting systems with human overview.



SD Card Interface:

SparkFun MicroSD Breakout Board

  • MicroSD mbed
  • CS <-> p8
  • DI <-> p5 (SPI mosi)
  • VCC <-> VOUT
  • SCK <-> p7 (SPI sclk)
  • GND <-> GND
  • DO <-> p6 (SPI miso)
  • CD <-> (No Connection)

RS232 Connections:

SparkFun RS232 Breakout Board

  • RS232 MBED
  • Vcc <-> Vout
  • Gnd <-> Gnd
  • Txo <-> p27
  • Rxi <-> p28

For this experiment, any sensor like temperature,pressure etc can be interfaced. For the demo we have used Sharp IR sensor.


  • Sensor MBED
  • Vcc <-> Digitalout
  • Gnd <-> Gnd
  • AnalogIn <-> p20


How is Power Management Achieved?

  1. By turning down the PHY Module (Ethernet Interface).
  2. Semihost Powerdown (MBED is powered through Vin pin)
  3. Selective powering of IR Sensor only when needed.
  4. Using ticker interrupts to wake from "sleep" and periodically service the routine to log in the data.


Main Function

#include "string.h"
#include "mbed.h"
#include "SDFileSystem.h"
#include "PowerControl.h"
#include "EthernetPowerControl.h"
AnalogIn ain(p20);
DigitalOut sensor(p15);
Serial pc(p28, p27);
SDFileSystem sd(p5, p6, p7, p8, "sd"); 
#define USR_POWERDOWN    (0x104)

int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
Ticker sense; // Ticker to Interrupt the sleeping mode
Timer t;

void sd_write_read() {
    char data[100];
    int time_stamp;;
    sensor=1;   /* Power up Sensor only when necessary */
    pc.printf("\n Writing into SD card... \n");
    pc.printf("\n Writing Sensor Data... \n");
    mkdir("/sd/mydir", 0777);
    /* Following code does a conditional check on analog in to determine the distance from IR Sensor */
    if (ain < 0.3) {
        strcpy(data,"Its approximately 30 cm away");
    } else if (ain > 0.3&&ain < 0.5) {
        strcpy(data,"Its approximately 20 cm away");
    } else if (ain>0.5 && ain < 0.6) {
        strcpy(data,"Its approximately 15 cm away");
    } else {
        strcpy(data,"Its approximately 10 cm away");

    /* Open the File for writing into the SD Card */
    FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
    if (fp == NULL) {
        error("Could not open file for write\n");
    fprintf(fp, "%d : %s \n",time_stamp,data);  /* Record Sensor data along with time stamp */
    sensor=0;   /* Power down Sensor after data is logged */

int main() {
    int result; 
    PHY_PowerDown();                    /* PHY Powerdown */
    result = semihost_powerdown();      /* Semihost Powerdown */
    sense.attach(&sd_write_read, 5);    /* Excecute sd_write_read function every 5s */
    t.start();                          /* Start of timer to record Time Stamp */
    while (1) {
        Sleep();                        /* Sleep mode to save power */

The entire code with libraries is available at


Please log in to post comments.