// Connect your Dynamo set to Arduino! // Connect the 4.3v dynamo output to GPIO 8 of your Arduino UNO. Connect the GND pin fom the dynamo board to one of the GND pins of your UNO as well. // If you want to connect an active low relay board to control with this program, connect the input signal line to your relay board, to GPIO 7 of your Arduino UNO // Continued: Connect the 5v line from your UNO to the power supply pin of your relay board, and lastly, connect another GND pin from your UNO to the GND terminal of your relay board #define dynamo 8 // Declare GPIO 8 as our dynamo input #define relay 7 // Declare GPIO 7 as your relay control pin int charge = 0; // This integer will be used to determine if the set is "charging" void setup() { pinMode(dynamo, INPUT); // Dynamo pin is an input pinMode(relay, OUTPUT); // Relay pin is an output digitalWrite(relay,HIGH); // Because the relay board is active low, turn off the relay by setting the control line to 5v Serial.begin(9600); // start serial to PC delay(1000); // Wait for one full second Serial.println("SYSTEM READY TO CHARGE!"); // Print this to the serial monitor. You'll need to open the serial monitor to see this. } void loop() { if(digitalRead(dynamo) == HIGH) // Execute the following if the dynamo is being turned { delay(1000); // Wait for one full second Serial.println("SYSTEM CHARGING!"); // Print this to the serial monitor delay(1000); // Wait for one more second int a; // Introduce integer "a" for (a = 0; a < 5; a++) // The code in this for statement will be executed 5 times { delay(1000); // Wait for one full second if(digitalRead(dynamo) == HIGH) // If the dynamo is still being turned { charge = charge + 1; // Then add a value of 1 to the "charge" integer } } if(charge == 5) // If after the FOR statement has completed, if the "charge" integer has a value of 5, then the system is charged. Execute the following. { Serial.println("SYSTEM CHARGED - RELAY ON... DEACTIVATING IN 20 SECONDS"); // Print this to the serial monitor digitalWrite(relay,LOW); // Turn the relay on delay(20000); // Wait for 20 seconds Serial.println("RELAY DEACTIVATED"); // Print this to the serial monitor digitalWrite(relay,HIGH); // Turn the relay off delay(3000); // Wait for three seconds Serial.println("SYSTEM READY TO CHARGE!"); // Print this to the serial monitor, and start the loop from the beginning } else // If charge oes NOT = 5, execute the following { Serial.println("SYSTEM NOT CHARGED"); // Print to the serial monitor delay(3000); // Wait for three seconds Serial.println("SYSTEM READY TO CHARGE!"); // Print to the serial monitor, and start the loop from the beginning } } } // End of program