Also
Should this:
sensorValuePercent = (300/1023) * 100;
Not be:
sensorValuePercent = (Sensorvalue/1023) * 100;
Also
Should this:
sensorValuePercent = (300/1023) * 100;
Not be:
sensorValuePercent = (Sensorvalue/1023) * 100;
Mark, what is the raw values for analogread(A0) dry and wet?
dry is 1023 instead of 0
wet is 0 instead of 1023
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>
int Sensorvalue=0;
int sensorPin=A0;
int sensorValuePercent=0;
WidgetLED led1(V1);
WidgetLED led2(V2);
SimpleTimer timer;
char auth[] = "6044f1c858a547d5a54cf14a1287de89";
void setup()
{
// Debug console
DebugSerial.begin(9600);
timer.setInterval(3000L, blinkLedWidget);
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void blinkLedWidget()
{
Blynk.virtualWrite(V5, analogRead(A0) );
Sensorvalue = map(Sensorvalue, 0,1023,0,1023);
sensorValuePercent = (Sensorvalue/1023)* 100; // In Prozentļ»æ
}
void loop()
{
Blynk.run();
timer.run();
}
Does not work with blynk
It doesnāt work because you do not have any code to obtain the SensorValue.
Directly after:
Blynk.virtualWrite(V5, analogRead(A0) );
add;
SensorValue = analogRead(A0);
Does not work even with dry 1023 and with moist 0
Home now, busy checking.
try this:
void blinkLedWidget()
{
Sensorvalue = analogRead(A0);
Sensorvalue = map(Sensorvalue, 0, 1023, 1023, 0);
sensorValuePercent = (Sensorvalue / 1023) * 100; // In Prozentļ»æ
Blynk.virtualWrite(V5, Sensorvalue);
}
THANK YOU it works now as I would like to thank you again
This works now (Iāve added wifi connection details etc as I donāt use serial connection to blynk)
When the fakesensor (I donāt have a moisture sensor handy) value is 0 the gauge widget shows 1023 (full) and as the fakesensor value increases the gauge decreases. (how many posts are needed for a simple remappingā¦)
//#include <SoftwareSerial.h>
//SoftwareSerial DebugSerial(2, 3); // RX, TX
//#define BLYNK_PRINT DebugSerial
//#include <BlynkSimpleStream.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiClient.h>
#include <SimpleTimer.h>
int Sensorvalue = 0;
int sensorPin = A0;
int sensorValuePercent = 0;
int FakeSensorvalue = 0;
int i = 0;
WidgetLED led1(V1);
WidgetLED led2(V2);
SimpleTimer timer;
SimpleTimer faketimer;
char auth[] = "My Auth"; //Insert Your Auth Code Here
char ssid[] = "My SSID; //WiFi SSID
char pass[] = "My PSK"; //WiFi Key / Password
IPAddress server_ip (192, 168, 1, 00; //insert local server IP address here
WiFiClient espClient;
void setup()
{
Serial.begin(115200);
// Connect to WiFi network (DHCP Mode)
WiFi.begin(ssid, pass);
Serial.print("\n\r \n\rWorking to connect");
// Wait for connection
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Blynk.config(auth, server_ip); //local server connection string
//for Blynk cloud uncomment below
// Blynk.config(auth);
while (Blynk.connect() == false) {}
// Debug console
//DebugSerial.begin(9600);
timer.setInterval(1000L, blinkLedWidget);
faketimer.setInterval(1000L, loopsensor); //need this to simulate the sensor
//Blynk.begin(Serial, auth);
}
void blinkLedWidget()
{
//Sensorvalue = analogRead(A0);
Sensorvalue = FakeSensorvalue;
Sensorvalue = map(Sensorvalue, 0, 1023, 1023, 0);
sensorValuePercent = (Sensorvalue / 1023) * 100; // In Prozentļ»æ
Blynk.virtualWrite(V5, Sensorvalue);
Blynk.virtualWrite(V6, FakeSensorvalue); //Just to see the raw value
Serial.print("Sensor Val: ");
Serial.println(Sensorvalue);
Serial.print("Fake Sensor Val: ");
Serial.println(FakeSensorvalue);
}
void loop()
{
Blynk.run();
timer.run();
faketimer.run();
}
void loopsensor() {
FakeSensorvalue = FakeSensorvalue + 1;
if (FakeSensorvalue == 1023) FakeSensorvalue = 0;
}
Ignore the other buttons. the value display is V6 and the gauge is V5.
hey please can u share with me the last form of the code that worked i amm doing a plant watering project and i am facing same problem as you
hello what do you mean Iāve solved the problem with map
<<<sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0, 1023, 1023, 0);
sensorValuePercent = (sensorValue / 1023) * 100;
Serial.print (String ("Bodenfeuchte ist : ") + sensorValue = analogRead(sensorPin));
Blynk.virtualWrite(V7, sensorValue);>>>
can u share the whole code please
the code runs with fishno board
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Fishino.h>
#include <BlynkSimpleFishino.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] = "962a607a6a01458fbf5c3437aexxxxxx";
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
float tempout = 0;
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
char Date[16];
char Time[16];
int sensorValue = 0;
int sensorPin = A0;
int sensorValuePercent = 0;
WidgetRTC rtc;
void clockdata()
{
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
Serial.print("Uhrzeit und Datum ");
Serial.print(Time);
Serial.print(" ");
Serial.print(Date);
Serial.println();
Blynk.virtualWrite(V1, Time);
Blynk.virtualWrite(V2, Date);
}
void Twitter(){
Blynk.tweet (String ("Temperatur ist : ") + sensors.getTempCByIndex(0) + "Ā°C / Bodenfeuchte ist : " + sensorValue + "% um " + (Time) + " am " + (Date));
}
void Bodenfeucht(){
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0, 1023, 1023, 0);
sensorValuePercent = (sensorValue / 1023) * 100;
Serial.print (String ("Bodenfeuchte ist : ") + sensorValue = analogRead(sensorPin));
Blynk.virtualWrite(V7, sensorValue);
}
void Temperaturmessung(){
sensors.requestTemperatures();
tempout = (sensors.getTempCByIndex(0));
Serial.print (String ("Temperatur ist : ") + sensors.getTempCByIndex(0));
Blynk.virtualWrite(V4, tempout);
if (tempout < 9.99) {
Blynk.setProperty(V4, "label", "arsch kalt Ā°C");
}
if (tempout > 10 && tempout < 19) {
Blynk.setProperty(V4, "label", "Temperatur normal Ā°C");
}
if (tempout > 20 && tempout < 69.99) {
Blynk.setProperty(V4, "label", "schƶn warm Ā°C");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
rtc.begin();
timer.setInterval(1000, clockdata);
timer.setInterval(1000, Bodenfeucht);
timer.setInterval(1000, Temperaturmessung);
timer.setInterval(15000, Twitter);
Blynk.begin(auth, "");
}
void loop()
{
Blynk.run();
timer.run();
}
Well, digging the one year old topic is usually bad thing to do, but in this case, response was just brilliant, fast and precise.
Hats off to you, @markop!