I am trying to get my new velleman vma320 to work with my arduino.
It doensn't work at all, the temperature goes down its heated up. I've tried everything. Can somebody help me? Here is my code...
int SensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
//reading
int sensorvalue = analogRead(SensorPin);
Serial.print("value: ");
Serial.print(sensorvalue);
//voltage
float voltage = sensorvalue * 5.0;
voltage /= 1024.0;
Serial.print(", volts: ");
Serial.print(voltage);
//temperature
float temperature = (voltage - 0.5) * 100 ;
Serial.print(" degrees C");
Serial.println(temperature);
}
Is it something I have done wrong? Or is it just the sensor? I tried it with two sensors.
If you can help me that would be awesome.
Thanks in advance,
Jens Van den Eede.
So, this is the working code for a thermister velleman vma320. According to the way it's wired, voltage will go down as the temperature goes up, and it's not linear.
#include <math.h>
double Thermistor(int RawADC) {
double Temp;
Temp =log(10000.0/(1024.0/RawADC-1)); // for pull-up configuration
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(int(Thermistor(analogRead(A0))));
delay(1000);
}
Please note the above code only provides accurate temperatures if you are supplying the VMA320 with 3.3VDC (from VCC, not 5V).
Also add "Temp = (Temp * 9.0)/ 5.0 + 32.0;" above "return Temp;" if you wish to convert to °F
Related
So me and my groupmates are been working on with our thesis project about energy meter. In our project, the esp32 is the main board we are using. We also have voltage sensor (ZMPT101B) and current sensor (SCT013 100V:50mA) connected to our main board.
here is the link for the ZMPT101B... https://www.autobotic.com.my/ac-voltage-sensor-module-zmpt101b-single-phase
and here is the link for the SCT013... https://innovatorsguru.com/sct-013-000/
I am also using the Emon library from https://www.arduino.cc/reference/en/libraries/emonlib/ to read the value thrown by the current and voltage sensor.
To get the power, i will multiply the current and voltage values.
Then to get the value of the energy i will be needing the time because Energy = Power x time. I saw formula online, it uses millis () function to get the time... but to be honest i dont know how millis works.
last_time = current_time;
current_time = millis();
Wh = Wh + power *(( current_time -last_time) /3600000.0) ;
The value of the energy will be send to the database, in our case our database is the firebase realtime database. Using this code...
Firebase.setDouble(firebaseData, path , KWh);
If the electricity cuts off , ESP32 will also be dead and will stop working. So we decided to add this line of codes...
Firebase.getInt(firebaseData, path);
totalEnergyDB = (firebaseData.intData());
preKWh = totalEnergyDB;
.... once the esp32 is turned on again, this code is used to get the data from the firebase... wherein the data got from the firebase will be used as a pre-kwh.
I used this lines of code to add the current readings from the pre-kwh.
KWh = (Wh/1000) + preKWh;
I set the calibration for the voltage and current sensor high so the changes will be easy to be seen.
My problem is that i was able to get the value from the database but it seems the energy formula is not working properly.
this is the result from the serial monitor... (171 KWH is the initial value from the database)
enter image description here
i wasn't able to show you the result of the power but it say in the lcd that it is around 3000W! But still Energy reading is not changing even its been turned on for over an hour:(
Here is the complete code for our project...
#include "EmonLib.h"
#define VOLT_CAL 52.5000
#define CURRENT_CAL 10.07
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
EnergyMonitor emon1;
int i;
// Wifi
#include <WiFi.h>
#include "FirebaseESP32.h"
#define FIREBASE_HOST "#!##!#$!#a.firebaseio.com"
#define FIREBASE_AUTH "RRw3u$!#%!##%##%$#%^#$^oI8LpQyVo0AWBC"
#define WIFI_SSID "WIFI"
#define WIFI_PASSWORD "PASSWORD"
// Define Firebase Data object
FirebaseData firebaseData;
// Root Path
String path = "/USER INFO/jdc/totalEnergy";
unsigned long last_time =0;
unsigned long current_time =0;
int Wh = 0;
int preKWh;
int KWh;
int totalEnergyDB;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
initWifi();
lcd.init();
lcd.backlight();
lcd.begin(4, 20);
lcd.clear();
lcd.setCursor(1,4);
lcd.print("LOADING...");
Serial.print("LOADING...");
emon1.voltage(32, VOLT_CAL, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(33, CURRENT_CAL);
for ( i = 0; i < 5; i++ ) {
emon1.calcVI(20,2000);
float currentDraw = emon1.Irms;
float supplyVoltage = emon1.Vrms;
}
delay(1);
Firebase.getInt(firebaseData, path);
totalEnergyDB = (firebaseData.intData());
preKWh = totalEnergyDB;
}
void loop() {
emon1.calcVI(20,2000);
float currentDraw = emon1.Irms; //extract Irms into Variable
float supplyVoltage = emon1.Vrms;
float power = currentDraw * supplyVoltage;
last_time = current_time;
current_time = millis();
Wh = Wh + power *(( current_time -last_time) /3600000.0) ;
KWh = (Wh/1000) + preKWh;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("VOLTAGE: ");
lcd.print(supplyVoltage);
lcd.print(" V");
lcd.setCursor(0,1);
lcd.print("CURRENT: ");
lcd.print(currentDraw);
lcd.print(" A");
lcd.setCursor(0,2);
lcd.print("POWER: ");
lcd.print(power);
lcd.print(" W");
lcd.setCursor(0,3);
lcd.print("ENERGY: ");
lcd.print(KWh);
lcd.print(" KWh");
delay(100);
if (isnan(Wh)) { // if Wh is Not A Number
Serial.println(F("Error reading Energy!"));
}
else {
Serial.print(F("preKWh: "));
Serial.print(preKWh);
Serial.println(F("KWH"));
Serial.print(F("Energy: "));
Serial.print(KWh);
Serial.println(F("KWH"));
Firebase.setDouble(firebaseData, path , KWh);
delay(100);
}
}
void initWifi(){
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
//Set database read timeout to 1 minute (max 15 minutes)
Firebase.setReadTimeout(firebaseData, 1000 * 60);
//tiny, small, medium, large and unlimited.
//Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s).
Firebase.setwriteSizeLimit(firebaseData, "tiny");
}
Can anyone help me with the code. What changes should be done?
Looking at your data types, you are storing Wh and KWh as an integer, and you are adding likely very small floats to them (imagine (current_time - last_time) being 1000 (1 second), then Wh would become Wh + power * 2.78e-5, which will result in rounding errors unless your power consumption is enormous. To solve this, you should not round to integers, and keep Wh and KWh as floats.
I'm trying to write some code that will turn on the gps module and wait for data to arrive, so that I can then do things with it. I don't need a continuous stream; I only need the first lat/long received from the gps unit, then I can turn it off. I also need this to just stop if it can't find it's location within a certain amount of time (20 seconds for example)
Here is some simple code that I've tried just to get the gps to read (full code with timeout comes later)
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(D4, D3); // The serial connection to the GPS
float latitude , longitude;
int count = 0;
void setup()
{
Serial.begin(9600);
ss.begin(9600);
Serial.println();
Serial.print("Starting");
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
if (gps.location.isValid())
{
latitude = gps.location.lat();
lat_str = String(latitude , 6);
longitude = gps.location.lng();
lng_str = String(longitude , 6);
}
}
Serial.println(lat_str + ":" + lng_str);
delay(100);
count += 1;
String Count = String(count);
Serial.println(Count);
}
When the delay above is 100, then everything works fine, when the delay is 1000, then suddenly no data comes through.
Here is the full code I've tried that includes my timeout and breakout condition, again not working. The cutoff line is in the GPS_mode function here: while ((stoploop < 1) && (previous - startTime < TimeOut)).
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(D4, D3); // The serial connection to the GPS d
int stoploop = 0; //used for stopping gps once a signal lock or timeout is reached
unsigned long startTime = millis(); // timer used for gps timeout
const int gpsCutoffPin = D1;
void setup() {
//initialise the serial monitor
Serial.begin(9600);
gps_ss.begin(9600);
//initialise the transistor pins
pinMode(gpsCutoffPin, OUTPUT);
// Start the gps in an off state
digitalWrite(gpsCutoffPin, LOW);
}
void loop() {
Serial.println("Enter GPS mode");
GPS_mode();
Serial.println("Back to the main loop now...");
Serial.println(stoploop);
delay(100000);
}
void GPS_mode(){
//turn on the gps
digitalWrite(gpsCutoffPin, HIGH);
stoploop = 0;
startTime = millis();
previous = millis();
int TimeOut = 60*1000;
gps_ss.listen();
Serial.println(stoploop);
while ((stoploop < 1) && (previous - startTime < TimeOut))
{
while (gps_ss.available() > 0)
{
if (gps.encode(gps_ss.read()))
{
logInfo();
}
yield();
}
}
gpsLat = (gps.location.lat(), DEC);
gpsLon = (gps.location.lng(), DEC);
// turn off the gps
digitalWrite(gpsCutoffPin, LOW);
}
void logInfo(){
// Causes us to wait until we have satelite fix
if(!gps.location.isValid())
{
Serial.println("Not a valid location. Waiting for satelite data.");
//return;
}
else {
//url += String(gps.location.lat(), DEC);
//url += String(gps.location.lng(), DEC);
Serial.println(gps.location.lat(), DEC);
Serial.println(gps.location.lng(), DEC);
stoploop = 2;
//delay(1000);
}
previous = millis();
}
I expect to see some gps data printed to the screen, but I actually don't see anything. I know that the gps is working and is receiving data because the blinking LED tell me so.
I have no idea how to fix this. If anyone could help I'd very much appreciate it.
Thanks
I got an issue with the PWM signal on the fan, it actually gets to 100% right away when it hits 21°C when it should be on 10%. I don't think it's a circuit issue, so any suggestions on the code ? I am pretty sure the problem is somewhere at the Map function, just can't seem to figure it out.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 20; // the temperature to start the fan
int tempMax = 30; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
}
void loop() {
temp = readTemp(); // get the temperature
if(temp < tempMin) { // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
digitalWrite(fan, LOW);
}
if((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 115, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
if(temp > tempMax) { // if temp is higher than tempMax
digitalWrite(led, HIGH); // turn on led
} else { // else turn off led
digitalWrite(led, LOW);
}
lcd.print("TEMP: ");
lcd.print(temp,1); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(500);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return (temp * 0.48828125)-48;
}
Ok so apparently there was a problem with this specific pin, i tried another one (PWM), and it worked perfectly!
I'm making a simple temperature sensor to light one of two LEDs depending on the temperature.
For some reason the LED output only blinks the onboard LED (pin 13 on the Edison) once.
My temperature output is working fine, but I'm not sure why my code is working incorrectly.
Photo of the wiring here.
int temppin = 0;
int ledhigh = 7;
int ledlow = 8;
void setup()
{
Serial.begin(9600);
pinMode(temppin, INPUT);
pinMode(ledhigh, OUTPUT);
pinMode(ledlow, OUTPUT);
}
void loop()
{
int tempout = analogRead(temppin);
float volts = tempout * 5.0;
volts /= 1024.0;
float temp = (volts - 0.5) * 100 ;
Serial.print(temp); Serial.println(" celsius");
if (temp > 0){
Serial.print("high temp =");
digitalWrite(ledhigh, HIGH);
} else {digitalWrite(ledlow, HIGH);
Serial.print("low temp");
}
delay(3000);
}
The problem is probably that you're trying to use the analog input pins as output. You need to use the digital pins.
As explained in this video:
https://youtu.be/BtLwoNJ6klE?t=50s
I have arduino uno r3, temp sensor lm335z and 2 led.
I found this code in internet
float celsius = 0, kelvin=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 273.15;
Serial.print("Celsius: ");
Serial.println(celsius);
//Serial.print("Kelvin: ");
//Serial.println(kelvin);
Serial.println();
delay(10000);
}
and works great with this schema
temp only
I add two led with this code:
float celsius = 0, kelvin=0;
int led_green = 13;
int led_red = 12;
void setup()
{
Serial.begin(9600);
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);
}
void loop()
{
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 273.15;
Serial.print("Celsius: ");
Serial.println(celsius);
//Serial.print("Kelvin: ");
//Serial.println(kelvin);
Serial.println();
if (celsius <= 25.00)
{
digitalWrite(led_green, HIGH);
digitalWrite(led_red, LOW);
}
else
{
digitalWrite(led_green, LOW);
digitalWrite(led_red, HIGH);
}
delay(10000);
}
and this schema:
led and temp
Temperature 1,2 or 3 degree plus than normal where or what I miss?
Because of
kelvin = analogRead(0) * 0.004882812 * 100;
So each step of the ADC will imply ~0.5 degrees of temperature difference. Since you did not specify anything in your sketch the voltage reference is the supply voltage. Loading the Arduino's outputs with just one LED (as you do) may affect the supply voltage in the order of magnitude of 50-100 mV. This in turn will affect your temperature reading by several degrees.
You can find a detailed analysis of this effect in my blog
So the issue can be explained by the addition of LEDs to your circuit.