#02_14 Solar Panel Voltage Logging with NearBus Cloud Connector and Xively
Posted by Superadmin on November 28 2018 05:07:22

Solar Panel Voltage Logging with NearBus Cloud Connector and Xively

 


Do you want to synchronize your Arduino board memory with cloud memory? Then this is the solution for memory mapping between Arduino and cloud. The memory mapping is done by mirroring or replicating a small part of Arduino's memory into the cloud's memory. So, reading or writing on the cloud's memory will have the same effect as reading or writing directly into the Arduino's memory.

The objective of this project is to log the voltage values generated by a solar cell against the time.

In this chapter, you will learn:

Connecting a solar cell with the Arduino Ethernet board

We will use the following hardware to build the circuit:

Also, you will need a computer with an Arduino IDE installed.

Building a voltage divider

A voltage divider is a simple circuit that can be used to turn higher voltage into lower voltage through a series of two resistors. The resistor values depend on the input voltage and the mapped output voltage:

For this project, we are using Sparkfun Solar Cell Large—2.5W (PRT07840). The open voltage of this solar cell is 9.15V (take a look at the datasheet for open voltage specification).

SparkFun Solar Cell Large - 2.5W Image courtesy of SparkFun Electronics (https://www.sparkfun.com)

So, we can calculate the resistor values for the voltage divider by using the following equation:

Therefore, the following can be derived:

Building the circuit with Arduino

The following Fritzing diagram shows how to connect the voltage divider and solar cell with the Arduino Ethernet board. Now, start building the circuit according to the following diagram and steps provided:

This particular solar cell comes with a DC barrel jack plug attached, and it is center positive. Plug it to the DC barrel jack adapter. Now solder two wires to the positive and negative terminals of the DC barrel jack adapter, as shown in the following image:

Connect the other wires as explained in the following steps:

  1. Connect the voltage divider's output (Vout) with the Arduino analog pin 0 (A0).

  2. Connect the solar cell's positive wire with voltage divider's Vin.

  3. Connect the solar cell's negative wire to Arduino GND.

  4. Connect the Arduino Ethernet board to a network switch or router using an Ethernet cable.

  5. Power the Arduino Ethernet board using a 9V DC 650mA wall adapter power supply.

Now, the circuit and hardware setup is complete, and in the next section you will learn how to set up a NearBus account and connect your Arduino Ethernet shield to the NearBus Cloud for solar cell voltage logging.

Setting up a NearBus account

Setting up a NearBus account is simple. Visit the NearBus home page at http://www.nearbus.net/ and click on Sign Up in the main menu. This will navigate you to the new user signup page with a simple form to enter your registration information. Enter your information as described in following steps:

  1. E-mail: Type a valid e-mail address.

  2. User name: Type your preferred name for the NearBus account.

  3. Password: Type a secret word and don't share it with others.

  4. Then, click on the checkbox of the captcha section to verify that you are a human.

  5. Finally, click on the Sign Up button.

Now you have successfully registered with the NearBus website and you will be navigated to the Login page. Now, enter the following information to log in.

  1. Username: Type your user name.

  2. Password: Type your password.

  3. Click on the Login button.

Defining a new device

Now, you can define a new device with the NearBus cloud connector. In this chapter, we will work with the Arduino Ethernet board. If you have an Arduino Ethernet Shield, you can stack it with an Arduino board and test it with the samples provided in this chapter.

  1. On the NearBus website menu bar, click on New Device. You will be navigated to the NEW DEVICE SETUP page.

  1. You can enter a value for each parameter and the only mandatory field is SHARED SECRET. It is eight characters long. Other fields are optional.



DEVICE NAME (Maximum 18 characters)

Arduino Ethernet 

LOCATION

 

FUNCTION

 

SHARED SECRET

12345678

PIN

 

CALLBACK SERVICE

 

DEVICE IDENTIFIER

 

DEFAULT REFRESH RATE [ms]

 

  1. Click on the Setup button.

Examining the device lists

After setting up the new device, you will navigate to the DEVICE LIST page. The NearBus system will assign a DEVICE ID to your new device and display your device name under the device alias. However, your new device will not have been mapped with NearBus. The mapped status shows as DOWN, which is highlighted in the following:

You will need this DEVICE ID when you write an Arduino sketch for this device.

Later, you can visit to the device list page by clicking on Device List on the menu bar.

Downloading the NearBus agent

To use your Arduino Ethernet Shield, or Arduino Ethernet board with the NearBus cloud connector, you must download and install the NearAgent code library. You can download the latest version of the NearBus library for Arduino at http://www.nearbus.net/v1/downloads.html. Also, you can visit the download page by clicking on Downloads on the NearBus web page menu bar. The following screenshot shows the Download page:

For this project, we need Arduino library for Ethernet, and the latest version is 16. Click on the NearBusEther_v16.zip link to download the library, or type http://www.nearbus.net/downloads/NearBusEther_v16.zip on your browser's address bar and hit Enter to download it on your computer's hard drive. Then, extract the downloaded ZIP file into the Arduino libraries folder.

Also, you need to download the FlexiTimer2 from http://github.com/wimleers/flexitimer2/zipball/v1.1 and extract the ZIP file into the Arduino libraries folder. You can read more about the FlexiTimer2 at https://github.com/wimleers/flexitimer2, which is the GitHub page, and you can even download it from there.

Perform the following steps to modify the sample code to read the voltage:

  1. Open your Arduino IDE.

  2. In the menu bar, click on File | Examples | NearBusEther_v16 | Hello_World_Ether. The sample code will load into the Arduino IDE. Also, you can copy and paste the sample sketch, B04844_05_01.ino, into your Arduino IDE which is located in the code folder of Chapter 5.

  3. Save the sketch in another location by selecting File | Save As from the menu bar. Now, make the following modifications to the sample code to work with your Arduino Ethernet board or Ethernet Shield.

  4. Modify the following code lines with your NearBus configuration's Device ID and Shared Secret. The Device ID can be found at the Device List page:

char deviceId [] = "NB101706"; // Put here the device_ID generated by the NearHub ( NB1xxxxx )

char sharedSecret[] = "12345678"; // (IMPORTANT: mandatory 8 characters/numbers) - The same as you configured in the NearHub

  1. Replace the MAC address with your Arduino Ethernet board's MAC address:

byte mac[6] = { 0x90, 0xA2, 0xDA, 0x0D, 0xE2, 0xCD }; // Put here the Arduino's Ethernet MAC

  1. Comment the following line:

//pinMode(3, OUTPUT); 

  1. Then, uncomment the following line:

///////////////////////////////////
// Example 1 - Analog Input
// Mode: TRNSP
///////////////////////////////////
A_register[0] = analogRead(0); // PIN A0

Remember, our solar panel is connected to the Arduino analog pin, 0 (A0). But you can attach it to another analog pin and make sure that the pin number is modified in the sketch.

  1. That's all. Now, connect your Arduino Ethernet board with the computer using an FTDI cable.

  2. Select the board type as Arduino Ethernet (Tools | Board | Arduino Ethernet), and select the correct COM port (Tools | Port).

  3. Verify and upload the sketch into your Arduino Ethernet board.

  4. Now, revisit the DEVICE LIST page. You can see the Device's STATE is changed to UP and highlighted:

Now, your Arduino Ethernet Shield's internal memory is correctly mapped with the NearBus cloud.

In the next section, we shall learn how to feed our solar panel voltage readings to the Xively and display the real time data on a graph.

Creating and configuring a Xively account

Xively (formerly known as Cosm and Pachube) is a cloud-based platform that provides remote access to devices like Arduino and many more. You can read condensed information about Xively by visiting https://en.wikipedia.org/wiki/Xively.

Using your web browser, visit http://xively.com/:

There is no link label to sign up in the web page, so type https://personal.xively.com/signup in your web browser's address bar and directly visit the Sign Up page.

After a successful sign up with Xively, you will get an e-mail with an activation link. Click on the activation link.

You will be redirected to the Welcome to Xively web page:

Click on DEVELOP from the top menu bar. The Development Devices page will appear:

Click on +Add Device. The Add Device page will appear:

Fill the following textboxes with relevant information:

Click on the +Add Channel button:

To add a channel, follow these steps:

  1. Fill in the following information:

  2. Click on the Save Channel button to save the channel.

  3. On the right-hand side of the page, under API Keys, you can find out the Xively API Key and Feed ID for this device.

  1.  

Configuring the NearBus connected device for Xively

Perform the following steps to configure the NearBus connected device for Xively:

  1. Log in to your NearBus account.

  2. Click on the DEVICE LIST menu. The DEVICE LIST page will appear:

  1. From the drop-down menu, select COSM CONFIG.

  2. Click on the Setup button. The COSM CONNECTOR (xively.com) page will appear:

  1. In this page, you have to enter some configuration settings in order to work your Arduino with NearBus and Xively. Here, we are using the NearBus channel 0 to communicate with our device. So, configure the following entries for the channel 0 entry using the CMOS CONNECTOR (xively.com) page:

  2. Click on the Setup button.

  3. Now, switch to your Xively web page. On the left-hand side of the page, you can see a graph displaying your solar cell voltage with time. If you can't see the graph, click on the channel ID to expand the graph:

Developing a web page to display the real-time voltage values

Use the following chart to find the time zone for your device. The following two examples will show you how to find the correct time zone value:



Zone

Place names

UTC -11:00

International Date Line West, Midway Island, Samoa

UTC -10:00

Hawaii

UTC -09:00

Alaska

UTC -08:00

Pacific Time (US & Canada), Tijuana

UTC -07:00

Arizona, Chihuahua, Mazatlan, Mountain Time (US & Canada)

UTC -06:00

Central America, Central Time (US & Canada), Guadalajara, Mexico City, Monterrey, Saskatchewan

UTC -05:00

Bogota, Eastern Time (US & Canada, Indiana (East)), Lima, Quito

UTC -04:30

Caracas

UTC -04:00

Atlantic Time (Canada), La Paz, Santiago

UTC -03:30

Newfoundland

UTC -03:00

Brasilia, Buenos Aires, Georgetown, Greenland

UTC -02:00

Mid-Atlantic

UTC -01:00

Azores, Cape Verde Is.

UTC +00:00

Casablanca, Dublin, Edinburgh, Lisbon, London, Monrovia

UTC +01:00

Amsterdam, Belgrade, Berlin, Bern, Bratislava, Brussels, Budapest, Copenhagen, Ljubljana, Madrid, Paris, Prague, Rome, Sarajevo, Skopje, Stockholm, Vienna, Warsaw, West Central Africa, Zagreb

UTC +02:00

Athens, Bucharest, Cairo, Harare, Helsinki, Istanbul, Jerusalem, Kyev, Minsk, Pretoria, Riga, Sofia, Tallinn, Vilnius

UTC +03:00

Baghdad, Kuwait, Moscow, Nairobi, Riyadh, St. Petersburg, Volgograd

UTC +03:30

Tehran

UTC +04:00

Abu Dhabi, Baku, Muscat, Tbilisi, Yerevan

UTC +04:30

Kabul

UTC +05:00

Ekaterinburg, Islamabad, Karachi, Tashkent

UTC +05:30

Chennai, Kolkata, Mumbai, New Delhi, Sri Jayawardenepura

UTC +05:45

Kathmandu

UTC +06:00

Almaty, Astana, Dhaka, Novosibirsk

UTC +06:30

Rangoon

UTC +07:00

Bangkok, Hanoi, Jakarta, Krasnoyarsk

UTC +08:00

Beijing, Chongqing, Hong Kong, Irkutsk, Kuala Lumpur, Perth, Singapore, Taipei, Ulaan Bataar, Urumqi

UTC +09:00

Osaka, Sapporo, Seoul, Tokyo, Yakutsk

UTC +09:30

Adelaide, Darwin

UTC +10:00

Brisbane, Canberra, Guam, Hobart, Melbourne, Port Moresby, Sydney, Vladivostok

UTC +11:00

Magadan, New Caledonia, Solomon Is.

UTC +12:00

Auckland, Fiji, Kamchatka, Marshall Is., Wellington

UTC +13:00

Nuku'alofa

Displaying data on a web page

Now, we will look at how to display the temperature data on a web page using HTML and JavaScript by connecting to the Xively cloud.

  1. Copy the following index.html file from the code folder of Chapter 5 to your computer's hard drive.

  2. Using a text editor (Notepad or Notepad++), open the file and edit the highlighted code snippets using your NearBus and Xively device configuration values. Modify the device ID, user, and password:

var device_id = "NB101706"; // Your device ID
var user = "****"; // Your NearBus Web user
var pass = "****"; // Your NearBus Web password

Following are the variables:

  1.  
  2. Replace 1 with your NearBus channel ID:

ret = NearAPIjs( "ADC_INPUT", device_id , 
1
, 0, "RONLY" );

  1. Replace 1910481586 with your Xively device Feed ID, 1.png with your NearBus channel ID (only replace the number part) and 5.5 with your time zone.

<div id="div_temp_chart_cm"> <img src="https://api.cosm.com/v2/feeds/
1910481586
/datastreams/
1
.png?width=750&height=400&colour=%23f15a24&duration=3hours&show_axis_labels=true&detailed_grid=true&timezone=
5.5
" > </div>

You can also modify the cosm to Xively in the preceding URL because both are working. The modified URL can be written as follows:

<div id="div_temp_chart_cm"> <img src="https://api.
xively
.com/v2/feeds/
1910481586
/datastreams/
1
.png?width=750&height=400&colour=%23f15a24&duration=3hours&show_axis_labels=true&detailed_grid=true&timezone=
5.5
" > </div>

  1. Now, save and close the file. Then, open the file using your preferred web browser. You will see a graph displaying the real-time voltage values against the time which is continuously updating.

  2. Also, you can copy the file into your smart phone's SD card or its internal memory, and then open it with the mobile web browser to see the real time graph.

  3. The following image shows a real time graph that is plotting the output voltage of a solar cell, where the x axis represents the time (t) and the y axis represents the voltage (V):

Summary

In this chapter, you have learned how to log your solar cell voltage using the NearBus and Xively cloud platforms and access them remotely from anywhere in the world using a mobile device. You can modify this project to log data from any type of sensor and also add more channels to display multiple data streams on a single graph.