O'Reilly logo

Arduino Android Blueprints by Stefan Buttigieg, Marco Schwartz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing the Arduino sketch

Now that we are sure that the connections of the relay, the current sensor, and the power cables are correct, we will write an Arduino sketch to accept connections coming via Wi-Fi from the Android device.

The following is the complete sketch for this part:

// Import required libraries #include <Adafruit_CC3000.h> #include <SPI.h> #include <aREST.h> // Relay state const int relay_pin = 8; // Define measurement variables float amplitude_current; float effective_value; float effective_voltage = 230.; // Set voltage to 230V (Europe) or 110V (US) float zero_sensor; // These are the pins for the CC3000 chip if you are using a breakout board #define ADAFRUIT_CC3000_IRQ 3 #define ADAFRUIT_CC3000_VBAT 5 #define ADAFRUIT_CC3000_CS ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required