Hi all,
I am having a bit of a dilemma here.... This sketch I have attached is meant to print the battery voltage measured on analog0 to a webpage. The issue is it will not add any of the decimal places, I am using the "float command" but still not working. When the code is set to dump the voltage to serial it prints it perfectly to 2 decimal places. Why isn't this working? How should I go about fixing it?
#include "etherShield.h"
#include "ETHER_28J60.h"
// Define MAC address and IP address - both should be unique in your network
static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
static uint8_t ip[4] = {
192, 168, 0, 12};
static uint16_t port = 80; // Use port 80 - the standard for HTTP
int loadrelay = 7;
int solarrelay = 6;
int volt_val;
int voltage;
int light_val;
ETHER_28J60 ethernet;
void setup()
{
pinMode(loadrelay, OUTPUT);
pinMode(solarrelay, OUTPUT);
digitalWrite(solarrelay, HIGH);
digitalWrite(loadrelay, HIGH);
Serial.begin(9600);
ethernet.setup(mac, ip, port);
}void loop()
{
{
digitalWrite(solarrelay, HIGH); // turn solar regulator on
volt_val = analogRead(0);
float voltage = volt_val * (20.0 / 1023.0);
Serial.println(voltage); //for calibrating voltage divider
light_val = analogRead(1);
//Serial.println(light_val); //for calibrating light sensor
//low battery cutoff
if(voltage <12.5){
digitalWrite(loadrelay, LOW);
delay(1000*10);
}
else{
if(light_val >140){
digitalWrite(loadrelay, LOW);
delay(10*1000);
}
else{
digitalWrite(loadrelay, HIGH);
}
}
}
{
if (ethernet.serviceRequest())
{
ethernet.print("<meta http-equiv='refresh' content='1'>");
ethernet.print("<font face='verdana'>");
ethernet.print("<center><H1>Remote Battery Management</H1></center>");
volt_val = analogRead(0);
float voltage = volt_val * (20.0 / 1023.0);
ethernet.print("<p><b>Battery Bank Voltage</b></p>");
ethernet.print(voltage); //this is the value which will not display the entire number.
ethernet.print("<p> Wireless transmitter and IP camera are turned off if battery is low. </p>");
ethernet.print("</font>");
ethernet.respond();
}
}
}