3

I'm working with a fuzzy logic controller with Arduino, I'm trying to emulate an AC by entering inputs [temperature and humidity] using two potentiometers and the output is the AC power.

This is the basic part of the program, every thing is good, I can print the values of Temp and HU. But when I try to print the value of the Power, nothing happens, and the serial monitor displays nothing. By trial and error, I can see that Serial.println with power or any variable related to power crashes the program. What may be the reason?

 void loop()
{
 // Read Input: Temperature
 ttemp = analogRead(temp);
 Serial.println("the analoge Tempreture is ");
 Serial.println (ttemp);
 ttemp = map(ttemp, 0, 1023, 5, 65);
 ttemp = constrain(ttemp, 5, 65);
 Serial.println("the actual Tempreture is ");
 Serial.println (ttemp);
 Serial.println("-------------------------");
 delay(100);
 g_fisInput[0] = ttemp;
 // Read Input: Humidity
 hhu = analogRead(hu);
 Serial.println("the analoge Humidity is ");
 Serial.println (hhu);
 hhu = map(hhu, 0, 1023, 16, 100);
 hhu = constrain(hhu, 16, 100);
 Serial.println("the actual Humidity is ");
 Serial.println (hhu);
 Serial.println("-----------------------");
 delay(100);
 g_fisInput[1] = hhu;
 g_fisOutput[0] = 0;
 fis_evaluate();
 // Set output vlaue: Power
 int ppower1 = g_fisOutput[0];
 // Serial.println("the actual Power is ");
 // Serial.println (ppower1);
 ppower = map(ppower1,100,3000,0,255);
 ppower = constrain (ppower, 0,255);
 analogWrite(power , ppower);
 // Serial.println("the analoge Tempreture is ");
 //Serial.println (ppower);
 // Serial.println("--------------------------");
}
Avamander
6242 gold badges11 silver badges35 bronze badges
asked Apr 10, 2017 at 17:59
3
  • Too much RAM usage from all those strings in SRAM? Commented Apr 10, 2017 at 18:15
  • With the complete program we could try to compile it and possibly run it. But without the globals and setup() function, we can't really do much more than guess. Commented Apr 10, 2017 at 18:24
  • Try using the Serial.println(F("String")); instead of Serial.println("String") to utilize progmem rather than SRAM. Commented Apr 10, 2017 at 18:28

1 Answer 1

1

You should have provided your full Arduino code. Without setup() part of Arduino code, we can not exactly tell what might be wrong. Please provide it and I'll revise my answer as well.

Check if you have this code in your setup() function:

Serial.begin(9600);

9600 is baud rate and it could be any other supported baud rate(you can see those by opening a Serial monitor and clicking on 9600 baud rate on bottom right edge).

Related to to comments above, from experience and it can be easily "counted", RAM shouldn't be a problem in such short code.

answered Apr 10, 2017 at 23:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.