Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Test a single coil latching relay: KEMET EC2-3SNU
- https://content.kemet.com/datasheets/KEM_R7002_EC2_EE2.pdf
- This test is using a 5V Arduino NANO but all other circuitry is 3V3.
- Switching the Arduino output pins LOW applies an open collector ground
- while switching the Arduino output pins to HIGH applies 3.3V via
- external 20 ohm pullup resistors.
- NOTE: Since the contact load is resistive no snubber circuit is used.
- NOTE: The EC2-3SNU set/reset Pulse Width requirement: > 10 ms
- CONNECTIONS:
- NANO-2 -to- EC2-3SNU pin 1
- NANO-3 -to- EC2-3SNU pin 12
- LED-D2 -to- EC2-3SNU pin 3
- LED-D1 -to- EC2-3SNU pin 5
- */
- #define COILP 2 // S+ (Pulse polarity to SET)
- #define COILN 3 // S- (Pulse polarity to SET)
- #define DEFAULT_PULSE 15 // Pulse Width: > 10 ms
- int loops = 0;
- int Pulsewidth = 15; // Pulsewidth in ms
- void setup() {
- int n;
- //start serial connection
- Serial.begin(9600);
- // Start with relay coil pins with 3V3 applied via pullups
- pinMode(COILP, OUTPUT); // Relay coil pin 1
- pinMode(COILN, OUTPUT); // Relay coil pin 12
- digitalWrite(COILP, HIGH); // 3V3 applied via pullup
- digitalWrite(COILN, HIGH); // 3V3 applied via pullup
- pinMode(LED_BUILTIN, OUTPUT); // Pin 13 on NANO
- digitalWrite(LED_BUILTIN, LOW); // Set the LED to off
- digitalWrite(LED_BUILTIN, HIGH); // Set the LED to on - alive blink
- delay(50);
- digitalWrite(LED_BUILTIN, LOW); // Set the LED to off
- Serial.println("Press ENTER to start");
- while (Serial.available() == 0) {
- // Wait for User to Input Data
- }
- Serial.parseInt(); // Discard input (assumed to be an ENTER)
- // Offer user opportunity to temporarily change Pulsewidth
- Serial.print("Pulsewidth is ");
- Serial.print(Pulsewidth);
- Serial.println(". Enter new value or just ENTER to keep current ?");
- while (Serial.available() == 0) {
- // Wait for User to Input Data
- }
- n = Serial.parseInt();
- if(n >0)
- {
- Pulsewidth = n;
- }
- Serial.println("");
- Serial.print("Pulsewidth is ");
- Serial.println(Pulsewidth);
- }
- void Relay_Quiescent()
- {
- digitalWrite(COILP, HIGH); // External pullup applies 3V3
- digitalWrite(COILN, HIGH); // External pullup applies 3V3
- }
- void Relay_Set()
- {
- digitalWrite(LED_BUILTIN, HIGH); // Builtin LED to ON
- digitalWrite(COILN, LOW); // External pullup applies 3V3
- digitalWrite(COILP, HIGH); // Apply GND sink
- delay(Pulsewidth);
- Relay_Quiescent();
- }
- void Relay_Reset()
- {
- digitalWrite(LED_BUILTIN, LOW); // Builtin LED to OFF
- digitalWrite(COILN, HIGH); // External pullup applies 3V3
- digitalWrite(COILP, LOW);
- delay(Pulsewidth);
- Relay_Quiescent();
- }
- /************************
- * Main Endless Loop
- ************************
- */
- void loop() {
- loops += 1;
- Serial.print("Loop# ");
- Serial.print(loops);
- Serial.println(" iteration");
- // Set the relay
- Serial.println("SETting relay");
- Relay_Set();
- delay(3000); // delay 3 seconds between set/reset
- Serial.println("RESETting relay");
- Relay_Reset();
- delay(3000); // delay 3 seconds between Reset/set
- }
Add Comment
Please, Sign In to add comment