By connecting the output of our circuit to an analog pin on our Feather (or other) microcontroller, we can use software to read the voltage level. Go ahead place the FeatherWing Proto board the Feather -- this will connect the circuit's divided DC output to pin A0 on your Feather microcontroller, as well as common ground.

Don't even *think* of connecting the 'raw' 30VAC or 30VDC to your microcontroller, you will blow it up!

Make sure you can upload code to your Feather -- use this guide if you are just getting started. Once you can successfully upload to the board, move on to the next step.

Copy the above code, and then paste it into a new Arduino sketch. Save it as acRead.ino and then upload it to the Feather. Open the Serial Monitor in the Arduino IDE (Tools > Serial Monitor) and you'll see the values mapped from 0 to 1023 showing up. Apply your AC current by plunging a TNT plunger, or spinning a bicycle wheel light generator, or however else you like, and you'll see the values increase temporarily.

Or, you can visualize things using the Arduino Serial Plotter Tools > Serial Plotter

Now, we can create code to read the voltage level and wait for it to hit a certain threshold before sending the signal to the relay in the power strip.

//Coffee Detonator
// Reads TNT blasting cap detonator voltage levels and 
// triggers a relay to power a coffee grinder
// by John Edgar Park
// for Adafruit Industries
//MIT License
const int analogInPin = A0;  // Analog input pin attached to voltage divider
int sensorValue = 0;        // value read from the pot
int controlPin = 12; // pin attached to relay
int RUNTIME = 5000; //time to grind in millis
void setup() {
  pinMode(controlPin, OUTPUT); //set pin attached to relay as output
  Serial.begin(9600); //use for monitoring and debugging
void loop() {
  sensorValue = analogRead(analogInPin); // read the analog in value
  //Serial.print("sensor = ");
  delay(2);// wait for converter to settle down
  if(sensorValue>=1000){ //anything above this threshold will trigger it
    digitalWrite(controlPin, HIGH);
    digitalWrite(controlPin, LOW);

Copy the above code and save it as a new Arduino sketch called coffeeDetonator.ino. Upload it to the Feather. Now, when the voltage goes up to a certain level, the Feather will close the relay inside the power strip for five seconds. You can adjust this time by changing the "RUNTIME" variable.

This guide was first published on Apr 12, 2017. It was last updated on Apr 12, 2017.

This page (Microcontroller Reading) was last updated on Nov 20, 2021.

Text editor powered by tinymce.