Go Down

Topic: Project Help (Read 443 times) previous topic - next topic


Oct 11, 2011, 07:56 am Last Edit: Oct 11, 2011, 10:28 am by chayanba Reason: 1
Please check the diagram 1st to understand the problem and the code:
While the switch is on
  a) the System should be on and it should print out on monitor " System is on" Problem : it keeps printing out system is on for infinite times.
b) When it calls the function teamreading(). Pin 13 should go on and it should send a signal to relay .if relay detects the signal it should turn on the heating element and led as shown in figure. Problem: the reading from temperature decreases without using any heating element.
c) if we put delay on each output such as Serial.print(tempC) Problem: while the loop() keeps running for infinite times and user try to turn off the switch it does not detects it.

I have written following code:
Code: [Select]
// These constants won't change:
const int sensorPin = 2;       // pin that the sensor is attached to
const int ledPin = 9;           // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2;        // pin that the button is attached to
boolean calabrated = false;   // have we calabrated the sensor
//boolean calibration = false;  //
boolean onMsgSent = false;
boolean offMsgSent = false;

float tempC =0;
float tempF=0;
int tempSen=0;

void setup() {
 // set the LED pins as outputs and the switch pin as input:
 pinMode(indicatorLedPin, OUTPUT);
 pinMode (ledPin, OUTPUT);
 pinMode (buttonPin, INPUT);

void loop() {
   // while the button is pressed, take calibration readings:
 while (digitalRead(buttonPin) == HIGH) {

   Serial.println("System ON!!!!");
   if(digitalRead(buttonPin)==HIGH) onMsgSent =false;
   //if(digitalRead(buttonPin) == HIGH) calibration = false;  
 calabrated= true;
 // signal the end of the calibration period
 digitalWrite(indicatorLedPin, LOW);
Serial.println("System OFFFFF!!!!");
 if(digitalRead(buttonPin) == HIGH) calabrated = false;
 // do other suff here

void tempreading() {

 // turn on the indicator LED to indicate that Heating process is happening:
 digitalWrite(indicatorLedPin, HIGH);

   Serial.println("System is on.. This part is operating!!!!");
   if(digitalRead(buttonPin)==HIGH) onMsgSent =false;
//Serial.println("System is on this part is operating!!!!");
 int reading =analogRead(sensorPin);
 Serial.print(reading);Serial.println(" Current Reading");
 if(reading < 920)
   digitalWrite(indicatorLedPin, HIGH);
   float voltage = reading*5000.0;
    voltage = (voltage)/1024.0;
    tempC = (voltage -500)/100;
    Serial.print(tempC); Serial.println(" degress C");
  digitalWrite(indicatorLedPin, LOW);
   Serial.print("Temperature is more then 40*C");



This is your third thread on the same topic. Are you going to listen here?
The art of getting good answers lies in asking good questions.

Go Up