Variable Power
This is a more advanced program for your VapOven Arduino Shield, it enables variable power at the turn of a dial
This code enables the potentiometer that’s included in the kit. The dial turns up the clouds… At it’s lowest setting you’ll get light flavoursome terpy hits, turn up the dial and you’ll get huge clouds
Simply copy and paste the code below into the Arduino IDE and upload to your VapOven Arduino Shield to add variable power to your IH project.
If you have any questions about the code or need assistance uploading it to your VapOven Arduino Shield , let me know and I’ll do my best to help.
/*
* Advanced code for the VapOven Arduino Shield
*
* **ADJUSTABLE HEATING***
*
* Potentiometer adjusts heat by altering the pulse heating duty cycle.
*
*
* turns on the IH module and light up LED1 when the trigger button is pressed
* uses the RGB LED as a battery indicator – green when battery is good, red when battery is low.
* temperature cutoff monitors the temperature and will not activate the IH if over 60 deg Centigrade
*
*
* This code is free to use and modify for personal use. It is released on the "You owe me a bud" licence - if we ever meet, you promise to provide me with a bud.
*/
//pins
int triggerPin = 3;
//LEDs
int LED12v = 2;
int LED1 = 4;
int LED2 = 5;
int intLED = 13;
int blueRGB = 9;
int greenRGB = 10;
int redRGB = 11;
//inputs
int buttonPin = 8;
int potPin = A7;
//sensors
int tempPin = A1;
int voltSensorPin = A6;
bool buttonState; //variable for the button press
bool ovenOn = LOW; //the main oven on / off variable
int tempC; //temperature from TMP36 sensor
int tempCutOff = 60; //temperature in Centigrade to stop IH activating
float voltage; //battery voltage
double lowBatteryThreshold = 10;
//for the pulse heat mode
long pulseOvenTime = 500; //adjust this value to change speed of pulse
double pulseFactor = 100;
long pulseOvenStart = 0;
float loopTime;
int potValue; // value returned from potentiometer
void setup() {
//set up all the pins
pinMode(buttonPin, INPUT);
pinMode(triggerPin, OUTPUT);
pinMode(LED12v, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(blueRGB, OUTPUT);
pinMode(greenRGB, OUTPUT);
pinMode(redRGB, OUTPUT);
pinMode(intLED, OUTPUT);
}
void loop() {
loopTime = millis();
//check the temperature
tempC = getTemp();
//check the battery voltage (if the button isn't pressed)
if(ovenOn == LOW) voltage = getVoltage();
//set the RGB LED colour to indicate battery level
if(voltage >= lowBatteryThreshold){
digitalWrite(redRGB, LOW);
digitalWrite(greenRGB, HIGH);
digitalWrite(blueRGB, LOW);
}
else{
digitalWrite(redRGB, HIGH);
digitalWrite(greenRGB, LOW);
digitalWrite(blueRGB, LOW);
}
//read the potentiometer value
potValue = analogRead(potPin);
//set pulse time to pot value
pulseFactor = map(potValue, 0, 1023, 0, 200);
//check if the button is pressed
buttonState = digitalRead(buttonPin);
//if the button is pressed set oven to on, else set it to off
if(buttonState == HIGH) ovenOn = HIGH;
else ovenOn = LOW;
//if the temperature is above the cutoff, set the oven to off
if(tempC >= tempCutOff){
ovenOn = LOW;
}
// on off switch for oven
if(ovenOn == HIGH){
//if pot is turned all the way down, heat at full power
if(pulseFactor < 5){
digitalWrite(intLED, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(triggerPin, HIGH);
}
//pulse to adjust the heating based on the pot knob reading
else{
if(loopTime - pulseOvenStart < pulseOvenTime){
digitalWrite(intLED, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(triggerPin, HIGH);
}
else{
digitalWrite(intLED, LOW);
digitalWrite(LED1, LOW);
digitalWrite(triggerPin, LOW);
}
if (loopTime - pulseOvenStart > pulseOvenTime + ((pulseOvenTime/100)*pulseFactor)){
pulseOvenStart = loopTime;
}
}
}
else{
digitalWrite(intLED, LOW);
digitalWrite(LED1, LOW);
digitalWrite(triggerPin, LOW);
}
}
//returns temperature in celcius from TMP36 sensor
int getTemp(){
int tempReading = analogRead(tempPin);
// converting to voltage
double voltage = tempReading * 5.0;
voltage /= 1024.0;
// output the temperature
double tempCdoub = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
//parse from double to int
int tempCint = tempCdoub;
return tempCint;
}
//returns the battery voltage
float getVoltage(){
int data = 0;
float V = 0.0;
float R1 = 47000.0;
float R2 = 22000.0;
data = analogRead(voltSensorPin);
V = (data * 5.0) / 1024.0;
return(V / (R2 / (R1 + R2)));
}