From 5ac95f82ba7fb3e67b09b02d0f5be3d791da4562 Mon Sep 17 00:00:00 2001 From: Joseph Timothy Foley Date: Wed, 25 Feb 2026 18:30:44 +0100 Subject: [PATCH] Code for the PrimoWhip Arduino prototype --- .gitignore | 2 ++ primowhip.ino | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 primowhip.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cce990e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*! +*~ diff --git a/primowhip.ino b/primowhip.ino new file mode 100644 index 0000000..cf34b3f --- /dev/null +++ b/primowhip.ino @@ -0,0 +1,67 @@ +#include // Include the Arduino library + +// Pin numbers defined +const int pinD3 = 3; +const int pinA1 = A1; // Define A1 pin as A1 + +// Constants for ADC to current conversion +const float referenceVoltage = 5.0; //5V logic +const int adcMax = 1023; +const float voltsToAmps = 1.0 / 1.2; // Conversion factor: 1A per 1.2V + +// Threshold current value in amperes +const float currentThreshold = 1.1; +const int consecutiveLimit = 3; // Number of consecutive readings needed to stop the motor + +void setup() { + // Initialize the serial communication + Serial.begin(9600); + + // Set pin D3 as an output to turn on and off cream whipper + pinMode(pinD3, OUTPUT); + + // Set pin D3 to HIGH (5V) + digitalWrite(pinD3, HIGH); + Serial.println("Pin D3 set to HIGH (5V)"); + + int consecutiveHighCurrent = 0; // Counter for consecutive high current readings + + // 150-second countdown so cream whipper won't run forever if you put unwhippable liquids in it + for (int i = 150; i > 0; i--) { + // Read the value from A1 + int adcValue = analogRead(pinA1); + + // Convert ADC value to voltage + float voltage = (adcValue * referenceVoltage) / adcMax; + + // Convert voltage to current + float current = voltage * voltsToAmps; + + // Print countdown time and current value + Serial.print("Time left: "); + Serial.print(i); + Serial.print(" seconds, Current: "); + Serial.print(current); + Serial.println(" A"); + + // Check if current exceeds the threshold + if (current > currentThreshold) { + consecutiveHighCurrent++; + } else { + consecutiveHighCurrent = 0; // Reset counter if current is below threshold + } + + // Stop the motor if the threshold is exceeded 3 times in a row + if (consecutiveHighCurrent >= consecutiveLimit) { + digitalWrite(pinD3, LOW); + Serial.println("Motor stopped due to high current!"); + break; // Exit the countdown loop + } + + delay(1000); // Wait 1 second + } + + // Ensure pin D3 is set to LOW (0V) at the end + digitalWrite(pinD3, LOW); + Serial.println("Pin D3 set to LOW (0V)"); +}