This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bdev:microfluidics [2020/09/27 21:40] richard created |
bdev:microfluidics [2021/08/16 22:22] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Microfluidics ====== | ====== Microfluidics ====== | ||
+ | |||
+ | The sketch and how the electrocaloric heat sensor works has changed. The temperature sensor circuit is based on the reprap design now. https:// | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ATX PSU | ||
+ | |||
+ | {{ : | ||
+ | {{ : | ||
+ | |||
+ | |||
+ | < | ||
+ | #include < | ||
+ | Servo myservo; | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | |||
+ | #define THERMISTOR_PIN A0 | ||
+ | |||
+ | int valveservo = 11; | ||
+ | |||
+ | int washpin = 10; | ||
+ | int drypin = 9; | ||
+ | int pcvpin = 6; | ||
+ | int heatpin = 5; | ||
+ | int turnon5vpin = 5; | ||
+ | int tempsensor = A0; | ||
+ | //int levelsensor = A1; | ||
+ | int washval = 255; | ||
+ | int dryval = 255; | ||
+ | int pcvval = 255; | ||
+ | |||
+ | String command; | ||
+ | float currpos; | ||
+ | int fillflag = 1; | ||
+ | int levelval = 50; | ||
+ | int heatval = 50; | ||
+ | int htcnt = 0; | ||
+ | int pumpdelayct = 0; | ||
+ | int pumpdelay = 0; | ||
+ | int pumponflag = 0; | ||
+ | int levelstreamon = 0; | ||
+ | |||
+ | |||
+ | #define NUMTEMPS 20 | ||
+ | short temptable[NUMTEMPS][2] = { | ||
+ | {1, 841}, | ||
+ | {54, 255}, | ||
+ | {107, 209}, | ||
+ | {160, 184}, | ||
+ | {213, 166}, | ||
+ | {266, 153}, | ||
+ | {319, 142}, | ||
+ | {372, 132}, | ||
+ | {425, 124}, | ||
+ | {478, 116}, | ||
+ | {531, 108}, | ||
+ | {584, 101}, | ||
+ | {637, 93}, | ||
+ | {690, 86}, | ||
+ | {743, 78}, | ||
+ | {796, 70}, | ||
+ | {849, 61}, | ||
+ | {902, 50}, | ||
+ | {955, 34}, | ||
+ | | ||
+ | }; | ||
+ | |||
+ | |||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(115200); | ||
+ | myservo.attach(valveservo); | ||
+ | analogWrite(pcvpin, | ||
+ | analogWrite(washpin, | ||
+ | analogWrite(drypin, | ||
+ | analogWrite(heatpin, | ||
+ | analogWrite(turnon5vpin, | ||
+ | currpos = 0; | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | int rawvalue = analogRead(THERMISTOR_PIN); | ||
+ | int celsius = read_temp(); | ||
+ | int fahrenheit = (((celsius * 9) / 5) + 32); | ||
+ | // put your main code here, to run repeatedly: | ||
+ | if ((celsius > levelval) and (fillflag == 0)){ | ||
+ | htcnt = htcnt + 1; | ||
+ | if (htcnt > 10) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | else if ((celsius < (levelval-5) and (pumponflag == 1) and (fillflag == 0))) { | ||
+ | if (pumpdelayct == pumpdelay){ | ||
+ | | ||
+ | | ||
+ | } | ||
+ | pumpdelayct = pumpdelayct + 1; | ||
+ | } | ||
+ | else if ((analogRead(tempsensor) > levelval)){ | ||
+ | htcnt = 0; | ||
+ | } | ||
+ | if (levelstreamon == 1) { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | { | ||
+ | char c = Serial.read(); | ||
+ | if (c== ' | ||
+ | { | ||
+ | currpos = parseCommand(command, | ||
+ | command = ""; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | command +=c; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | float parseCommand(String com, int currpos) | ||
+ | { | ||
+ | |||
+ | if(com.equalsIgnoreCase(" | ||
+ | analogWrite(washpin, | ||
+ | delay(100); | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | analogWrite(washpin, | ||
+ | delay(100); | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | analogWrite(drypin, | ||
+ | delay(100); | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | analogWrite(drypin, | ||
+ | delay(100); | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | analogWrite(turnon5vpin, | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | analogWrite(turnon5vpin, | ||
+ | } | ||
+ | |||
+ | else if(com.equalsIgnoreCase(" | ||
+ | fillflag = 1; | ||
+ | analogWrite(pcvpin, | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | fillflag = 0; | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | if (fillflag == 1){ | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | if (fillflag == 1){ | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | int rawvalue = analogRead(THERMISTOR_PIN); | ||
+ | int celsius = read_temp(); | ||
+ | | ||
+ | } | ||
+ | | ||
+ | else if (com.substring(0, | ||
+ | washval = com.substring(11).toInt(); | ||
+ | } | ||
+ | else if (com.substring(0, | ||
+ | dryval = com.substring(10).toInt(); | ||
+ | } | ||
+ | else if (com.substring(0, | ||
+ | pcvval = com.substring(10).toInt(); | ||
+ | } | ||
+ | else if (com.substring(0, | ||
+ | levelval = com.substring(11).toInt(); | ||
+ | } | ||
+ | else if (com.substring(0, | ||
+ | heatval = com.substring(7).toInt(); | ||
+ | } | ||
+ | | ||
+ | else if (com.substring(0, | ||
+ | myservo.write(com.substring(com.indexOf(" | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | int read_temp() | ||
+ | { | ||
+ | int rawtemp = analogRead(THERMISTOR_PIN); | ||
+ | int current_celsius = 0; | ||
+ | |||
+ | byte i; | ||
+ | for (i=1; i< | ||
+ | { | ||
+ | if (temptable[i][0] > rawtemp) | ||
+ | { | ||
+ | int realtemp | ||
+ | |||
+ | if (realtemp > 255) | ||
+ | realtemp = 255; | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Overflow: We just clamp to 0 degrees celsius | ||
+ | if (i == NUMTEMPS) | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||