Here is a concept sketch of an automatic rice cooker that utilizes some sort of sensor to measure the rice and water levels for precise cooking allowing for a perfect batch of rice EVERY TIME! I haven't had the chance to pursue this idea because the Arduino components I have aren't accurate enough and I haven't researched other methods. The code I wrote based on the Arduino's Ultrasonic Sensor is functional, just the accuracy of the components prevent it from working properly.
the ultrasonic sensor can measure differences in height due to the rice and water being added, which can be used in the program
I upgraded the setup and taped the device to a cardboard cutout, the oval shaped cutout allows for water to be added
I made a 3rd setup because I thought the water measurements weren't accurate because the ultrasonic sensor was too close. It also made adding water a lot easier because there is more space. It ended up not functioning properly due to the inaccuracies of the sensor.
const int trigPin = 9;
const int echoPin = 10;
const int buttonPin = 0;
float emptyRice = 7.21;
int buttonState = 0;
float distance, riceLevel, waterLevel,riceDistance;
long duration;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buttonPin,INPUT);
Serial.begin(9600);
}
void loop() {
// Serial.println("PRESSED");
// digitalWrite(trigPin, LOW);
// delayMicroseconds(2);
// digitalWrite(trigPin, HIGH);
// delayMicroseconds(10);
// digitalWrite(trigPin, LOW);
// Serial.println(pulseIn(echoPin, HIGH));
// duration = pulseIn(echoPin, HIGH);
// distance = duration*.0343/2;
// Serial.println(distance);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
// Serial.println(calculateWaterLevel(3.00));
buttonState = digitalRead(buttonPin);
if(buttonState == LOW)
{
Serial.println("PRESSED");
// Serial.println(calculateWaterLevel(distance));
riceLevel = emptyRice - distance;
riceDistance = distance;
// waterLevel = calculateWaterLevel(distance);
while(true)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.println(distance);
Serial.print("Water to Fill: ");
Serial.println(riceDistance-riceLevel);
if(distance < 0.25)
{
Serial.println("ENOUGH WATER");
}
}
}
delay(100);
}
float calculateWaterLevel(float riceLevel)
{
return 2*(emptyRice-riceLevel);
}