Hello, I want to make an electrolysis device using Arduino Nano. I finished all the designs of the device and prepared its electronic connections.
Device:
- 18650 batteries will be used as the power source. (The number is not important, but I connected 4 to experiment)
- A button will be used to activate the device and a red LED will be connected to indicate that it is working.
- Current, voltage, watt and temperature values will be instantly printed on the screen on the device.
- With a TOGGLE SWITCH on the device, the device will perform current electrolysis or start the motor that drains the water inside the device.
- There will be 3 fans on the sides of the device to prevent the battery and components from heating up.
However, the fans connected to the device were rotating very slowly. When I examined the connections I made, I noticed that the Arduino pins gave 4.07V as output. Also, the switch connection I made to control the relays did not work. I'm very new to this and I really need help. I would be glad if you help me.
Code:
//OLED SCREEN - SSD1306
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED weight (128 pixel)
#define SCREEN_HEIGHT 64 // OLED height (64 pixel)
#define OLED_RESET -1 // I don't use reset pin
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//TEMPERATURE SENSOR - DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temperature;
//CURRENT SENSOR - ACS712 30A
const int currentSensorPin = A0;
const int voltageSensorPin = A1;
float vOUT = 0.0;
float vIN = 0.0;
float R1 = 10000.0;
float R2 = 1980.0;
float Vdata = 0;
float V,I,I1;
float Cdata;
float watt_value;
//LEDS & FANS
int ledPin = 2;
int fanPin1 = 3;
int fanPin2 = 4;
int fanPin3 = 5;
int switchLed = 9;
int relay1 = 7; //ELECTROLYSIS RELAY
int relay2 = 8; //PUMP RELAY
int switch_ = 10;
int switch_close = 11;
int switch_open = 12;
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 error!!!"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
sensors.begin();//DS18B20 starting
pinMode(ledPin, OUTPUT);
pinMode(fanPin1, OUTPUT);
pinMode(fanPin2, OUTPUT);
pinMode(fanPin3, OUTPUT);
pinMode(switchLed, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(switch_, OUTPUT);
pinMode(switch_close, INPUT);
pinMode(switch_open, INPUT);
digitalWrite(switch_, HIGH);
}
void loop() {
digitalWrite(ledPin, HIGH);
digitalWrite(fanPin1, HIGH);
digitalWrite(fanPin2, HIGH);
digitalWrite(fanPin3, HIGH);
int pump_open = digitalRead(switch_open);
int pump_close = digitalRead(switch_close);
if(pump_open == HIGH && pump_close == LOW){
digitalWrite(switchLed, HIGH);
}
else if(pump_close == HIGH && pump_open == LOW){
digitalWrite(switchLed, LOW);
}
if(pump_open && !pump_close){
digitalWrite(relay1, LOW);
delay(500);
digitalWrite(relay2, LOW);
delay(500);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("PUMP");
int timeee=10;
while(timeee>0){
display.println(timeee);
delay(1000);
timeee--;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("PUMP");
display.println("OPEN");
digitalWrite(relay1, LOW);
delay(500);
digitalWrite(relay2, HIGH);
delay(10000);
}
else{
digitalWrite(relay2, LOW);
delay(500);
digitalWrite(relay1, HIGH);
delay(500);
sensors.requestTemperatures(); //Get data from sensor
float temperatureCelsius = sensors.getTempCByIndex(0); //Get celcius data from sensor
if (temperatureCelsius != DEVICE_DISCONNECTED_C) {
temperature = temperatureCelsius;
}
else {
Serial.println("Sensor is not connected");
}
current_sensor();
}
}
void current_sensor() {
for(int i = 0; i < 300; i++){
//Reading 300 times to get a more stable average result
Cdata = Cdata + analogRead(currentSensorPin);
Vdata = Vdata + analogRead(voltageSensorPin);
delay(1);
}
Cdata=Cdata/300;
V=(Cdata/1024.0)*5000;
I=((V - 2500)/ 96);
Vdata=Vdata/300;
vOUT = (Vdata * 5.0) / 1024.0;
vIN = (vOUT / (R2/(R1+R2)));
print_screen();
}
void print_screen(){
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("A: ");
if (I<0) {display.println("0.0");} else {display.println(I, 1);}
display.print("VOLT: ");
display.println(vIN, 1);
display.print("WATT: ");
watt_value = (I * vIN);
if (watt_value<0) {display.println("0.0");} else {display.println(watt_value, 1);}
display.println(temperature, 1);
display.print("C");
display.display();
display.clearDisplay();
Cdata=0;
I=0;
V=0;
Vdata=0;
vIN=0;
watt_value=0;
}
