I have got my circuit and sketch working on Wokwi, it functions correctly. However the hardwire circuit sees the pump/solenoid turn on and off constantly. I can't see the problem.
#define fullvatswitch_pin 1
#define bottlecapapcityswitch_pin 2
#define ps_pin 4
//#define pot_value 0
//#define motor_value 200
void setup()
{
//Serial.begin(9600);
//define pins
pinMode(fullvatswitch_pin, INPUT);
pinMode(bottlecapapcityswitch_pin, INPUT);
pinMode(ps_pin, OUTPUT);
digitalWrite(ps_pin, LOW);
}
void loop()
{
//if bottle is empty do not start pump and recheck bottle level
//checkbottlelevel:
if
(digitalRead(bottlecapapcityswitch_pin) == LOW)
{
digitalWrite(ps_pin, LOW);
//Serial.printIn("resin bottle empty");
}
//else if resin bottle has resin check vat resin level
if
((digitalRead(bottlecapapcityswitch_pin) == HIGH) && (digitalRead(fullvatswitch_pin) == LOW))
{
//if vat resin level is below maximum delay pump start by 1 minute
delay(10000);//10s pump delay 0n
//start pump
digitalWrite(ps_pin, HIGH);
//Serial.printIn("soleniods and pump on");
}
if
((digitalRead(bottlecapapcityswitch_pin) == HIGH) && (digitalRead(fullvatswitch_pin) == HIGH))
{
//Serial.println(pwm_pin value);
//delay pump off by 5 seconds
delay(5000);
digitalWrite(ps_pin, LOW);
//restart resin level check cycle
}
}
Wokwi diagram.json
{
"version": 1,
"author": "Kevin Bartolo",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-attiny85", "id": "tiny", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": -12.34,
"left": -291.27,
"attrs": { "color": "blue" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -144.86,
"left": 97.47,
"attrs": { "color": "green", "bounce": "0" }
},
{ "type": "wokwi-vcc", "id": "vcc1", "top": 30.65, "left": -83.94, "attrs": {} },
{ "type": "wokwi-gnd", "id": "gnd1", "top": 93.07, "left": 40.47, "attrs": {} },
{
"type": "wokwi-pushbutton",
"id": "btn2",
"top": -141.32,
"left": -103.84,
"attrs": { "color": "red", "bounce": "0" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": -83.2,
"left": -196.33,
"attrs": { "value": "1000" }
},
{
"type": "wokwi-resistor",
"id": "r2",
"top": -87.62,
"left": 20.17,
"attrs": { "value": "1000" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": -206.73,
"left": -43.41,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -202.31,
"left": 171.98,
"attrs": { "color": "green" }
}
],
"connections": [
[ "gnd1:GND", "tiny:GND", "black", [ "v0" ] ],
[ "gnd1:GND", "led1:C", "black", [ "v0.36", "h-219.99" ] ],
[ "btn1:2.l", "vcc1:VCC", "red", [ "h-29.19", "v95.29", "h-127.02", "v19.88" ] ],
[ "btn2:1.l", "vcc1:VCC", "red", [ "h-21.17", "v127.32" ] ],
[ "tiny:PB4", "led1:A", "green", [ "v49.63", "h-179.95" ] ],
[ "r1:1", "tiny:PB1", "gold", [ "v52.25", "h220.42" ] ],
[ "r2:1", "tiny:PB2", "violet", [ "v0" ] ],
[ "r1:1", "btn2:2.l", "gold", [ "v0" ] ],
[ "r1:2", "gnd1:GND", "black", [ "v12.48", "h223.48", "v149.12" ] ],
[ "btn1:1.l", "r2:1", "violet", [ "h0" ] ],
[ "r2:2", "gnd1:GND", "black", [ "v-0.77", "h26.86", "v171.21" ] ],
[ "tiny:VCC", "vcc1:VCC", "red", [ "v-5.42", "h-39.55" ] ],
[ "led2:C", "r1:2", "black", [ "v0" ] ],
[ "led3:C", "r2:2", "black", [ "v0" ] ],
[ "led2:A", "btn2:2.l", "gold", [ "v77.57", "h-91.14" ] ],
[ "led3:A", "btn1:1.l", "violet", [ "v9.09", "h-95.56" ] ]
],
"dependencies": {}
}
For a Resin 3D printer auto filler Digispark aatiny85. The circuit tests firstly for resin in the filler bottle. If resin is present, then it checks if the print vat is full. If resin in bottle is true and vat is false, then after 10s it turns on the pump and solenoids via a mosfet, to switch on 24V dc to activate pump and solenoids. If vat is full and resin bottle is full then turn of pump and solenoids of after 5 sec.
Thanks and in advance.