Open jcohenadad opened 1 month ago
Problem of SSR: Most SSR are unidirectional, ie: the DC controls the AC. But here i want to do the other way around.
Sure! Here's the first option written in Markdown format.
This solution uses a non-invasive current sensor to detect when the brew switch on your Rancilio Silvia espresso machine is turned on or off. This method is safe, simple, and does not require making direct electrical connections to the high-voltage AC circuit.
SCT-013-000 Non-Invasive AC Current Sensor
Burden Resistor (if not built-in): 33Ω to 68Ω resistor (needed if the current sensor does not include a built-in burden resistor).
Arduino Board: Any Arduino (e.g., Uno, Nano) to read the current sensor output.
Jumper Wires: For connections between the sensor and the Arduino.
Connect the Current Sensor to the AC Wire:
Wiring the Sensor to the Arduino:
A0
).VCC
, GND
, and Signal
):
Verify Sensor Orientation:
The following code reads the analog signal from the current sensor and determines whether the brew switch is on or off based on a predefined current threshold.
#define CURRENT_SENSOR_PIN A0 // Analog pin to read current sensor value
const int threshold = 50; // Adjust this threshold based on the sensor's output
bool isBrewing = false;
unsigned long startTime = 0;
unsigned long shotDuration = 0;
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read the analog value from the current sensor
int sensorValue = analogRead(CURRENT_SENSOR_PIN);
// If current is detected (above threshold), it means the brew switch is on
if (sensorValue > threshold && !isBrewing) {
startTime = millis(); // Start timing
isBrewing = true;
Serial.println("Brew started!");
}
// If current drops below threshold, it means the brew switch is off
else if (sensorValue <= threshold && isBrewing) {
shotDuration = millis() - startTime; // Calculate shot duration
isBrewing = false;
Serial.print("Brew stopped! Duration: ");
Serial.print(shotDuration / 1000.0); // Convert duration to seconds
Serial.println(" seconds");
}
delay(100); // Small delay to avoid rapid readings
}
Reading Sensor Values:
CURRENT_SENSOR_PIN
(e.g., A0
).Setting a Current Threshold:
threshold
value is used to determine if current is flowing through the wire (indicating the brew switch is on).Starting and Stopping the Timer:
Upload the Code to the Arduino:
Open the Serial Monitor:
9600
in the Serial Monitor.Adjust the Threshold Value:
threshold
value in the code.Additional ressource:
Given that I need something to power the arduino, it makes sense to use the AC power line anyway. So one option would be to
Given that you'd like to power the Arduino using the espresso machine’s power supply and detect the activation of the brew switch, we need to focus on a solution that provides:
Here’s how you can achieve both goals:
The Rancilio Silvia operates on a high AC voltage (120V AC or 230V AC depending on your region). To power the Arduino, you need to step down the AC voltage to a safe DC voltage (e.g., 5V or 9V DC).
AC to DC Converter Module (Buck Converter or Power Adapter):
HiLetgo AC to DC 5V Converter Module:
AC to DC Power Adapter:
5V
pin).Use the Brew Switch’s Power Directly:
Vin
and GND
pins.Since you’ll be using the espresso machine’s power to drive the Arduino, we can use a voltage detection solution to monitor the brew switch state. The following two solutions are suitable:
This solution is ideal if you want to maintain electrical isolation between the high-voltage AC circuit and the low-voltage Arduino circuit.
Digital Pin 2
). Brew Switch (AC Circuit)
┌─────────────────────────────┐
│ │
│ AC Live ─────┬───────────┬┘
│ │ │
│ │ │
┌─────────▼────┐ ┌─────▼────────┐
│ Optocoupler │ │ AC-DC 5V │
│ Input Side │ │ Converter │
│ (LED) │ │ Module │
│ ┌───────┐ │ │ AC In │
│ │ AC+ │──┘ └───AC In──────┘
│ │ │
│ │ AC- │
│ └───────┘
│ ┌───────────────┐
│ │ Output Side │
│ │ (To Arduino) │
└─────────────┼───────────────┘
│ Emitter ─────> GND
│ Collector ───> Pin 2
#define BREW_SWITCH_PIN 2 // Digital pin connected to the optocoupler's output
bool isBrewing = false;
unsigned long startTime = 0;
unsigned long shotDuration = 0;
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(BREW_SWITCH_PIN, INPUT_PULLUP); // Use internal pull-up resistor
}
void loop() {
// Read the state of the optocoupler's output
bool brewSwitchState = digitalRead(BREW_SWITCH_PIN);
// When the brew switch is on, the optocoupler output will be LOW (inverted logic)
if (brewSwitchState == LOW && !isBrewing) {
startTime = millis(); // Start timing
isBrewing = true;
Serial.println("Brew started!");
} else if (brewSwitchState == HIGH && isBrewing) {
shotDuration = millis() - startTime; // Calculate duration
isBrewing = false;
Serial.print("Brew stopped! Duration: ");
Serial.print(shotDuration / 1000.0); // Convert to seconds
Serial.println(" seconds");
}
delay(50); // Small delay to debounce the signal
}
You can use an AC voltage sensor like the ZMPT101B AC Voltage Sensor Module to detect voltage changes across the brew switch and send a corresponding signal to the Arduino.
A0
).#define VOLTAGE_SENSOR_PIN A0 // Analog pin to read voltage sensor output
const int threshold = 512; // Midpoint of 0-1023 analog range
bool isBrewing = false;
unsigned long startTime = 0;
unsigned long shotDuration = 0;
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read the analog value from the voltage sensor
int sensorValue = analogRead(VOLTAGE_SENSOR_PIN);
// If voltage is detected (above threshold), it means the brew switch is on
if (sensorValue > threshold && !isBrewing) {
startTime = millis(); // Start timing
isBrewing = true;
Serial.println("Brew started!");
}
// If voltage drops below threshold, it means the brew switch is off
else if (sensorValue <= threshold && isBrewing) {
shotDuration = millis() - startTime; // Calculate duration
isBrewing = false;
Serial.print("Brew stopped! Duration: ");
Serial.print(shotDuration / 1000.0); // Convert to seconds
Serial.println(" seconds");
}
delay(100); // Small delay to avoid rapid readings
}
Little room for optocoupler behind switch... maybe a current probe is better.
Alternatively, I use no additional sensor associated with the switch, and I just rely on the pressure from the pump!!! At a certain threshold, i can start the timer.
Similar projects:
USING SSR:
Measuring Espresso Shot Duration with Arduino and Rancilio Silvia Machine
Project Overview
This project involves measuring the duration of an espresso shot on a Rancilio Silvia machine using an Arduino. The timer starts when the brew switch is turned on and stops when the switch is turned off.
1. Wiring the Arduino to the Rancilio Silvia Machine
The Rancilio Silvia’s brew switch controls power to the pump or a solenoid valve. We'll use this switch state to detect when the brewing starts and stops.
Components Needed
Wiring Instructions
Identify the Brew Switch Terminals:
Connect the Optocoupler or Relay to the Brew Switch:
Connect the Optocoupler or Relay to the Arduino:
Digital Pin 2
).2. Arduino Code for Timer Functionality
This code example starts a timer when the brew switch is turned on and stops the timer when the switch is turned off.
Explanation of the Code
Pin Definition:
BREW_SWITCH_PIN
: The digital pin connected to the output of the optocoupler or relay module.Variables:
startTime
: Records the start time when the brew switch is turned on.shotDuration
: Calculates the duration of the shot when the brew switch is turned off.isBrewing
: Keeps track of whether the brew is currently ongoing.Loop Logic:
startTime
is recorded.shotDuration
is calculated and printed.3. Testing and Calibration
4. Safety Considerations
5. Alternative Option - Hall Effect or Reed Switch
If you want a non-invasive approach, you can use a Hall effect sensor or a reed switch to detect when the brew switch is toggled (if the switch uses a magnetic field for actuation). This will eliminate the need to work directly with high-voltage components.
6. Troubleshooting
Let me know if this Markdown version works for you or if you'd like me to include any additional information!
Source: ChatGPT with prompt: