Can someone tell me what i am doing wrong?

I want to make a program that takes the rpms from my fan as well as the temperature from a temperature sensor, and display both on an lcd screen in real time. This is what i have so far… I am not sure what i am doing wrong and am fairly new at this.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h> // For many “1-wire” devices
#include <DallasTemperature.h> // Specific for temperature sensors
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
#define ONE_WIRE_BUS 10 // NOTE: No “;” on #define
OneWire oneWire(ONE_WIRE_BUS);
// Pass address of our oneWire instance to Dallas Temperature.
DallasTemperature sensors(&oneWire);

int NbTopsFan;
int Calc;
float TempInC ; //Floating Point variable for C Temperature
float TempInF ; //Floating Point variable for F Temperature

//The pin location of the sensor
int hallsensor = 2;

typedef struct{ //Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv;
}fanspec;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1; //This is the varible used to select the fan and it’s divider, set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor

void rpm () //This is the function that the interupt calls
{
NbTopsFan++;
}

//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup() {
{
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, RISING);
}
{
Serial.begin(4800); // start serial port
Serial.println(“YourDuinoStarter Example: DS18B20 Temperature Sensor Reading”);
sensors.begin(); // Start up the temperature measurement library
}
{
Serial.begin(19200); // Used to type in characters

lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight

// ------- Quick 2 blinks of backlight -------------
for(int i = 0; i< 2; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on

//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print(“Initializing…”);
delay(1000);
lcd.setCursor(0,1);
lcd.print(“Please wait…”);
delay(8000);
}

}
void loop ()
{
{
// when characters arrive over the serial port…
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan’s divider
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
}
{
Serial.print(“Requesting temperatures using Library …”);
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println(“DONE”);

/----( Here we will save values to use for other things)------/
TempInC = sensors.getTempCByIndex(0); // Get and save sensor value
TempInF = sensors.getTempFByIndex(0); // Get and save sensor value
Serial.println(“Here are our saved values”);
Serial.print("Temperature in C = ");
Serial.println(TempInC, 2); // “2” sets the number of decimal places
Serial.print("Temperature in F = ");
Serial.println(TempInF, 2); // “2” sets the number of decimal places
Serial.println();
delay(5000);
}

}

Please modify your post and use code tags.

** **[code]** **
your code here
** **[/code]** **
will result in

 your code here

Next describe what you expect your code to do and what it does do.

When you do the above, also lose the delay() calls

Have a look at Planning and Implementing a Program which illustrates how to separate your program into small functions and also how to manage timing using millis() rather than delay(). The Arduino can do nothing during a delay() interval.

...R

Also, in your code you do a lot of this:

void setup() {
{
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}
}

There are too many braces and should look more like this:

void setup() {

  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

}

It probably doesn't cause the code to work incorrectly, but makes the whole code harder to read.

if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);

In 1/10th of a second at 19200 bits per second, the input buffer could overflow three times over, and you’d never know.

I expect the code to read the temperature values from the temperature sensor and the rpms from my PC fan. I want the display to show both of those values (Calc is the RPM). Right now it won't get past the part where it says initializing. Please wait. Also. When I open up my serial monitor it is giving me random characters that should not be there

sterretje:
Please modify your post and use code tags.

** **[code]** **
your code here
** **[/code]** **
will result in

 your code here

Next describe what you expect your code to do and what it does do.

anishp:
Also. When I open up my serial monitor it is giving me random characters that should not be there

You have initialized your serial connection at 4800 baud, I'm sure the Arduino IDE's lowest baud rate is 9600.

In any case it sounds like you haven't selected the correct baud rate in the serial window.

In fact on looking again it seems you have initialized your serial connection 3 times in total during setup().

The last one is 19200 which will be the one that the Arduino uses since it is the last one you defined. So, unless your serial monitor window is set to 19200 baud rate you won't see and serial messages.

nzcrog:
You have initialized your serial connection at 4800 baud, I'm sure the Arduino IDE's lowest baud rate is 9600.

You may be sure, but you're also wrong.

AWOL:
You may be sure, but you're also wrong.

Figures! In any case I still think I'm correct as to why he is getting random crap from his serial monitor window :wink: