You will need the following parts to build this example:
- Arduino Uno or Nano
- CC3000 breakout or shield
- 10 kilo-ohm, 1/4 watt resistor
- 6x AA or AAA battery holder as a power source
- Batteries, preferably rechargeable. Look for a name brand battery with a datasheet that provides the battery capacity.
- CC3000 VIN to power supply positive.
- CC3000 ground to power supply ground.
- CC3000 CLK to Arduino digital pin 13.
- CC3000 MISO to Arduino digital pin 12.
- CC3000 MOSI to Arduino digital pin 11.
- CC3000 CS to Arduino digital pin 10.
- CC3000 VBEN to Arduino digital pin 5.
- CC3000 IRQ to digital pin 3.
- One photocell lead to Arduino 5V power.
- The other photocell lead through the 10 kilo-ohm resistor to ground.
- From the junction of the photocell and resistor, connect a wire back to an Arduino analog input such as analog pin 4.
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, and ADAFRUIT_CC3000_CS should be set to the appropriate pins which connect the CC3000 to the Arduino.
WLAN_SSID, WLAN_PASS, and WLAN_SECURITY should be set to the appropriate values for your wireless network.
- SENSOR_PIN should be set to the analog input which is connected to the photocell and resistor.
- SERVER_IP and SERVER_PORT should be set to the IP address and port of the computer which will receive photo sensor readings. The IP address should be written with commas instead of periods, for example if your computer has an IP address of 192.168.1.100 you would use a value of '192, 168, 1, 100' without quotes.
To receive measurements on your computer, you can either run a python script (good for Windows, Mac, or Linux with python installed) or use the netcat command (good for Mac or Linux out of the box, or Windows if installed separately).
To run the python listener, in a terminal window navigate to the Scripts subdirectory of the software download and execute this command:
Alternatively, to use the netcat tool in a terminal window execute:
nc -lk 8000
Either server will listen for connections on port 8000 and print out data received to the standard output. The python script will also append the time that each measurement occured, whereas the netcat command won't add anything. You can stop either server by pressing Ctrl-C in the terminal.
Once the server and hardware are running, wait a few minutes to confirm the server receives a measurement from the hardware about once a minute. If you don't see anything on the server after a few minutes, make sure the hardware is configured with the right server IP and there aren't any firewall or routing issues that might block the network traffic.
Looking at the code for this example you'll see it's a fairly simple sketch. The setup() function connects to the WiFi network, and the loop() function waits a minute before sending a new reading to the server using the CC3000 board.
The current consumption of this hardware should be fairly high because both the Arduino and CC3000 constantly run at full power, even when sitting idle between measurements. To confirm this assumption I connected my hardware (an Arduino Nano and CC3000 breakout) to the INA219 current datalogger and measured the current consumption for 5 minutes.
With a measure of the average current consumption, I can estimate and test how long the hardware will run on batteries.
The 160mA discharge current curve is pretty close to the current consumption of this example, 135mA, so the battery capacity should be 750 mAh.
If the hardware's average current consumption was much higher, for example around 800mA or more, I would want to use a lower milliamp-hour rating in battery life calculations. Remember, pulling more current from a battery results in a lower battery capacity.
Dividing the milliamp hour capacity of the batteries by the average current consumption will yield the number of hours I can expect the hardware to run.
Expected battery life:
750 mAh / 135 mA = 5.6 hours
To measure the actual battery life I ran the hardware on batteries and used the INA219 datalogger to measure battery pack voltage over time.
At a full charge the battery cell voltage starts around 1.35 volts. Over time the voltage drops following a curve that's similar to what's seen in the battery datasheet.
Once the battery cell voltage drops below 1 volt the batteries are exhausted and the hardware will quickly stop running. Be careful not to run rechargeable batteries too far below 1 volt or else they might be damaged.
The actual battery life of the hardware was quite close to the expected battery life. Factors such as age of the batteries, ambient temperature, and number of charge/discharge cycles can all affect capacity and might explain some of the difference in expected vs. actual capacity.
Actual Battery Life: